Skip to content

Commit ff019c1

Browse files
committed
fix(uart): ensure debug uart is ready before send
Like state is ready not need to loop on the blocking HAL_UART_Transmit(). If not ok it can be HAL_ERROR or HAL_TIMEOUT. Moreover, it avoid to disable the U(S)ART IRQ which prevent to receive data. Fixes #1789 Signed-off-by: Frederic Pillon <[email protected]>
1 parent d974fb2 commit ff019c1

File tree

1 file changed

+11
-14
lines changed
  • libraries/SrcWrapper/src/stm32

1 file changed

+11
-14
lines changed

Diff for: libraries/SrcWrapper/src/stm32/uart.c

+11-14
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ void uart_debug_init(void)
705705
size_t uart_debug_write(uint8_t *data, uint32_t size)
706706
{
707707
uint32_t tickstart = HAL_GetTick();
708+
serial_t *obj = NULL;
708709

709710
if (serial_debug.index >= UART_NUM) {
710711
if (DEBUG_UART == NP) {
@@ -726,26 +727,22 @@ size_t uart_debug_write(uint8_t *data, uint32_t size)
726727
if (serial_debug.index >= UART_NUM) {
727728
return 0;
728729
}
729-
} else {
730-
serial_t *obj = get_serial_obj(uart_handlers[serial_debug.index]);
731-
if (obj) {
732-
serial_debug.irq = obj->irq;
733-
} else {
734-
return 0;
735-
}
736730
}
737731
}
732+
obj = get_serial_obj(uart_handlers[serial_debug.index]);
733+
if (!obj) {
734+
return 0;
735+
}
738736

739-
HAL_NVIC_DisableIRQ(serial_debug.irq);
740-
741-
while (HAL_UART_Transmit(uart_handlers[serial_debug.index], data, size, TX_TIMEOUT) != HAL_OK) {
742-
if ((HAL_GetTick() - tickstart) >= TX_TIMEOUT) {
743-
size = 0;
744-
break;
737+
while (serial_tx_active(obj)) {
738+
if ((HAL_GetTick() - tickstart) >= TX_TIMEOUT) {
739+
return 0;
745740
}
746741
}
747742

748-
HAL_NVIC_EnableIRQ(serial_debug.irq);
743+
if (HAL_UART_Transmit(&(obj->handle), data, size, TX_TIMEOUT) != HAL_OK) {
744+
size = 0;
745+
}
749746

750747
return size;
751748
}

0 commit comments

Comments
 (0)