← index #17236PR #8645
Related · high · value 0.090
QUERY · ISSUE

rp2: Flash writes disrupt UART IRQ

openby Gadgetoidopened 2025-05-01updated 2026-03-12
bugport-rp2

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

CANDIDATE · PULL REQUEST

stm32/uart_repl: Disable irq flash erase/write if uart repl enabled.

closedby andrewleechopened 2022-05-09updated 2022-08-08
port-stm32

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?

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied