diff --git a/.vscode/launch.json b/.vscode/launch.json index bf76ee1..d9696c0 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,26 +1,33 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Debug Microcontroller with TinyGo", - "type": "cortex-debug", - "request": "launch", - "servertype": "external", - "cwd": "${workspaceRoot}", - "executable": "${workspaceFolder}/build/devicecode.elf", - "preLaunchTask": "TinyGo Build", - "configFiles": [ - "${workspaceFolder}/debug/openocd.cfg" - ], - "gdbTarget": "localhost:3060", - "interface": "swd", - "postLaunchCommands": [ - "monitor reset" - ], - "postDebugTask": "Stop OpenOCD" - } - ] -} \ No newline at end of file + "version": "0.2.0", + "configurations": [ + { + "name": "Debug Pico (rp2040)", + "type": "cortex-debug", + "request": "launch", + "servertype": "openocd", + "cwd": "${workspaceFolder}", + "executable": "${workspaceFolder}/build/devicecode.elf", + "preLaunchTask": "TinyGo Build (rp2040)", + "configFiles": [ + "debug/openocd_rp2040.cfg" + ], + "interface": "swd", + "postLaunchCommands": ["monitor reset"] + }, + { + "name": "Debug Pico 2 (rp2350)", + "type": "cortex-debug", + "request": "launch", + "servertype": "openocd", + "cwd": "${workspaceFolder}", + "executable": "${workspaceFolder}/build/devicecode.elf", + "preLaunchTask": "TinyGo Build (rp2350)", + "configFiles": [ + "debug/openocd_rp2350.cfg" + ], + "interface": "swd", + "postLaunchCommands": ["monitor reset"] + } + ] +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json index f40cf47..ea251d8 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,41 +2,34 @@ "version": "2.0.0", "tasks": [ { - "label": "Run OpenOCD", + "label": "TinyGo Build (rp2040)", "type": "shell", - "command": "openocd -f ${workspaceFolder}/debug/openocd.cfg", - "isBackground": true, - "problemMatcher": { - "pattern": [ - { - "regexp": ".", - "file": 1, - "location": 2, - "message": 3 - } - ], - "background": { - "activeOnStart": true, - // Start checking output as soon as OpenOCD starts - "beginsPattern": ".", - // Adjust this line if your OpenOCD prints a different “ready” message - "endsPattern": "for telnet connections" - } - } + "command": "tinygo", + "args": [ + "build", + "-o", "${workspaceFolder}/build/devicecode.elf", + "-stack-size=3KB", + "-serial=none", + "-target=pico", + "-tags", "pico_bb_proto_1", + "-scheduler=tasks" + ], + "problemMatcher": [] }, { - "label": "TinyGo Build", + "label": "TinyGo Build (rp2350)", "type": "shell", - "command": "tinygo build -o ${workspaceFolder}/build/devicecode.elf -stack-size=3KB -serial=none -target=pico -tags pico_bb_proto_1 -scheduler=tasks", - "problemMatcher": [], - "dependsOn": ["Run OpenOCD"] - }, - { - "label": "Stop OpenOCD", - "type": "process", - "command": "pkill", - "args": ["-f", "openocd"], - "problemMatcher": [] + "command": "tinygo", + "args": [ + "build", + "-o", "${workspaceFolder}/build/devicecode.elf", + "-stack-size=3KB", + "-serial=none", + "-target=pico2", + "-tags", "pico_bb_proto_1", + "-scheduler=tasks" + ], + "problemMatcher": [] } ] -} \ No newline at end of file +} diff --git a/README.md b/README.md index f959d1d..a94e2d6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ # devicecode-go +## Flashing ISOC Power Board via USB port on Pico +tinygo flash -stack-size=3KB -monitor -scheduler tasks -target=pico -tags "pico_bb_proto_1" main.go + +## Flashing ISOC Power Board via USB port on Pico2 +tinygo flash -stack-size=3KB -monitor -scheduler tasks -target=pico2 -tags "pico_bb_proto_1" main.go + +------------------- + ## Debugging instructions The following instructions set you up debugging the code on an MCU, using a Pico debug module, connected to a Mac (tested on arm64). @@ -20,8 +28,11 @@ The Darwin Kernel requires the debugger to have special permissions before it is ### Build and debug from VSCode +- Select target from debug dropdown (Pico or Pico2) - Press F5 to begin debugging +![alt text](/assets/image.png) + An OpenOCD server will be started, a GDB session started. Then the project will be built with flags specified in .vscode/tasks.json. Next, the compiled .elf file will be flashed to the MCU. The MCU will then be reset and control is handed over to you for the debug session. You'll then be able to add breakpoints, pause, resume and reset the MCU remotely using VsCode debug tools. diff --git a/assets/image.png b/assets/image.png new file mode 100644 index 0000000..512803e Binary files /dev/null and b/assets/image.png differ diff --git a/debug/openocd.cfg b/debug/openocd_rp2040.cfg similarity index 83% rename from debug/openocd.cfg rename to debug/openocd_rp2040.cfg index 2d5b283..94aece0 100644 --- a/debug/openocd.cfg +++ b/debug/openocd_rp2040.cfg @@ -5,7 +5,7 @@ source [find interface/cmsis-dap.cfg] source [find target/rp2040.cfg] # Confugure Ports -gdb_port 3060 +# gdb_port 3060 # (Seems to work without this - using cortex-debug default ports) tcl_port disabled telnet_port 4060 diff --git a/debug/openocd_rp2350.cfg b/debug/openocd_rp2350.cfg new file mode 100644 index 0000000..3ae65ca --- /dev/null +++ b/debug/openocd_rp2350.cfg @@ -0,0 +1,17 @@ +# Source the config file for the Raspberry Pi Debug Probe +source [find interface/cmsis-dap.cfg] + +# Source the config file for the RP2350 target MCU +source [find target/rp2350.cfg] + +# Confugure Ports +# gdb_port 3060 # (Seems to work without this - using cortex-debug default ports) +tcl_port disabled +telnet_port 4060 + + +# Set Adapter Speed in KHz (Lower speed may be needed for bootloader debugging). +adapter speed 5000 + +# init terminates the config stage and enters the run stage. +init \ No newline at end of file diff --git a/services/hal/internal/provider/boards/pico2_default.go b/services/hal/internal/provider/boards/pico2_default.go new file mode 100644 index 0000000..280520b --- /dev/null +++ b/services/hal/internal/provider/boards/pico2_default.go @@ -0,0 +1,24 @@ +//go:build pico2 + +package boards + +var SelectedBoard = Board{ + Name: "raspberrypi_pico2", + GPIOMin: 0, + GPIOMax: 28, + I2C: []string{"i2c0", "i2c1"}, + SPI: nil, // add when we expose SPI owners + UART: []string{"uart0", "uart1"}, + Defaults: struct { + I2C0_SDA, I2C0_SCL int + I2C1_SDA, I2C1_SCL int + UART0_TX, UART0_RX int + UART1_TX, UART1_RX int + }{ + // RP2040 default pins (GPIO numbers) + I2C0_SDA: 4, I2C0_SCL: 5, + I2C1_SDA: 2, I2C1_SCL: 3, + UART0_TX: 0, UART0_RX: 1, + UART1_TX: 8, UART1_RX: 9, + }, +} diff --git a/services/hal/internal/provider/resources.go b/services/hal/internal/provider/resources.go index 2cac323..854754e 100644 --- a/services/hal/internal/provider/resources.go +++ b/services/hal/internal/provider/resources.go @@ -1,4 +1,4 @@ -//go:build rp2040 +//go:build rp2040 || rp2350 package provider diff --git a/services/hal/internal/provider/rp2_resources.go b/services/hal/internal/provider/rp2_resources.go index 50e7e36..28e24e6 100644 --- a/services/hal/internal/provider/rp2_resources.go +++ b/services/hal/internal/provider/rp2_resources.go @@ -1,4 +1,4 @@ -//go:build rp2040 +//go:build rp2040 || rp2350 package provider diff --git a/services/hal/internal/provider/setup_none.go b/services/hal/internal/provider/setup_none.go index c79515e..2863103 100644 --- a/services/hal/internal/provider/setup_none.go +++ b/services/hal/internal/provider/setup_none.go @@ -1,4 +1,4 @@ -//go:build !(pico && (pico_rich_dev || pico_bb_proto_1)) +//go:build !((rp2040 || rp2350) && (pico_rich_dev || pico_bb_proto_1)) package provider diff --git a/services/hal/internal/provider/setup_selected.go b/services/hal/internal/provider/setup_selected.go index 98225c4..f865eef 100644 --- a/services/hal/internal/provider/setup_selected.go +++ b/services/hal/internal/provider/setup_selected.go @@ -1,4 +1,4 @@ -//go:build pico && (pico_rich_dev || pico_bb_proto_1) +//go:build (rp2040 || rp2350) && (pico_rich_dev || pico_bb_proto_1) package provider diff --git a/services/hal/internal/provider/setups/pico_bb_proto_1.go b/services/hal/internal/provider/setups/pico_bb_proto_1.go index 2ffba25..594ae06 100644 --- a/services/hal/internal/provider/setups/pico_bb_proto_1.go +++ b/services/hal/internal/provider/setups/pico_bb_proto_1.go @@ -1,4 +1,4 @@ -//go:build pico && pico_bb_proto_1 +//go:build (rp2040 || rp2350) && pico_bb_proto_1 package setups diff --git a/services/hal/internal/provider/setups/pico_rich_dev.go b/services/hal/internal/provider/setups/pico_rich_dev.go index 740893b..d2bd8e8 100644 --- a/services/hal/internal/provider/setups/pico_rich_dev.go +++ b/services/hal/internal/provider/setups/pico_rich_dev.go @@ -1,4 +1,4 @@ -//go:build pico && pico_rich_dev +//go:build (rp2040 || rp2350) && pico_rich_dev package setups diff --git a/x/fmtx/fmtx_host.go b/x/fmtx/fmtx_host.go index d6dcad5..848722a 100644 --- a/x/fmtx/fmtx_host.go +++ b/x/fmtx/fmtx_host.go @@ -1,4 +1,4 @@ -//go:build !rp2040 +//go:build !(rp2040 || rp2350) package fmtx diff --git a/x/fmtx/fmtx_mcu.go b/x/fmtx/fmtx_mcu.go index e47bb0a..5fa5b6a 100644 --- a/x/fmtx/fmtx_mcu.go +++ b/x/fmtx/fmtx_mcu.go @@ -1,4 +1,4 @@ -//go:build rp2040 +//go:build rp2040 || rp2350 package fmtx diff --git a/x/strconvx/strconvx_host.go b/x/strconvx/strconvx_host.go index 4a11dc2..bf918c6 100644 --- a/x/strconvx/strconvx_host.go +++ b/x/strconvx/strconvx_host.go @@ -1,4 +1,4 @@ -//go:build !rp2040 +//go:build !(rp2040 || rp2350) package strconvx diff --git a/x/strconvx/strconvx_mcu.go b/x/strconvx/strconvx_mcu.go index 2419083..f88516a 100644 --- a/x/strconvx/strconvx_mcu.go +++ b/x/strconvx/strconvx_mcu.go @@ -1,4 +1,4 @@ -//go:build rp2040 +//go:build rp2040 || rp2350 package strconvx