FreeRTOS SMP on RP2040 Caused Flash Erase and Write Fails

Hi, I am working on a project required to erase/write flash memory on Raspberry Pi Pico inside a FreeRTOS task. I know in order to erase/write flash I need to disable interrupt, I tried wrap around flash function with taskENTER_CRITICAL() and taskExit_CRITICAL() but no luck, still freeze when flash erase is call. I removed FreeRTOS and just run the flash code by itself, it works fine. Below is the snippet of the flash function I am using.

    uart_puts(UART_ID, "Erase\r");
    taskENTER_CRITICAL();
    //uint32_t ints = save_and_disable_interrupts();
    flash_range_erase(FLASH_TARGET_OFFSET, FLASH_SECTOR_SIZE);
   //restore_interrupts (ints);
    taskEXIT_CRITICAL();
    
    uart_puts(UART_ID, "Write\r");
    taskENTER_CRITICAL();
    //uint32_t ints1 = save_and_disable_interrupts();
    flash_range_program(FLASH_TARGET_OFFSET, (uint8_t *)err, FLASH_PAGE_SIZE);
    //restore_interrupts (ints1);
    taskEXIT_CRITICAL();

I am wondering if I didn’t disable the interrupt correctly or if there are something to do with FreeRTOS SMP version.

Thanks

With SMP “taskENTER_CRITICAL” only disables interrupt for the current processor, but not the other.

Thanks for the reply, is there a way to disable interrupt for both core? I don’t have anything running on second core yet. I thought about could be the issue with second core but I didn’t find any info on it.

I don’t know the SMP code well enough to say, but it is unlikely. If you don’t need the second core, maybe you should just be running in single processor mode on just one core.

Can you break the code in debugger and see what it is doing when it freezes?

Hello, I have the same problem.
Do you have any update about that ?

Can you break in the debugger and share what you find?