rp2: Flash writes disrupt UART IRQ
Port, board and/or hardware
rp2
MicroPython version
All.
Reproduction
Attempting to stream data from a UART to Flash - ie: servicing a soft (MicroPython) UART IRQ and writing the UART contents to a file on Flash - will result in lost data.
Using the same code and writing the same data to an SD card works fine.
Expected behaviour
No data should be lost.
Observed behaviour
Flash writes on RP2 disable all interrupts to avoid any code running from Flash while it's being written.
Since the UART copy from its 32 byte buffer into the user-specified (size) ring buffer requires the IRQ to fire, then writing to flash will lose arbitrary portions of incoming UART data since they will never make it to the ring buffer.
Additional Information
It's possible, maybe, that this could be fixed by moving the UART IRQ handler to RAM and being very careful about what it does. IE: This could not interop with a "hard" IRQ since we can't predict what the user might be doing (even if they don't allocate RAM).
AIUI the normal soft UART IRQ is dispatched and handled by MicroPython outside of the IRQ handler so this might just work.
Code of Conduct
Yes, I agree
stm32/uart_repl: Disable irq flash erase/write if uart repl enabled.
Uart repl stdin loses data when the background flash erase / cache flush happens during communication.
This change forces all erase / write operations to happen during file sync/close instead.
This change can be overridden by defining MICROPY_HW_FLASH_BACKGROUND_CACHE (1) in board config.
For more details see: mpremote cannot cp files to stm32wb55 nucleo on stlink/com port. #8386
I'm not sure if there are likely to be other unintended side-effects of disabling this flash irq however?