Skip to content

Commit c125dd3

Browse files
committed
Fix flash_safe_execute timeout under FreeRTOS
In some cases, the flash lockout task can start on the wrong core and not have time to move to the correct core before exit is called. This causes a timeout as the exit function is looking at the wrong core when checking for the lockout task.
1 parent 5032223 commit c125dd3

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/rp2_common/pico_flash/flash.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,14 @@ static int default_enter_safe_zone_timeout_ms(__unused uint32_t timeout_ms) {
142142
// it only prevents the other core from also entering a critical section.
143143
// Therefore, we must do our own handshake which starts a task on the other core and have it disable interrupts
144144
uint core_num = get_core_num();
145-
// create at low priority
145+
// create at low priority on other core
146146
TaskHandle_t task_handle;
147-
if (pdPASS != xTaskCreate(flash_lockout_task, "flash lockout", configMINIMAL_STACK_SIZE, (void *)core_num, 0, &task_handle)) {
147+
if (pdPASS != xTaskCreateAffinitySet(flash_lockout_task, "flash lockout", configMINIMAL_STACK_SIZE, (void *)core_num, 0, 1u << (core_num ^ 1), &task_handle)) {
148148
return PICO_ERROR_INSUFFICIENT_RESOURCES;
149149
}
150150
lockout_state[core_num] = FREERTOS_LOCKOUT_LOCKER_WAITING;
151151
__sev();
152-
// bind to other core
153-
vTaskCoreAffinitySet(task_handle, 1u << (core_num ^ 1));
154-
// and make it super high priority
152+
// make it super high priority
155153
vTaskPrioritySet(task_handle, configMAX_PRIORITIES -1);
156154
absolute_time_t until = make_timeout_time_ms(timeout_ms);
157155
while (lockout_state[core_num] != FREERTOS_LOCKOUT_LOCKEE_READY && !time_reached(until)) {

0 commit comments

Comments
 (0)