FreeRTOS SMP: Unable to call cyw43_arch_init outside of FreeRTOS task (intentional?) #1540
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#1540
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 am using upstream FreeRTOS with the SMP work merged into main (and using PR #1530 to fix the renaming of a FreeRTOS config).
I've successfully managed to convert the NTP client example Pico W example from its original LwIP raw API form to one using NO_SYS=0 FreeRTOS SMP and the LwIP socket API. In the process, I discovered that if I tried calling
cyw43_arch_initfrommain(), the pico would hard crash with no output whatsoever. It worked fine if called from a FreeRTOS task.I rigged up a second pico as a debug probe, and found a
hard_assertthat was failing inasync_context_freertos_execute_sync. Specifically:When called from
main()or outside of a FreeRTOS task,xTaskGetCurrentTaskHandle()returns 0, and in general I'm seeingxSemaphoreGetMutexHolder(self->lock_mutex)return 0 during initialization (as apparently no tasks have claimed the mutex). This clearly leads to the hard_assert to fire when callingasync_context_freertos_execute_syncoutside of a FreeRTOS task.Is this intentional? I'm also not 100% sure what that
hard_assertis checking. Is it to catch some sort of recursive calling/deadlock (although I don't see that mutex being claimed during init-- maybe it is in other execution paths?)?After some more experimentation, the implementation of
async_context_freertos_*functions, which are called bycyw43_arch_init, assume that they are taking place within the context of an already running FreeRTOS. For example,async_context_freertos_execute_synccallsxQueueSemaphoreTakenear its end, and that in turn callsvTaskPlaceOnEventList, which implicitly assumes the current thread is running within FreeRTOS.Per the documentation on
async_context_execute_syncI think I understand what thehard_assertis checking against-- it is very clear in the documentation that the context's lock should not be held by whoever is callingexecute_sync, so it's just checking against that.So it does look like this behavior is intentional-- it might be a good idea to document that when using the FreeRTOS async_context,
cyw43*functions should be called within a FreeRTOS task.edit: and possibly also
async_context_freertosfunctions.Yes, you're probably right - it needs to be documented.
I was thinking the other day that we really need more examples of this. Any chance of contributing this to pico-examples?
Sure, I've submitted a draft example based on my code. My own personal code was all in C++, so it took a bit but I managed to get it back to C.
Is there anything to do here? We added the ping example. Just a documentation issue perhaps?
Yes, I think it's just documentation stating that when using the FreeRTOS async_context, cyw43* functions should be called within a FreeRTOS task. Or something to that effect.