Last active
October 1, 2025 05:28
-
-
Save vogon/4c08fdd31a565609d02cb2534a4386bd to your computer and use it in GitHub Desktop.
pico SDK async_context race condition repro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include "pico/stdlib.h" | |
| #include "hardware/spi.h" | |
| #include "pico/cyw43_arch.h" | |
| #include <lwip/apps/http_client.h> | |
| #include "pico/sync.h" | |
| #include "FreeRTOS.h" | |
| #include "task.h" | |
| #include "tusb.h" | |
| // e-paper breakout pinout: | |
| // SCK GP14, MISO GP12, MOSI GP15, ECS GP13, D/C GP11, SRCS GP10, SDCS GP9, | |
| // RST GP8, BUSY GP7, ENA GP6 | |
| #define SPI_PORT spi1 | |
| #define PIN_MISO 12 | |
| #define PIN_CS 13 | |
| #define PIN_SCK 14 | |
| #define PIN_MOSI 15 | |
| static TaskHandle_t xTaskToNotify = NULL; | |
| const UBaseType_t xArrayIndex = 0; | |
| static void update_message_task(void * pvParameters) { | |
| while (true) { | |
| // Initialise the Wi-Fi chip | |
| if (cyw43_arch_init()) { | |
| printf("Wi-Fi init failed\n"); | |
| return; | |
| // // return -1; | |
| } | |
| printf("cyw43_arch_init done\n"); | |
| // Enable wifi station | |
| cyw43_arch_enable_sta_mode(); | |
| printf("Hello, world!\n"); | |
| cyw43_arch_deinit(); | |
| vTaskDelay(pdMS_TO_TICKS(60000)); | |
| } | |
| } | |
| int main() | |
| { | |
| stdio_init_all(); | |
| while (!tud_cdc_connected()) { sleep_ms(100); } | |
| printf("usb connected! running\n"); | |
| printf("waking up\n"); | |
| TaskHandle_t um_task; | |
| xTaskCreate(update_message_task, | |
| "update message", | |
| 32 * configMINIMAL_STACK_SIZE, | |
| NULL, | |
| tskIDLE_PRIORITY + 1, | |
| &um_task | |
| ); | |
| vTaskCoreAffinitySet(um_task, 0x01); | |
| printf("task created\n"); | |
| vTaskStartScheduler(); | |
| printf("FATAL: Scheduler returned!\n"); | |
| while (1) sleep_ms(1000); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Generated Cmake Pico project file | |
| cmake_minimum_required(VERSION 3.13) | |
| set(CMAKE_C_STANDARD 11) | |
| set(CMAKE_CXX_STANDARD 17) | |
| set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | |
| # Initialise pico_sdk from installed location | |
| # (note this can come from environment, CMake cache etc) | |
| # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == | |
| if(WIN32) | |
| set(USERHOME $ENV{USERPROFILE}) | |
| else() | |
| set(USERHOME $ENV{HOME}) | |
| endif() | |
| set(sdkVersion 2.2.0) | |
| set(toolchainVersion 14_2_Rel1) | |
| set(picotoolVersion 2.2.0) | |
| set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) | |
| if (EXISTS ${picoVscode}) | |
| include(${picoVscode}) | |
| endif() | |
| # ==================================================================================== | |
| set(PICO_BOARD pico2_w CACHE STRING "Board type") | |
| include(pico_sdk_import.cmake) | |
| add_library(freertos_config INTERFACE) | |
| target_include_directories(freertos_config INTERFACE ${CMAKE_SOURCE_DIR}/include) | |
| include(FetchContent) | |
| FetchContent_Populate(freertos_kernel | |
| GIT_REPOSITORY "https://github.com/FreeRTOS/FreeRTOS-Kernel.git" | |
| GIT_TAG "V11.2.0" | |
| ) | |
| set(FREERTOS_KERNEL_PATH "${CMAKE_CURRENT_BINARY_DIR}/freertos_kernel-src" CACHE STRING "FreeRTOS Location" FORCE) | |
| add_subdirectory(${FREERTOS_KERNEL_PATH}/portable/ThirdParty/Community-Supported-Ports/GCC/RP2350_ARM_NTZ) | |
| project(ais-epaper C CXX ASM) | |
| # Initialise the Raspberry Pi Pico SDK | |
| pico_sdk_init() | |
| add_executable(ais-epaper) | |
| pico_enable_stdio_uart(ais-epaper 0) | |
| pico_enable_stdio_usb(ais-epaper 1) | |
| target_sources(ais-epaper PRIVATE ais-epaper.c freertos/hooks.c) | |
| target_include_directories(ais-epaper PRIVATE ${CMAKE_SOURCE_DIR} include) | |
| target_compile_definitions(ais-epaper PUBLIC | |
| NO_SYS=0 | |
| WANT_HCI_DUMP=1 | |
| ) | |
| target_link_libraries(ais-epaper PUBLIC | |
| FreeRTOS-Kernel-Heap4 | |
| freertos_config | |
| hardware_spi | |
| pico_lwip_http | |
| pico_sync | |
| pico_stdlib | |
| pico_cyw43_arch_lwip_sys_freertos | |
| ) | |
| pico_add_extra_outputs(ais-epaper) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include "pico.h" | |
| #include <stddef.h> | |
| // =================================================================================== | |
| // PICO-SPECIFIC CONFIG | |
| // =================================================================================== | |
| /* SMP/monocore selection */ | |
| #if PICO_NO_HARDWARE | |
| #define configNUMBER_OF_CORES 1 | |
| #else | |
| #if defined(PICO_RP2350) || defined(PICO_RP2040) | |
| #define configNUMBER_OF_CORES 2 | |
| #define configUSE_CORE_AFFINITY 1 | |
| #define configRUN_MULTIPLE_PRIORITIES 1 | |
| #define configUSE_PASSIVE_IDLE_HOOK 0 | |
| #else | |
| #define configNUMBER_OF_CORES 1 | |
| #endif | |
| #endif | |
| #define configTICK_CORE 0 | |
| /* CPU / FPU / TrustZone */ | |
| #if defined(PICO_RP2350) | |
| #define configCPU_CLOCK_HZ 150000000 | |
| #define configENABLE_TRUSTZONE 0 | |
| #define configENABLE_MPU 0 | |
| #define configENABLE_FPU 1 | |
| #define configRUN_FREERTOS_SECURE_ONLY 1 | |
| #define configMAX_SYSCALL_INTERRUPT_PRIORITY 16 | |
| #elif defined(PICO_RP2040) | |
| #define configCPU_CLOCK_HZ 133000000 | |
| #endif | |
| /* ISR vector remap */ | |
| #define vPortSVCHandler isr_svcall | |
| #define xPortPendSVHandler isr_pendsv | |
| #define xPortSysTickHandler isr_systick | |
| #define configSUPPORT_PICO_SYNC_INTEROP 1 | |
| #define configSUPPORT_PICO_TIME_INTEROP 1 | |
| /* Compatibility for lwIP */ | |
| #ifndef portTICK_RATE_MS | |
| #define portTICK_RATE_MS portTICK_PERIOD_MS | |
| #endif | |
| #define INCLUDE_xSemaphoreGetMutexHolder 1 | |
| // =================================================================================== | |
| // COMMON FREERTOS CONFIG | |
| // =================================================================================== | |
| /* Scheduler Related */ | |
| #define configUSE_PREEMPTION 1 | |
| #define configUSE_TIME_SLICING 1 | |
| #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 | |
| #define configUSE_TICKLESS_IDLE 0 | |
| #define configMAX_PRIORITIES 32 | |
| #define configIDLE_SHOULD_YIELD 1 | |
| #define configUSE_TASK_NOTIFICATIONS 1 | |
| #define configTASK_NOTIFICATION_ARRAY_ENTRIES 3 | |
| /* System */ | |
| #define configSTACK_DEPTH_TYPE uint32_t | |
| #define configMESSAGE_BUFFER_LENGTH_TYPE size_t | |
| /* Memory allocation related definitions. */ | |
| #define configSUPPORT_STATIC_ALLOCATION 1 // Set to 1 | |
| #define configSUPPORT_DYNAMIC_ALLOCATION 1 | |
| #define configTOTAL_HEAP_SIZE (128*1024) | |
| #define configAPPLICATION_ALLOCATED_HEAP 0 | |
| /* Hook function related definitions. */ | |
| #define configUSE_IDLE_HOOK 0 | |
| #define configUSE_TICK_HOOK 0 | |
| #define configCHECK_FOR_STACK_OVERFLOW 2 // Set to 2 | |
| #define configUSE_MALLOC_FAILED_HOOK 1 // Set to 1 | |
| #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 | |
| /* Run time and task stats gathering related definitions. */ | |
| #define configGENERATE_RUN_TIME_STATS 0 | |
| #define configUSE_TRACE_FACILITY 1 | |
| #define configUSE_STATS_FORMATTING_FUNCTIONS 0 | |
| /* Possible values are portCLEAN_UP_TCB, portPRE_DELETION_HOOK_TCB. */ | |
| #define configTASK_DELETION_SUPPORT 0 | |
| /* Co-routine related definitions. */ | |
| #define configUSE_CO_ROUTINES 0 | |
| #define configMAX_CO_ROUTINE_PRIORITIES 1 | |
| /* Software timer related definitions. */ | |
| #define configUSE_TIMERS 1 | |
| #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) | |
| #define configTIMER_QUEUE_LENGTH 10 | |
| #define configTIMER_TASK_STACK_DEPTH 1024 | |
| /* Interrupt nesting behaviour configuration. */ | |
| /* | |
| #define configKERNEL_INTERRUPT_PRIORITY [dependent of processor] | |
| #define configMAX_SYSCALL_INTERRUPT_PRIORITY [dependent on processor and application] | |
| #define configMAX_API_CALL_INTERRUPT_PRIORITY [dependent on processor and application] | |
| */ | |
| #include <assert.h> | |
| /* Define to trap errors during development. */ | |
| #define configASSERT(x) assert(x) | |
| /* Define the sizes and usage. */ | |
| #define configTICK_RATE_HZ 1000 | |
| #define configMAX_TASK_NAME_LEN 16 | |
| #define configMINIMAL_STACK_SIZE 128 | |
| #define configUSE_16_BIT_TICKS 0 | |
| /* Mutexes */ | |
| #define configUSE_MUTEXES 1 | |
| #define configUSE_RECURSIVE_MUTEXES 1 | |
| #define configUSE_APPLICATION_TASK_TAG 0 | |
| #define configUSE_COUNTING_SEMAPHORES 1 | |
| #define configQUEUE_REGISTRY_SIZE 8 | |
| #define configUSE_QUEUE_SETS 1 | |
| #define configUSE_NEWLIB_REENTRANT 0 | |
| #define configENABLE_BACKWARD_COMPATIBILITY 0 | |
| #define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5 | |
| /* Optional functions - most linkers will remove unused functions anyway. */ | |
| #define INCLUDE_vTaskPrioritySet 1 | |
| #define INCLUDE_uxTaskPriorityGet 1 | |
| #define INCLUDE_vTaskDelete 1 | |
| #define INCLUDE_vTaskSuspend 1 | |
| #define INCLUDE_xResumeFromISR 1 | |
| #define INCLUDE_vTaskDelayUntil 1 | |
| #define INCLUDE_vTaskDelay 1 | |
| #define INCLUDE_xTaskGetSchedulerState 1 | |
| #define INCLUDE_xTaskGetCurrentTaskHandle 1 | |
| #define INCLUDE_uxTaskGetStackHighWaterMark 1 | |
| #define INCLUDE_xTaskGetIdleTaskHandle 1 | |
| #define INCLUDE_eTaskGetState 1 | |
| #define INCLUDE_xEventGroupSetBitFromISR 1 | |
| #define INCLUDE_xTimerPendFunctionCall 1 | |
| #define INCLUDE_xTaskAbortDelay 1 | |
| #define INCLUDE_xTaskGetHandle 1 | |
| #define INCLUDE_xTaskResumeFromISR 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment