Comments for https://wellys.com/posts/rp2040_c_macos/
Comments for: https://wellys.com/posts/rp2040_c_macos/
- RRob @rabarar
Can't seem to get openocd to work on a Mac M1 Max Pro
$ ./openocd -s ../tcl -f ./interface/picoprobe.cfg -f ./target/rp2040.cfg -c "program /Users/robert/src/pico/pico-examples/build/blink/blink.elf verify reset exit" Open On-Chip Debugger 0.11.0-g4f2ae61 (2021-12-22-19:50) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html Info : only one transport option; autoselect 'swd' adapter speed: 5000 kHz Info : Hardware thread awareness created Info : Hardware thread awareness created Info : RP2040 Flash Bank Command Info : clock speed 5000 kHz Info : DAP init failed in procedure 'program' ** OpenOCD init failed ** shutdown command invoked
I see the serial device
/dev/tty.usbmodem101
from flashing picoprobe, but can't get openocd to play nice! any ideas? Here's a longer version with debugging foropenocd
:$ ./openocd -d -s ../tcl -f ./interface/picoprobe.cfg -f ./target/rp2040.cfg -c "program /Users/robert/src/pico/pico-examples/build/blink/blink.elf verify reset exit" Open On-Chip Debugger 0.11.0-g4f2ae61 (2021-12-22-19:50) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html User : 13 2 options.c:63 configuration_output_handler(): debug_level: 3 User : 14 2 options.c:63 configuration_output_handler(): Debug: 15 2 configuration.c:42 add_script_search_dir(): adding ../tcl Debug: 16 2 options.c:244 add_default_dirs(): bindir=/usr/local/bin Debug: 17 2 options.c:245 add_default_dirs(): pkgdatadir=/usr/local/share/openocd Debug: 18 2 options.c:246 add_default_dirs(): exepath=/Users/robert/src/pico/openocd/src Debug: 19 2 options.c:247 add_default_dirs(): bin2data=../share/openocd Debug: 20 2 configuration.c:42 add_script_search_dir(): adding /Users/robert/Library/Preferences/org.openocd Debug: 21 2 configuration.c:42 add_script_search_dir(): adding /Users/robert/.config/openocd Debug: 22 2 configuration.c:42 add_script_search_dir(): adding /Users/robert/.openocd Debug: 23 2 configuration.c:42 add_script_search_dir(): adding /Users/robert/src/pico/openocd/src/../share/openocd/site Debug: 24 2 configuration.c:42 add_script_search_dir(): adding /Users/robert/src/pico/openocd/src/../share/openocd/scripts Debug: 25 3 configuration.c:97 find_file(): found ../tcl/./interface/picoprobe.cfg Debug: 26 3 command.c:146 script_debug(): command - adapter driver picoprobe Info : 28 3 transport.c:117 allow_transports(): only one transport option; autoselect 'swd' Debug: 29 3 command.c:146 script_debug(): command - adapter speed 5000 Debug: 31 3 core.c:1822 jtag_config_khz(): handle jtag khz Debug: 32 3 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value Debug: 33 3 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value User : 34 3 options.c:63 configuration_output_handler(): adapter speed: 5000 kHz User : 35 3 options.c:63 configuration_output_handler(): Debug: 36 3 configuration.c:97 find_file(): found ../tcl/./target/rp2040.cfg Debug: 37 3 configuration.c:97 find_file(): found ../tcl/target/swj-dp.tcl Debug: 38 3 command.c:146 script_debug(): command - transport select Debug: 39 3 configuration.c:97 find_file(): found ../tcl/mem_helper.tcl Debug: 40 3 command.c:146 script_debug(): command - add_usage_text mrw address Debug: 42 3 command.c:1115 help_add_command(): added 'mrw' help text Debug: 43 3 command.c:146 script_debug(): command - add_help_text mrw Returns value of word in memory. Debug: 45 3 command.c:1128 help_add_command(): added 'mrw' help text Debug: 46 3 command.c:146 script_debug(): command - add_usage_text mrh address Debug: 48 3 command.c:1115 help_add_command(): added 'mrh' help text Debug: 49 3 command.c:146 script_debug(): command - add_help_text mrh Returns value of halfword in memory. Debug: 51 3 command.c:1128 help_add_command(): added 'mrh' help text Debug: 52 3 command.c:146 script_debug(): command - add_usage_text mrb address Debug: 54 3 command.c:1115 help_add_command(): added 'mrb' help text Debug: 55 3 command.c:146 script_debug(): command - add_help_text mrb Returns value of byte in memory. Debug: 57 3 command.c:1128 help_add_command(): added 'mrb' help text Debug: 58 3 command.c:146 script_debug(): command - add_usage_text mmw address setbits clearbits Debug: 60 3 command.c:1115 help_add_command(): added 'mmw' help text Debug: 61 3 command.c:146 script_debug(): command - add_help_text mmw Modify word in memory. new_val = (old_val & ~clearbits) | setbits; Debug: 63 3 command.c:1128 help_add_command(): added 'mmw' help text Debug: 64 3 command.c:146 script_debug(): command - transport select Debug: 65 3 command.c:146 script_debug(): command - transport select Debug: 66 3 command.c:146 script_debug(): command - swd newdap rp2040.core0 cpu -dp-id 0x01002927 -instance-id 0 Debug: 67 3 tcl.c:610 jim_newtap_cmd(): Creating New Tap, Chip: rp2040.core0, Tap: cpu, Dotted: rp2040.core0.cpu, 4 params Debug: 68 3 tcl.c:623 jim_newtap_cmd(): Processing option: -dp-id Debug: 69 3 tcl.c:623 jim_newtap_cmd(): Processing option: -instance-id Debug: 70 3 core.c:1488 jtag_tap_init(): Created Tap: rp2040.core0.cpu @ abs position 0, irlen 0, capture: 0x0 mask: 0x0 Debug: 71 3 command.c:146 script_debug(): command - transport select Debug: 72 3 command.c:146 script_debug(): command - transport select Debug: 73 3 command.c:146 script_debug(): command - swd newdap rp2040.core1 cpu -dp-id 0x01002927 -instance-id 1 Debug: 74 3 tcl.c:610 jim_newtap_cmd(): Creating New Tap, Chip: rp2040.core1, Tap: cpu, Dotted: rp2040.core1.cpu, 4 params Debug: 75 3 tcl.c:623 jim_newtap_cmd(): Processing option: -dp-id Debug: 76 3 tcl.c:623 jim_newtap_cmd(): Processing option: -instance-id Debug: 77 3 core.c:1488 jtag_tap_init(): Created Tap: rp2040.core1.cpu @ abs position 1, irlen 0, capture: 0x0 mask: 0x0 Debug: 78 3 command.c:146 script_debug(): command - dap create rp2040.core0.dap -chain-position rp2040.core0.cpu Debug: 79 3 command.c:146 script_debug(): command - target create rp2040.core0 cortex_m -endian little -coreid 0 -dap rp2040.core0.dap -rtos hwthread Info : 80 3 hwthread.c:390 hwthread_create(): Hardware thread awareness created Debug: 81 3 command.c:376 register_command(): command 'smp_gdb' is already registered in 'cortex_m' context Debug: 82 3 command.c:376 register_command(): command 'rtt' is already registered in '<global>' context Debug: 83 3 command.c:376 register_command(): command 'smp_gdb' is already registered in 'cortex_m' context Debug: 84 3 command.c:146 script_debug(): command - rp2040.core0 configure -work-area-phys 0x20010000 -work-area-size 0x10000 -work-area-backup 0 Debug: 85 3 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas Debug: 86 3 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas Debug: 87 3 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas Debug: 88 3 command.c:146 script_debug(): command - cortex_m reset_config sysresetreq Debug: 90 3 command.c:146 script_debug(): command - dap create rp2040.core1.dap -chain-position rp2040.core1.cpu Debug: 91 3 command.c:146 script_debug(): command - target create rp2040.core1 cortex_m -endian little -coreid 1 -dap rp2040.core1.dap -rtos hwthread Info : 92 3 hwthread.c:390 hwthread_create(): Hardware thread awareness created Debug: 93 3 command.c:376 register_command(): command 'arm' is already registered in '<global>' context Debug: 94 3 command.c:376 register_command(): command 'reg' is already registered in 'arm' context Debug: 95 3 command.c:376 register_command(): command 'core_state' is already registered in 'arm' context Debug: 96 3 command.c:376 register_command(): command 'disassemble' is already registered in 'arm' context Debug: 97 3 command.c:376 register_command(): command 'mcr' is already registered in 'arm' context Debug: 98 3 command.c:376 register_command(): command 'mrc' is already registered in 'arm' context Debug: 99 3 command.c:376 register_command(): command 'semihosting' is already registered in 'arm' context Debug: 100 3 command.c:376 register_command(): command 'semihosting_cmdline' is already registered in 'arm' context Debug: 101 3 command.c:376 register_command(): command 'semihosting_fileio' is already registered in 'arm' context Debug: 102 3 command.c:376 register_command(): command 'semihosting_resexit' is already registered in 'arm' context Debug: 103 3 command.c:376 register_command(): command 'tpiu' is already registered in '<global>' context Debug: 104 3 command.c:376 register_command(): command 'config' is already registered in 'tpiu' context Debug: 105 3 command.c:376 register_command(): command 'itm' is already registered in '<global>' context Debug: 106 3 command.c:376 register_command(): command 'port' is already registered in 'itm' context Debug: 107 3 command.c:376 register_command(): command 'ports' is already registered in 'itm' context Debug: 108 3 command.c:376 register_command(): command 'cortex_m' is already registered in '<global>' context Debug: 109 3 command.c:376 register_command(): command 'smp_gdb' is already registered in 'cortex_m' context Debug: 110 3 command.c:376 register_command(): command 'maskisr' is already registered in 'cortex_m' context Debug: 111 3 command.c:376 register_command(): command 'vector_catch' is already registered in 'cortex_m' context Debug: 112 3 command.c:376 register_command(): command 'reset_config' is already registered in 'cortex_m' context Debug: 113 3 command.c:376 register_command(): command 'smp' is already registered in 'cortex_m' context Debug: 114 3 command.c:376 register_command(): command 'smp_on' is already registered in 'cortex_m' context Debug: 115 3 command.c:376 register_command(): command 'smp_off' is already registered in 'cortex_m' context Debug: 116 3 command.c:376 register_command(): command 'smp_gdb' is already registered in 'cortex_m' context Debug: 117 3 command.c:376 register_command(): command 'rtt' is already registered in '<global>' context Debug: 118 3 command.c:376 register_command(): command 'setup' is already registered in 'rtt' context Debug: 119 3 command.c:376 register_command(): command 'start' is already registered in 'rtt' context Debug: 120 3 command.c:376 register_command(): command 'stop' is already registered in 'rtt' context Debug: 121 3 command.c:376 register_command(): command 'polling_interval' is already registered in 'rtt' context Debug: 122 3 command.c:376 register_command(): command 'channels' is already registered in 'rtt' context Debug: 123 3 command.c:376 register_command(): command 'channellist' is already registered in 'rtt' context Debug: 124 4 command.c:376 register_command(): command 'smp_gdb' is already registered in 'cortex_m' context Debug: 125 4 command.c:146 script_debug(): command - rp2040.core1 configure -work-area-phys 0x20010000 -work-area-size 0x10000 -work-area-backup 0 Debug: 126 4 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas Debug: 127 4 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas Debug: 128 4 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas Debug: 129 4 command.c:146 script_debug(): command - cortex_m reset_config sysresetreq Debug: 131 4 command.c:146 script_debug(): command - target smp rp2040.core0 rp2040.core1 Debug: 132 4 target.c:5943 jim_target_smp(): 3 Debug: 133 4 target.c:5953 jim_target_smp(): rp2040.core0 Debug: 134 4 target.c:5953 jim_target_smp(): rp2040.core1 Debug: 135 4 hwthread.c:200 hwthread_update_threads(): hwthread_update_threads current_thread=-1 Debug: 136 4 command.c:146 script_debug(): command - flash bank rp2040.flash rp2040_flash 0x10000000 0x200000 1 32 rp2040.core0 Info : 138 4 rp2040.c:394 rp2040_flash_bank_command(): RP2040 Flash Bank Command Debug: 139 4 tcl.c:1319 handle_flash_bank_command(): 'rp2040_flash' driver usage field missing Debug: 140 4 command.c:146 script_debug(): command - targets rp2040.core0 Debug: 142 4 command.c:146 script_debug(): command - reset_config srst_nogate Debug: 144 4 command.c:146 script_debug(): command - gdb_flash_program enable Debug: 146 4 command.c:146 script_debug(): command - gdb_memory_map enable Debug: 148 4 command.c:146 script_debug(): command - init Debug: 150 4 command.c:146 script_debug(): command - target init Debug: 152 4 command.c:146 script_debug(): command - target names Debug: 153 4 command.c:146 script_debug(): command - rp2040.core0 cget -event gdb-flash-erase-start Debug: 154 4 command.c:146 script_debug(): command - rp2040.core0 configure -event gdb-flash-erase-start reset init Debug: 155 4 command.c:146 script_debug(): command - rp2040.core0 cget -event gdb-flash-write-end Debug: 156 4 command.c:146 script_debug(): command - rp2040.core0 configure -event gdb-flash-write-end reset halt Debug: 157 4 command.c:146 script_debug(): command - rp2040.core0 cget -event gdb-attach Debug: 158 4 command.c:146 script_debug(): command - rp2040.core0 configure -event gdb-attach halt 1000 Debug: 159 4 command.c:146 script_debug(): command - rp2040.core1 cget -event gdb-flash-erase-start Debug: 160 4 command.c:146 script_debug(): command - rp2040.core1 configure -event gdb-flash-erase-start reset init Debug: 161 4 command.c:146 script_debug(): command - rp2040.core1 cget -event gdb-flash-write-end Debug: 162 4 command.c:146 script_debug(): command - rp2040.core1 configure -event gdb-flash-write-end reset halt Debug: 163 4 command.c:146 script_debug(): command - rp2040.core1 cget -event gdb-attach Debug: 164 4 command.c:146 script_debug(): command - rp2040.core1 configure -event gdb-attach halt 1000 Debug: 165 4 target.c:1639 handle_target_init_command(): Initializing targets... Debug: 166 4 semihosting_common.c:99 semihosting_common_init(): Debug: 167 4 semihosting_common.c:99 semihosting_common_init(): Debug: 168 6 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value Debug: 169 6 core.c:1789 adapter_khz_to_speed(): have interface set up Debug: 170 7 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value Debug: 171 7 core.c:1789 adapter_khz_to_speed(): have interface set up Info : 172 7 core.c:1565 adapter_init(): clock speed 5000 kHz Debug: 173 7 openocd.c:143 handle_init_command(): Debug Adapter init complete Debug: 174 7 command.c:146 script_debug(): command - transport init Debug: 176 7 transport.c:229 handle_transport_init(): handle_transport_init Debug: 177 7 command.c:146 script_debug(): command - dap init Debug: 179 7 arm_dap.c:116 dap_init_all(): Initializing all DAPs ... Debug: 180 7 picoprobe.c:453 picoprobe_swd_switch_seq(): DORMANT-to-SWD Debug: 181 7 adi_v5_swd.c:699 swd_multidrop_select_target(): Failed to select core 0, retrying... Debug: 182 8 adi_v5_swd.c:699 swd_multidrop_select_target(): Failed to select core 0, retrying... Debug: 183 8 adi_v5_swd.c:699 swd_multidrop_select_target(): Failed to select core 0 Info : 184 8 arm_dap.c:337 handle_dap_init(): DAP init failed Debug: 185 8 command.c:629 run_command(): Command 'dap init' failed with error code -4 User : 186 8 command.c:694 command_run_line(): in procedure 'program' Debug: 187 8 command.c:629 run_command(): Command 'init' failed with error code -4 Debug: 188 8 command.c:146 script_debug(): command - echo ** OpenOCD init failed ** User : 190 8 command.c:769 jim_echo(): ** OpenOCD init failed ** Debug: 191 8 command.c:146 script_debug(): command - shutdown error User : 193 8 server.c:755 handle_shutdown_command(): shutdown command invoked Debug: 194 8 command.c:629 run_command(): Command 'shutdown' failed with error code -4 User : 195 8 command.c:694 command_run_line(): Debug: 196 8 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas Debug: 197 8 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas Debug: 198 8 picoprobe.c:457 picoprobe_swd_switch_seq(): SWD-to-DORMANT Debug: 199 8 picoprobe.c:453 picoprobe_swd_switch_seq(): DORMANT-to-SWD Debug: 200 9 adi_v5_swd.c:699 swd_multidrop_select_target(): Failed to select core 0, retrying... Debug: 201 9 adi_v5_swd.c:699 swd_multidrop_select_target(): Failed to select core 0, retrying... Debug: 202 10 adi_v5_swd.c:699 swd_multidrop_select_target(): Failed to select core 0
- R
- LLief Koepsel @lkoepsel
That's great! Not sure I could have helped on that. :)
OpenOCD is a bit flakey on an M1...that said, the 2 Pico solution for a hardware debugger is awesome. I'm working on some AVR material and there isn't anything remotely comparable.
Thanks for letting me know and GOOD LUCK!
Lief- RRob @rabarar
Thanks Lief - appreciate the feedback - next i want to try out the gdb CLL command and see if I can get that working as well - just a point of clarification - the serial device that you're connecting to is via the USB - does the target RP2040 need the UART connected to the picoprobe RP2040 in order for that serial device to work?
UPDATE: So CLL works great! and you do need the UART of the target connected to the picoprobe UART to access it via the host through the USB connection - great stuff! Thanks again for the writeup!
- LLief Koepsel @lkoepsel
Great for you!
As you found out, you’ll need to connect the target 2040 through the probe in order to have serial communications from the target. And CLL is extremely helpful on shortening the compilation/link/load cycle!
You might check out the gab resources page, it’s full of links to gdb debugging. https://wellys.com/posts/gdb_resources/
- RRob @rabarar
Thanks Leif, I’ve been using gdb gcc et, al. for over 30 years….
- CIn reply tosystem⬆:@chriskiwi
I tried following this route for my M1 Max install. I've been struggling for a while to nail up this toolchain (Clion for RP2040) and there seem to be more gotchas than seems completely fair....
I got to the"brew install libtool automake libusb wget pkg-config gcc texinfo"
step above and I see that brew installed everything with the warning that everything was being installed pre-fixed with a "g".
This is new to me. I think it related to a conflict with my Xcode installation.I wasn't too keen to carry on just in case I really started to make a mess of things.
Am I worrying about nothing? Is this the way to go or has a more up to date guide on this appeared in the meantime?
Thanks in advance to any and all for any guidance and/or pointers that might help.
- AIn reply tosystem⬆:@awzonke
Hi all - I'm unable to find arm-none-eabi-gdb using Homebrew. It seems from the notes above it should be possible to get this installed. Any pointers to the correct installation method? I'm on an M1 Mac running Monterey. Thanks!
- LLief Koepsel @lkoepsel
UPDATED
There is a bug in the ARM GCC compiler on M1 Macs, see UPDATED April 7th, 2022 above.
The rest of this is the journey that got me there...ignore it.
I just did a brew list and it shows gcc-arm-embedded as a Cask. I also did a search on brew.sh and, it didn't show anything for arm-none-eabi-gcc, it does show gcc-arm-embedded.
I also went to the GNU Arm Embedded Toolchain Downloads site and found it was deprecated. When you click on the Arm GNU Toolchain button, it takes you to a new site GNU Toolchain for the Arm Architecture which describes the compiler as gcc...which is probably gcc-arm-embedded.
All of this to say (or confirm) that you need to install gcc-arm-embedded.
Update:
I removed the old arm-none-eabi-gcc and performed a brew update and brew upgrade, which installed a new version of gcc-arm-embedded. Then I ran cmake .. as described in the entry:PICO_SDK_PATH is /Users/lkoepsel/Documents/pico/pico-sdk PICO platform is rp2040. -- The C compiler identification is GNU 11.2.1 -- The CXX compiler identification is GNU 11.2.1 -- The ASM compiler identification is GNU -- Found assembler: /opt/homebrew/bin/arm-none-eabi-gcc Using regular optimized debug build (set PICO_DEOPTIMIZED_DEBUG=1 to de-optimize) PICO target board is pico. Using board configuration from /Users/lkoepsel/Documents/pico/pico-sdk/src/boards/include/boards/pico.h -- Found Python3: /opt/homebrew/Frameworks/Python.framework/Versions/3.9/bin/python3.9 (found version "3.9.12") found components: Interpreter TinyUSB available at /Users/lkoepsel/Documents/pico/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040; adding USB support. Compiling TinyUSB with CFG_TUSB_DEBUG=1 -- Configuring done -- Generating done -- Build files have been written to: /Users/lkoepsel/Documents/pico/pico-examples/build
And the system froze at:
[ 0%] Building C object blink/CMakeFiles/blink.dir/Users/lkoepsel/Documents/pico/pico-sdk/src/rp2_common/pico_platform/platform.c.objKilled it and deleted the entire build folder then reran:
mkdir build cd build cmake .. cd blink make -j4
And it appeared to freeze again. My next step is to delete everything and start all over with my instructions. The examples, sdk etc are all over a year old...
Last update: Failure
I was using a new terminal program, switched back to iTerm and re-did all the steps. I am getting the following errors:
Building C object blink/CMakeFiles/blink.dir/blink.c.obj Building C object blink/CMakeFiles/blink.dir/Users/lkoepsel/Documents/pico2/pico-sdk/src/rp2_common/pico_stdlib/stdlib.c.obj Building C object blink/CMakeFiles/blink.dir/Users/lkoepsel/Documents/pico2/pico-sdk/src/rp2_common/hardware_gpio/gpio.c.obj Building C object blink/CMakeFiles/blink.dir/Users/lkoepsel/Documents/pico2/pico-sdk/src/rp2_common/hardware_claim/claim.c.obj during GIMPLE pass: evrp /Users/lkoepsel/Documents/pico2/pico-sdk/src/rp2_common/pico_stdlib/stdlib.c: In function 'check_sys_clock_khz': /Users/lkoepsel/Documents/pico2/pico-sdk/src/rp2_common/pico_stdlib/stdlib.c:104:1: internal compiler error: Illegal instruction: 4 104 | } | ^ Please submit a full bug report, with preprocessed source if appropriate. See <https://bugs.linaro.org/> for instructions. make[2]: *** [blink/CMakeFiles/blink.dir/Users/lkoepsel/Documents/pico2/pico-sdk/src/rp2_common/pico_stdlib/stdlib.c.obj] Error 1 make[2]: *** Waiting for unfinished jobs.... during GIMPLE pass: evrp /Users/lkoepsel/Documents/pico2/pico-sdk/src/rp2_common/hardware_gpio/gpio.c: In function 'gpio_irq_handler': /Users/lkoepsel/Documents/pico2/pico-sdk/src/rp2_common/hardware_gpio/gpio.c:227:1: internal compiler error: Illegal instruction: 4 227 | } | ^ Please submit a full bug report,
Haven't found a working solution.
Sigh, it appears one of the working solutions is to use an Intel Mac. Just attempted the above instructions on an 2018 MBP and it ran fine.
Thanks for the updated process - I've got it working with VS Code on my M1 Mac mini. After using your steps above, I just needed to update the paths in the launch.json (from the "Getting Started" manual) for picoprobe.cfg and rp2040.cfg. The relative paths didn't work, so I used the full paths. Then just needed to add the line "cortex-debug.openocdPath" to the settings.json with the path to openocd. From there I'm able to use VS Code's built-in debug tool.