improve non-SWD quality-of-life with fault handler + postmortem support #228
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk#228
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
For folks developing using picoboot or U2F and debug chatter over ACM CDC, hard faults are pretty painful -- the device stops responding, host side drivers may wedge up, figuring out what blew up is hard.
One could provide in the SDK:
Just a minimal dump like this would probably be insightful in many cases:
OTOH, getting access to SWD only involves an additional $4 outlay for a second Raspberry Pi Pico and the usage of picoprobe 😉
I guess https://github.com/raspberrypi/pico-sdk/tree/develop/src/rp2_common/pico_bootsel_via_double_reset is a good template for how something like that could work (i.e. the looking for a special marker after reboot).
Indeed. Certainly it's what I prefer. But some people seem really allergic to it and then get very frustrated when they can't figure out why their program is failing. A little bit of effort in the SDK could brighten their days.
As somebody outside of the RPi organisation, can you see anything in the documentation that might be putting people off from using picoprobe? (i.e. are there any parts that could be made friendlier or more helpful?)
I maintain my own debugger an am aware that I'm pretty far from a "typical target user" -- personally I've always found openocd a little clunky and gdb even more clunky for the basic "attach + reset-and-halt + flash + reset" cycle with the occasional "dump registers and memory and look at backtraces".
I've seen some folks grumble about needing additional hardware and wires and software and whatnot -- perhaps feeling it's a extra burden to "just write some programs" (though you're right that $4 for a pico in picoprobe mode is probably the most affordable SWD interface available).
I can imagine that some people, looking at the pitch of "oh you don't need any special software, just drag your app on to the virtual usb drive" might find "oh and get a second board to run a debugger" to be an annoying increase in complexity.
This does sound really handy. I guess it should be in a known location (or at least one that can be found from a table in a known location, like the bininfo table) so that the debugger can also dump the state of the most recent crash, even if the system has already watchdogged.
As for printing out the last-exception state on boot, I can think of worse ideas than (optionally) hooking
stdio_init_all(), since this is the earliest point where stdout is known to work, and just printing the dump to all available stdouts.That's a great idea, but it seems that it takes a while for the USB serial console to connect, so I think if you were using USB CDC for stdio then this would already be 'gone' by the time e.g. mincom connected?
(A while ago I modified the
hello_worldexample to print to both UART and USB CDC, and to print an auto-incrementing number; and IIRC whilst the UART-connected minicom always caught every single print, the USB-connected minicom always missed the first couple)SWD is definitely a faff. On Linux, I have to have three different xterms open: one for openocd, one for gdb, and one for the terminal I'm actually developing on. Flashing via SWD is slow, so if you're working with large images it's actually faster to wire up a reset button and use the mass storage boot loader. (OTOH just being able to type load into gdb and have it work is so nice.) SWD also doesn't help if you're doing anything with USB, because as soon as the chip halts the host punts the device.
Re postmortem support: I like the idea, although I reckon it should be an optional feature; it should be up to the user to check for a postmortem report and register the handler, so that if they don't use it they don't pay for it.
I think a postmortem crash handler should stop after displaying the crash report rather than just continuing to run (and possibly crashing and rebooting over and over again) -- it could spit out its message via USB serial console on connect.
I also agree that it should be a build option. Not everyone will want or need it on every build.
It should certainly be possible to improve SWD flash speed -- my solution involves shooting down a little flash agent to sram to handle the actual heavy lifting (which on rp2040 is just calling the ROM routines) -- I expect if I adjusted the agent to spin up the clock first it could be competitive with USB. I certainly can download to RAM on most targets at 400KB/s or better. I've been porting my SWD backend to Pico and am still investigating performance differences vs LPCLINKII (the hardware I've traditionally used -- but that critter is $20 vs $4 for a spare Pico)
I don't know where your bottlenecks are but you could certainly set things up (you may already) such that you are writing to flash while downloading the next data
fixed by #1026