Using the RP2040 USB UART, when printing a string from non-interrupt context, and an interrupt occurs, the string printed stops where the interrupt occurred and the rest is never printed - continues instead with later printf-s. I tried disabling interrupts and also using a delay and flush(stdout); but nothing seems to make the whole string printed.
The code I see the problem in is much longer and more complex but for now I don't want to try to find exactly what in it causes it. It should be equivalent to the code below, although I have not tested the code below and I am not sure if the problem happens in it to.
EDIT: Actually the cause may have been calling printf in interrupt-disabled state. Is there a way to make printf work normally in interrupt disabled state and in interrupts?
The code I see the problem in is much longer and more complex but for now I don't want to try to find exactly what in it causes it. It should be equivalent to the code below, although I have not tested the code below and I am not sure if the problem happens in it to.
Code:
int intrLoopTime = 1000*1000; //1sint64_t intrFunc(alarm_id_t alarmId, void *userData) {return intrLoopTime;}void mainLoop(void) {stdio_init_all();int alarmId = add_alarm_in_us(intrLoopTime, &intrFunc, NULL, true); while (1) {u32 intrStat = save_and_disable_interrupts();printf("testStringTestStringTestStringTestStringTestString\n ");fflush(stdout);stdio_flush();busy_wait_us(1000*100);restore_interrupts(intrStat);}}Statistics: Posted by wisi — Sat Jun 21, 2025 5:56 pm — Replies 0 — Views 45