Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 44f340f

Browse files
authoredJun 8, 2017
Merge pull request #17 from stm32duino/issue_16
Removed conflict between printf & Serial.print
2 parents 2fa0645 + 3bf4496 commit 44f340f

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed
 

‎cores/arduino/stm32/uart.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
*/
9090
/// @brief uart caracteristics
9191
#define UART_NUM (8)
92-
static UART_HandleTypeDef *uart_handlers[UART_NUM];
92+
static UART_HandleTypeDef *uart_handlers[UART_NUM] = {NULL};
9393
static void (*rx_callback[UART_NUM])(serial_t*);
9494
static serial_t *rx_callback_obj[UART_NUM];
9595
static int (*tx_callback[UART_NUM])(serial_t*);
@@ -336,21 +336,27 @@ size_t uart_write(serial_t *obj, uint8_t data, uint16_t size)
336336
size_t uart_debug_write(uint8_t *data, uint32_t size)
337337
{
338338
uint8_t index = 0;
339+
uint32_t tickstart = HAL_GetTick();
340+
339341
for(index = 0; index < UART_NUM; index++) {
340-
if(DEBUG_UART == uart_handlers[index]->Instance) {
341-
break;
342+
if(uart_handlers[index] != NULL) {
343+
if(DEBUG_UART == uart_handlers[index]->Instance) {
344+
break;
345+
}
342346
}
343347
}
344348

345349
if(index >= UART_NUM) {
346350
return 0;
347351
}
348352

349-
if(HAL_UART_Transmit(uart_handlers[index], data, size, TX_TIMEOUT) == HAL_OK) {
350-
return 1;
351-
} else {
352-
return 0;
353+
while(HAL_UART_Transmit(uart_handlers[index], data, size, TX_TIMEOUT) != HAL_OK) {
354+
if((HAL_GetTick() - tickstart) >= TX_TIMEOUT) {
355+
return 0;
356+
}
353357
}
358+
359+
return size;
354360
}
355361

356362
/**

0 commit comments

Comments
 (0)
Please sign in to comment.