Skip to content

Commit

Permalink
Avoid hang in stdio_set_chars_available_callback
Browse files Browse the repository at this point in the history
The function is setting the callback after enabing interrupts which
can cause a hang if a receive character is already pending.
Smilarly we also have to clear the callback pointer only after the
interrupt is disabled.

Fixes raspberrypi#2009
  • Loading branch information
peterharperuk committed Nov 5, 2024
1 parent 5032223 commit 54674a4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/rp2_common/pico_stdio_uart/stdio_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,18 @@ static void on_uart_rx(void) {
static void stdio_uart_set_chars_available_callback(void (*fn)(void*), void *param) {
uint irq_num = UART_IRQ_NUM(uart_instance);
if (fn && !chars_available_callback) {
chars_available_callback = fn;
chars_available_param = param;
irq_set_exclusive_handler(irq_num, on_uart_rx);
irq_set_enabled(irq_num, true);
uart_set_irqs_enabled(uart_instance, true, false);
} else if (!fn && chars_available_callback) {
uart_set_irqs_enabled(uart_instance, false, false);
irq_set_enabled(irq_num, false);
irq_remove_handler(irq_num, on_uart_rx);
chars_available_callback = fn;
chars_available_param = param;
}
chars_available_callback = fn;
chars_available_param = param;
}
#endif

Expand Down

0 comments on commit 54674a4

Please sign in to comment.