70
70
#define UART_NUM (8)
71
71
#elif defined(STM32F2xx )
72
72
#define UART_NUM (6)
73
- #else // STM32F1xx || STM32F3xx || STM32L0xx || STM32L1xx || STM32L4xx
73
+ #elif defined(STM32F1xx ) || defined(STM32F3xx ) || \
74
+ defined(STM32L0xx ) || defined(STM32L1xx ) || defined(STM32L4xx )
74
75
#define UART_NUM (5)
76
+ #else
77
+ #error "Unknown Family - unknown UART_NUM"
75
78
#endif
79
+
76
80
static UART_HandleTypeDef * uart_handlers [UART_NUM ] = {NULL };
77
81
static void (* rx_callback [UART_NUM ])(serial_t * );
78
82
static serial_t * rx_callback_obj [UART_NUM ];
79
83
static int (* tx_callback [UART_NUM ])(serial_t * );
80
84
static serial_t * tx_callback_obj [UART_NUM ];
81
85
82
- static uint8_t rx_buffer [1 ] = {0 };
83
-
84
86
/**
85
87
* @brief Function called to initialize the uart interface
86
88
* @param obj : pointer to serial_t structure
@@ -457,7 +459,7 @@ uint8_t serial_tx_active(serial_t *obj)
457
459
* @param obj : pointer to serial_t structure
458
460
* @retval last character received
459
461
*/
460
- int uart_getc (serial_t * obj )
462
+ int uart_getc (serial_t * obj , unsigned char * c )
461
463
{
462
464
if (obj == NULL ) {
463
465
return -1 ;
@@ -467,11 +469,12 @@ int uart_getc(serial_t *obj)
467
469
return -1 ; // transaction ongoing
468
470
}
469
471
472
+ * c = (unsigned char )(obj -> recv );
470
473
// Restart RX irq
471
474
UART_HandleTypeDef * huart = uart_handlers [obj -> index ];
472
- HAL_UART_Receive_IT (huart , rx_buffer , 1 );
475
+ HAL_UART_Receive_IT (huart , & ( obj -> recv ) , 1 );
473
476
474
- return rx_buffer [ 0 ] ;
477
+ return 0 ;
475
478
}
476
479
477
480
/**
@@ -498,7 +501,7 @@ void uart_attach_rx_callback(serial_t *obj, void (*callback)(serial_t*))
498
501
HAL_NVIC_SetPriority (obj -> irq , 0 , 1 );
499
502
HAL_NVIC_EnableIRQ (obj -> irq );
500
503
501
- if (HAL_UART_Receive_IT (uart_handlers [obj -> index ], rx_buffer , 1 ) != HAL_OK ) {
504
+ if (HAL_UART_Receive_IT (uart_handlers [obj -> index ], & ( obj -> recv ) , 1 ) != HAL_OK ) {
502
505
return ;
503
506
}
504
507
}
0 commit comments