Skip to content

Commit ced073d

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 stm32duino#1789 Signed-off-by: Frederic Pillon <[email protected]>
1 parent c774ab8 commit ced073d

File tree

1 file changed

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

1 file changed

+15
-14
lines changed

libraries/SrcWrapper/src/stm32/uart.c

+15-14
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,10 @@ void uart_debug_init(void)
705705
*/
706706
size_t uart_debug_write(uint8_t *data, uint32_t size)
707707
{
708+
#ifdef CORE_DEBUG_TIMEOUT
708709
uint32_t tickstart = HAL_GetTick();
710+
#endif
711+
serial_t *obj = NULL;
709712

710713
if (serial_debug.index >= UART_NUM) {
711714
if (DEBUG_UART == NP) {
@@ -727,26 +730,24 @@ size_t uart_debug_write(uint8_t *data, uint32_t size)
727730
if (serial_debug.index >= UART_NUM) {
728731
return 0;
729732
}
730-
} else {
731-
serial_t *obj = get_serial_obj(uart_handlers[serial_debug.index]);
732-
if (obj) {
733-
serial_debug.irq = obj->irq;
734-
} else {
735-
return 0;
736-
}
737733
}
738734
}
735+
obj = get_serial_obj(uart_handlers[serial_debug.index]);
736+
if (!obj) {
737+
return 0;
738+
}
739739

740-
HAL_NVIC_DisableIRQ(serial_debug.irq);
741-
742-
while (HAL_UART_Transmit(uart_handlers[serial_debug.index], data, size, TX_TIMEOUT) != HAL_OK) {
743-
if ((HAL_GetTick() - tickstart) >= TX_TIMEOUT) {
744-
size = 0;
745-
break;
740+
while (serial_tx_active(obj)) {
741+
#ifdef CORE_DEBUG_TIMEOUT
742+
if ((HAL_GetTick() - tickstart) >= TX_TIMEOUT) {
743+
return 0;
746744
}
745+
#endif
747746
}
748747

749-
HAL_NVIC_EnableIRQ(serial_debug.irq);
748+
if (HAL_UART_Transmit(&(obj->handle), data, size, TX_TIMEOUT) != HAL_OK) {
749+
size = 0;
750+
}
750751

751752
return size;
752753
}

0 commit comments

Comments
 (0)