Skip to content

Commit 444dd31

Browse files
committed
Disable uart interrupt in uart_debug_write
1 parent e11f862 commit 444dd31

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

cores/arduino/stm32/uart.c

+24-3
Original file line numberDiff line numberDiff line change
@@ -557,18 +557,26 @@ size_t uart_write(serial_t *obj, uint8_t data, uint16_t size)
557557
*/
558558
void uart_debug_init(void)
559559
{
560-
if (DEBUG_UART != NP) {
561-
serial_debug.pin_rx = pinmap_pin(DEBUG_UART, PinMap_UART_RX);
560+
void *periph = DEBUG_UART;
561+
if (periph != NP) {
562+
serial_debug.pin_rx = pinmap_pin(periph, PinMap_UART_RX);
562563
#if defined(DEBUG_PINNAME_TX)
563564
serial_debug.pin_tx = DEBUG_PINNAME_TX;
564565
#else
565-
serial_debug.pin_tx = pinmap_pin(DEBUG_UART, PinMap_UART_TX);
566+
serial_debug.pin_tx = pinmap_pin(periph, PinMap_UART_TX);
566567
#endif
567568
serial_debug.baudrate = DEBUG_UART_BAUDRATE;
568569
serial_debug.parity = UART_PARITY_NONE;
569570
serial_debug.databits = UART_WORDLENGTH_8B;
570571
serial_debug.stopbits = UART_STOPBITS_1;
571572

573+
if (periph == USART1)
574+
serial_debug.irq = USART1_IRQn;
575+
else if (periph == USART2)
576+
serial_debug.irq = USART2_IRQn;
577+
else if (periph == USART3)
578+
serial_debug.irq = USART3_IRQn;
579+
572580
uart_init(&serial_debug);
573581
}
574582
}
@@ -607,12 +615,25 @@ size_t uart_debug_write(uint8_t *data, uint32_t size)
607615
index = serial_debug.index;
608616
}
609617

618+
IRQn_Type irq;
619+
620+
if (DEBUG_UART == USART1)
621+
irq = USART1_IRQn;
622+
else if (DEBUG_UART == USART2)
623+
irq = USART2_IRQn;
624+
else if (DEBUG_UART == USART3)
625+
irq = USART3_IRQn;
626+
627+
HAL_NVIC_DisableIRQ(irq);
628+
610629
while (HAL_UART_Transmit(uart_handlers[index], data, size, TX_TIMEOUT) != HAL_OK) {
611630
if ((HAL_GetTick() - tickstart) >= TX_TIMEOUT) {
631+
HAL_NVIC_EnableIRQ(irq);
612632
return 0;
613633
}
614634
}
615635

636+
HAL_NVIC_EnableIRQ(irq);
616637
return size;
617638
}
618639

0 commit comments

Comments
 (0)