gpio_set_irq_enabled in pico-sdk 2.1.0 hits assert on RP2040 #2266
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#2266
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?
I have some RP2040 code which used to work fine in pico-sdk 1.4.0.
Now, I've upgraded to pico-sdk 2.1.0, and after making all the changes so the project builds again, I've stumbled upon quite a surprising problem - namely, somewhat randomly, the code fails to run after being flashed on the RP2040 MCU, because it hits an assert in
gpio_set_irq_enabled.I say that I hit the condition "somewhat randomly", because the first time I noticed this problem with the Debug .elf, I think I just reflashed the same .elf (or maybe I rebuilt the code, however without any code changes, can't really remember exactly), and then it started working. But then I rebuilt and reflashed Debug .elf again, and it started hitting the assert again; ever since, I cannot build a Debug .elf which works (does not hit the assert). However, I have built a Release .elf that does work.
I have seen gpio_set_irq_enabled() will not enable GPIO interrupt handling · Issue #1594 · raspberrypi/pico-sdk and tried to reorganize my setup code according to https://github.com/raspberrypi/pico-sdk/issues/1594#issuecomment-1888396046 .
My
main()function in this project calls this function somewhere at start:... where the function prototype for
on_gpio_edge_isrisI compile in a MINGW64
bashshell on Windows 10, with:Here is a transcript of gdb-multiarch session, where the assert has been hit after flashing, and then (after program restart) stepping through the first three lines of
prestart_irq_setup(some spacing added, and removed "target halted due ..." lines afterpcommands, for readability):So, I guess, neither of
irq_set_exclusive_handlerorirq_set_enabledchanges neithercallbacksnorraw_irq_maskfrom their starting value of 0 for that core, which ends up triggering the assert ingpio_set_irq_enabled.I've also tried using
gpio_set_irq_callback( &on_gpio_edge_isr );instead ofirq_set_exclusive_handler, but it generates compiler warnings:,,, as it apparently expects a function with two int arguments instead of no (void) arguments; this skips the assert and allows the rest of my code to run, but
on_gpio_edge_isrnever fires (so overall, it does not work for me). Apparently I'm usinggpio_set_irq_callbackincorrectly, as I'd need a different prototype foron_gpio_edge_isr, but I haven't been able to find a proper example for that so far. But at least, it confirms thatgpio_set_irq_callbackdoes set eithercallbacksorraw_irq_mask, as the assert ingpio_set_irq_enabledis not hit.What can I do, to have my code running again?
ah, the assertion (which is trying to be helpful) assumes you have used some of the
hardware_gpiofunctionality to set up the IRQ handler (either viagpio_set_irq_callbackorgpio_add_raw_irq_handler... it should probably be relaxedMany thanks, @kilograham
Great - thanks for the hint: I tried
gpio_add_raw_irq_handler( iopins.PIN_RX, on_gpio_edge_isr );instead ofirq_set_exclusive_handler( IO_IRQ_BANK0, on_gpio_edge_isr );and things seem to work fine again; although if the assert gets relaxed in 2.1.1, I'd definitely try to go back toirq_set_exclusive_handler, just to keep changes in respect to older versions of my code minimal.fix merged into develop