@@ -468,6 +468,11 @@ void uart_deinit(serial_t *obj)
468
468
}
469
469
470
470
HAL_UART_DeInit (uart_handlers [obj -> index ]);
471
+
472
+ /* Release uart debug to ensure init */
473
+ if (serial_debug .index == obj -> index ) {
474
+ serial_debug .index = UART_NUM ;
475
+ }
471
476
}
472
477
473
478
#if defined(HAL_PWR_MODULE_ENABLED ) && defined(UART_IT_WUF )
@@ -581,33 +586,31 @@ void uart_debug_init(void)
581
586
*/
582
587
size_t uart_debug_write (uint8_t * data , uint32_t size )
583
588
{
584
- uint8_t index = 0 ;
585
589
uint32_t tickstart = HAL_GetTick ();
586
590
587
591
if (DEBUG_UART == NP ) {
588
592
return 0 ;
589
593
}
590
- /* Search if DEBUG_UART already initialized */
591
- for (index = 0 ; index < UART_NUM ; index ++ ) {
592
- if (uart_handlers [index ] != NULL ) {
593
- if (DEBUG_UART == uart_handlers [index ]-> Instance ) {
594
- break ;
594
+ if (serial_debug .index >= UART_NUM ) {
595
+ /* Search if DEBUG_UART already initialized */
596
+ for (serial_debug .index = 0 ; serial_debug .index < UART_NUM ; serial_debug .index ++ ) {
597
+ if (uart_handlers [serial_debug .index ] != NULL ) {
598
+ if (DEBUG_UART == uart_handlers [serial_debug .index ]-> Instance ) {
599
+ break ;
600
+ }
595
601
}
596
602
}
597
- }
598
603
599
- if (index >= UART_NUM ) {
600
- /* DEBUG_UART not initialized */
601
604
if (serial_debug .index >= UART_NUM ) {
605
+ /* DEBUG_UART not initialized */
602
606
uart_debug_init ();
603
607
if (serial_debug .index >= UART_NUM ) {
604
608
return 0 ;
605
609
}
606
610
}
607
- index = serial_debug .index ;
608
611
}
609
612
610
- while (HAL_UART_Transmit (uart_handlers [index ], data , size , TX_TIMEOUT ) != HAL_OK ) {
613
+ while (HAL_UART_Transmit (uart_handlers [serial_debug . index ], data , size , TX_TIMEOUT ) != HAL_OK ) {
611
614
if ((HAL_GetTick () - tickstart ) >= TX_TIMEOUT ) {
612
615
return 0 ;
613
616
}
0 commit comments