Skip to content

cyw43_arch_enable_sta_mode hangs when run on Core 1 when using async background mode #3148

Closed

Description

@MikeGRobins

I am having problems using the Pico SDK version 2.3.0.
Using arm-none-eabi-gcc 14.2.1 running on Raspberry Pi 5, make 4.4.1 and cmake 3.31.
Not using code, but manually running cmake and make.
The program hangs when trying to enable station mode - see gdb back-trace at foot of this essay.
This is similar to bug report #3118 which seems to RISC-specific.
Anyone else seeing anything similar?
The program works if run on core 0 or if run with Pico SDK version 2.2.0.
I have tried with and without ASYNC_CONTEXT_THREADSAFE_BACKGROUND_MULTI_CORE. Although I cannot find this flag in the docs, this should be ok since my application access the cyw43 and lwip stuff exclusively from core 1.

My C code:
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>

#include <pico/stdlib.h>
#include <boards/pico_w.h>
#include <pico/async_context_threadsafe_background.h>
#include <pico/cyw43_arch.h>
#include <pico/multicore.h>

static_assert(!offsetof(async_context_threadsafe_background_t,core));

static inline const void * toVoidPtr(void * p)
{
return p;
} /* toVoidPtr() */

static inline void cyw43_arch_set_async_context_threadsafe_background(async_context_threadsafe_background_t context[static 1])
{
cyw43_arch_set_async_context(&context->core);
} /* cyw43_arch_set_async_context_threadsafe_background() */

static inline void async_context_threadsafe_background_deinit(async_context_threadsafe_background_t context[static 1])
{
async_context_deinit(&context->core);
} /* async_context_threadsafe_background_deinit() */

static void core1Entry(void)
{
printf("Creating alarm pool - ");
alarm_pool_t * alarmPool = alarm_pool_create_with_unused_hardware_alarm(12);
if (alarmPool)
{
printf("done\nInitializing threadsafe background context - ");
async_context_threadsafe_background_config_t ctxConfig = async_context_threadsafe_background_default_config();
ctxConfig.custom_alarm_pool = alarmPool;
async_context_threadsafe_background_t context;
if (async_context_threadsafe_background_init(&context, &ctxConfig))
{
cyw43_arch_set_async_context_threadsafe_background(&context);
printf("done\nCyw43_init_with_country - ");
if (cyw43_arch_init_with_country(CYW43_COUNTRY_UK))
{
puts("\nFailed to initialize cyw43 driver");
cyw43_arch_deinit();
async_context_threadsafe_background_deinit(&context);
alarm_pool_destroy(alarmPool);
}
else
{
printf("done\nalarmPool = %p context.alarm_pool = %p",
toVoidPtr(alarmPool), toVoidPtr(context.alarm_pool));
printf("\nEnable station mode - ");
cyw43_arch_enable_sta_mode();
puts("done");
for (;;) {}
}
}
else
{
puts("\nFailed to initialize threadsafe background context");
async_context_threadsafe_background_deinit(&context);
alarm_pool_destroy(alarmPool);
}
}
else
{
puts("\nfailed to create alarm pool");
}
} /* core1Entry() */

int main(void)
{
stdout_uart_init();
#if 1
puts("\nBooting core 1");
multicore_launch_core1(core1Entry);
#else
puts("\nAll running on core 0");
core1Entry();
#endif
for (;;) ;
} /* main() */

My CMakeLists.txt:cmake_minimum_required(VERSION 3.31)
set(NAME c1_cyw43)
set(PICO_SDK_PATH ~/pico.2.3.0/pico-sdk)
message("Using sdk path from ${PICO_SDK_PATH}")
set(PICO_BOARD pico_w)
set(PICO_PLATFORM rp2040)
include("${PICO_SDK_PATH}/external/pico_sdk_import.cmake")
#include(pico_sdk_import.cmake)

project(${NAME} C CXX ASM)

pico_sdk_init()

add_executable(${NAME} c1_cyw43.c)

target_include_directories(${NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR})

#add_library(cmsis_core INTERFACE)

target_link_libraries(${NAME}
cmsis_core
pico_cyw43_arch_lwip_threadsafe_background
pico_lwip
pico_multicore
pico_stdlib)

disable usb output, enable uart output

pico_enable_stdio_usb(${NAME} 0)
pico_enable_stdio_uart(${NAME} 1)

pico_set_compile_definition(${NAME} PICO_DEFAULT_UART 1)
pico_set_compile_definition(${NAME} PICO_DEFAULT_UART_TX_PIN 8)
pico_set_compile_definition(${NAME} PICO_DEFAULT_UART_RX_PIN 9)
#pico_set_compile_definition(${NAME} CYW43_LWIP 0)
pico_set_compile_definition(${NAME} ASYNC_CONTEXT_THREADSAFE_BACKGROUND_MULTI_CORE 0)
#PICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 # Set automatically
#LIB_PICO_CYW43_ARCH=1 # Set automatically
#LIB_PICO_ASYNC_CONTEXT_THREADSAFE_BACKGROUND=1 # Set automatically
target_compile_definitions(${NAME} PRIVATE
WIFI_SSID="$ENV{WIFI_SSID}"
WIFI_PASS="$ENV{WIFI_PASSWORD}"
)

gdb back-trace:
(gdb) bt
#0 0x100016a6 in timer_time_reached (timer=0x40054000, t=587493) at /home/pi/pico.2.3.0/pico-sdk/src/rp2_common/hardware_timer/include/hardware/timer.h:323
#1 time_reached (t=587493) at /home/pi/pico.2.3.0/pico-sdk/src/rp2_common/hardware_timer/include/hardware/timer.h:335
#2 best_effort_wfe_or_timeout (timeout_timestamp=) at /home/pi/pico.2.3.0/pico-sdk/src/common/pico_time/time.c:486
#3 0x20000108 in sem_acquire_block_until (sem=0x20040fd8, until=) at /home/pi/pico.2.3.0/pico-sdk/src/common/pico_sync/sem.c:54
#4 0x1000f5c4 in async_context_threadsafe_background_wait_for_work_until (self_base=, until=)
at /home/pi/pico.2.3.0/pico-sdk/src/rp2_common/pico_async_context/async_context_threadsafe_background.c:317
#5 0x1000f33e in async_context_wait_for_work_until (context=, until=)
at /home/pi/pico.2.3.0/pico-sdk/src/rp2_common/pico_async_context/include/pico/async_context.h:424
#6 cyw43_await_background_or_timeout_us (timeout_us=timeout_us@entry=1000)
at /home/pi/pico.2.3.0/pico-sdk/src/rp2_common/pico_cyw43_driver/cyw43_driver.c:266
#7 0x1000c452 in cyw43_do_ioctl (self=self@entry=0x200013fc <cyw43_state>, kind=kind@entry=2, cmd=cmd@entry=263, len=len@entry=1008,
buf=buf@entry=0x20001440 <cyw43_state+68> "\t\332\005\234C-KB\016\304H\003\257\252\354;\t\230x\002,\202\026w\252\004\273˻\305\327'7\241Ғeׁ\002\262$\347.\002E9\210\303\311\f\351\356(\252\221\252\302a\b^\207@q둇,1^3\314\327\321z\243|\224\337\356\306Q\375\310J\313\375\352s\362H\253F\v윝\024\213\030i\237\003\202\037&H\30044\332)ƪم\374;\212$\026\227\310\374\323\027\2043gmD\301\273\271\220\351\031\3600\2429a%\364\030uv7\020\222;\362NW\344\327\a,\272&ϴ\v_\2307\365d9\211\bÃ\r\241\355v\334\,\250,ލ\244\001\362\034ȷ\321\357\300M\344\200\021\265", <incomplete sequence \365>..., iface=0)
at /home/pi/pico.2.3.0/pico-sdk/lib/cyw43-driver/src/cyw43_ll.c:1181
#8 0x1000d68c in cyw43_do_ioctl (kind=2, self=0x200013fc <cyw43_state>, cmd=263, len=1008,
buf=0x20001440 <cyw43_state+68> "\t\332\005\234C-KB\016\304H\003\257\252\354;\t\230x\002,\202\026w\252\004\273˻\305\327'7\241Ғeׁ\002\262$\347.\002E9\210\303\311\f\351\356(\252\221\252\302a\b^\207@q둇,1^3\314\327\321z\243|\224\337\356\306Q\375\310J\313\375\352s\362H\253F\v윝\024\213\030i\237\003\202\037&H\30044\332)ƪم\374;\212$\026\227\310\374\323\027\2043gmD\301\273\271\220\351\031\3600\2429a%\364\030uv7\020\222;\362NW\344\327\a,\272&ϴ\v_\2307\365d9\211\bÃ\r\241\355v\334\,\250,ލ\244\001\362\034ȷ\321\357\300M\344\200\021\265", <incomplete sequence \365>..., iface=0)
at /home/pi/pico.2.3.0/pico-sdk/lib/cyw43-driver/src/cyw43_ll.c:1156
#9 cyw43_clm_load (clm_len=984, self=0x200013fc <cyw43_state>, clm_ptr=0x1004b844 <w43439A0_7_95_49_00_combined+224256> "BLOB<")
at /home/pi/pico.2.3.0/pico-sdk/lib/cyw43-driver/src/cyw43_ll.c:1382
#10 cyw43_ll_bus_init (self_in=self_in@entry=0x200013fc <cyw43_state>, mac=mac@entry=0x0)
at /home/pi/pico.2.3.0/pico-sdk/lib/cyw43-driver/src/cyw43_ll.c:1764
#11 0x1000eb74 in cyw43_ensure_up (self=0x200013fc <cyw43_state>) at /home/pi/pico.2.3.0/pico-sdk/lib/cyw43-driver/src/cyw43_ctrl.c:183
#12 cyw43_wifi_on (self=0x200013fc <cyw43_state>, country=16967) at /home/pi/pico.2.3.0/pico-sdk/lib/cyw43-driver/src/cyw43_ctrl.c:477
#13 cyw43_wifi_set_up (self=0x200013fc <cyw43_state>, itf=itf@entry=0, up=up@entry=true, country=16967)
at /home/pi/pico.2.3.0/pico-sdk/lib/cyw43-driver/src/cyw43_ctrl.c:557
#14 0x1000aca8 in cyw43_arch_enable_sta_mode () at /home/pi/pico.2.3.0/pico-sdk/src/rp2_common/pico_cyw43_arch/cyw43_arch.c:33
#15 0x10000308 in core1Entry () at /home/pi/c1_cyw43/c1_cyw43.c:60
#16 0x1000f79e in core1_wrapper (entry=0x10000281 , stack_base=)
at /home/pi/pico.2.3.0/pico-sdk/src/rp2_common/pico_multicore/multicore.c:110
#17 0x0000017e in ?? ()
(gdb)

Activity

  1. peterharperuk commented on Aug 20, 2026

    @peterharperuk
    Contributor

    Hi. I could reproduce your problem. Can you try the develop branch? Some sleep fixes have just gone in and they resolve the problem for me.

  2. MikeGRobins commented on Aug 20, 2026

    @MikeGRobins
    Author

    Hi Peter
    Thanks for the very prompt response. The develop build resolves the problem. Please close this issue with comment that is fixed in the develop branch and will be fixed in the next release.
    Kind regards,
    Mike

  3. added this to the 2.3.1 milestone on Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions