mirror of https://github.com/ARMmbed/mbed-os.git
commit
f907012e55
|
@ -47,12 +47,18 @@ UART_HandleTypeDef uart_handlers[UART_NUM];
|
||||||
|
|
||||||
static uart_irq_handler irq_handler;
|
static uart_irq_handler irq_handler;
|
||||||
|
|
||||||
|
// Defined in serial_api.c
|
||||||
|
inline int8_t get_uart_index(UARTName uart_name);
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* INTERRUPTS HANDLING
|
* INTERRUPTS HANDLING
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
static void uart_irq(int id)
|
static void uart_irq(UARTName uart_name)
|
||||||
{
|
{
|
||||||
|
int8_t id = get_uart_index(uart_name);
|
||||||
|
|
||||||
|
if (id >= 0) {
|
||||||
UART_HandleTypeDef * huart = &uart_handlers[id];
|
UART_HandleTypeDef * huart = &uart_handlers[id];
|
||||||
if (serial_irq_ids[id] != 0) {
|
if (serial_irq_ids[id] != 0) {
|
||||||
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
|
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
|
||||||
|
@ -72,17 +78,20 @@ static void uart_irq(int id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(USART1_BASE)
|
||||||
static void uart1_irq(void)
|
static void uart1_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(0);
|
uart_irq(UART_1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(USART2_BASE)
|
#if defined(USART2_BASE)
|
||||||
static void uart2_irq(void)
|
static void uart2_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(1);
|
uart_irq(UART_2);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -92,43 +101,43 @@ static void uart3_8_irq(void)
|
||||||
#if defined(TARGET_STM32F091RC)
|
#if defined(TARGET_STM32F091RC)
|
||||||
#if defined(USART3_BASE)
|
#if defined(USART3_BASE)
|
||||||
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART3) != RESET) {
|
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART3) != RESET) {
|
||||||
uart_irq(2);
|
uart_irq(UART_3);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(USART4_BASE)
|
#if defined(USART4_BASE)
|
||||||
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART4) != RESET) {
|
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART4) != RESET) {
|
||||||
uart_irq(3);
|
uart_irq(UART_4);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(USART5_BASE)
|
#if defined(USART5_BASE)
|
||||||
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART5) != RESET) {
|
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART5) != RESET) {
|
||||||
uart_irq(4);
|
uart_irq(UART_5);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(USART6_BASE)
|
#if defined(USART6_BASE)
|
||||||
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART6) != RESET) {
|
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART6) != RESET) {
|
||||||
uart_irq(5);
|
uart_irq(UART_6);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(USART7_BASE)
|
#if defined(USART7_BASE)
|
||||||
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART7) != RESET) {
|
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART7) != RESET) {
|
||||||
uart_irq(6);
|
uart_irq(UART_7);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(USART8_BASE)
|
#if defined(USART8_BASE)
|
||||||
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART8) != RESET) {
|
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART8) != RESET) {
|
||||||
uart_irq(7);
|
uart_irq(UART_8);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#else // TARGET_STM32F070RB, TARGET_STM32F072RB
|
#else // TARGET_STM32F070RB, TARGET_STM32F072RB
|
||||||
#if defined(USART3_BASE)
|
#if defined(USART3_BASE)
|
||||||
if (USART3->ISR & (UART_FLAG_TXE | UART_FLAG_RXNE | UART_FLAG_ORE)) {
|
if (USART3->ISR & (UART_FLAG_TXE | UART_FLAG_RXNE | UART_FLAG_ORE)) {
|
||||||
uart_irq(2);
|
uart_irq(UART_3);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(USART4_BASE)
|
#if defined(USART4_BASE)
|
||||||
if (USART4->ISR & (UART_FLAG_TXE | UART_FLAG_RXNE | UART_FLAG_ORE)) {
|
if (USART4->ISR & (UART_FLAG_TXE | UART_FLAG_RXNE | UART_FLAG_ORE)) {
|
||||||
uart_irq(3);
|
uart_irq(UART_4);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -149,10 +158,12 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
|
||||||
IRQn_Type irq_n = (IRQn_Type)0;
|
IRQn_Type irq_n = (IRQn_Type)0;
|
||||||
uint32_t vector = 0;
|
uint32_t vector = 0;
|
||||||
|
|
||||||
|
#if defined(USART1_BASE)
|
||||||
if (obj_s->uart == UART_1) {
|
if (obj_s->uart == UART_1) {
|
||||||
irq_n = USART1_IRQn;
|
irq_n = USART1_IRQn;
|
||||||
vector = (uint32_t)&uart1_irq;
|
vector = (uint32_t)&uart1_irq;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(USART2_BASE)
|
#if defined(USART2_BASE)
|
||||||
if (obj_s->uart == UART_2) {
|
if (obj_s->uart == UART_2) {
|
||||||
|
@ -351,40 +362,71 @@ static void serial_enable_event(serial_t *obj, int event, uint8_t enable)
|
||||||
/**
|
/**
|
||||||
* Get index of serial object TX IRQ, relating it to the physical peripheral.
|
* Get index of serial object TX IRQ, relating it to the physical peripheral.
|
||||||
*
|
*
|
||||||
* @param obj pointer to serial object
|
* @param uart_name i.e. UART_1, UART_2, ...
|
||||||
* @return internal NVIC TX IRQ index of U(S)ART peripheral
|
* @return internal NVIC TX IRQ index of U(S)ART peripheral
|
||||||
*/
|
*/
|
||||||
static IRQn_Type serial_get_irq_n(serial_t *obj)
|
static IRQn_Type serial_get_irq_n(UARTName uart_name)
|
||||||
{
|
{
|
||||||
struct serial_s *obj_s = SERIAL_S(obj);
|
|
||||||
IRQn_Type irq_n;
|
IRQn_Type irq_n;
|
||||||
|
|
||||||
switch (obj_s->index) {
|
switch (uart_name) {
|
||||||
|
|
||||||
#if defined(USART1_BASE)
|
#if defined(USART1_BASE)
|
||||||
case 0:
|
case UART_1:
|
||||||
irq_n = USART1_IRQn;
|
irq_n = USART1_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USART2_BASE)
|
#if defined(USART2_BASE)
|
||||||
case 1:
|
case UART_2:
|
||||||
irq_n = USART2_IRQn;
|
irq_n = USART2_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART3_BASE)
|
||||||
|
case UART_3:
|
||||||
#if defined (TARGET_STM32F091RC)
|
#if defined (TARGET_STM32F091RC)
|
||||||
case 2:
|
|
||||||
case 3:
|
|
||||||
case 4:
|
|
||||||
case 5:
|
|
||||||
case 6:
|
|
||||||
case 7:
|
|
||||||
irq_n = USART3_8_IRQn;
|
irq_n = USART3_8_IRQn;
|
||||||
break;
|
#else
|
||||||
#elif !defined (TARGET_STM32F030R8) && !defined (TARGET_STM32F051R8)
|
|
||||||
case 2:
|
|
||||||
case 3:
|
|
||||||
irq_n = USART3_4_IRQn;
|
irq_n = USART3_4_IRQn;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART4_BASE)
|
||||||
|
case UART_4:
|
||||||
|
#if defined (TARGET_STM32F091RC)
|
||||||
|
irq_n = USART3_8_IRQn;
|
||||||
|
#else
|
||||||
|
irq_n = USART3_4_IRQn;
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART5_BASE)
|
||||||
|
case UART_5:
|
||||||
|
irq_n = USART3_8_IRQn;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART6_BASE)
|
||||||
|
case UART_6:
|
||||||
|
irq_n = USART3_8_IRQn;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART7_BASE)
|
||||||
|
case UART_7:
|
||||||
|
irq_n = USART3_8_IRQn;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART8_BASE)
|
||||||
|
case UART_8:
|
||||||
|
irq_n = USART3_8_IRQn;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
irq_n = (IRQn_Type)0;
|
irq_n = (IRQn_Type)0;
|
||||||
}
|
}
|
||||||
|
@ -434,7 +476,7 @@ int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx
|
||||||
serial_enable_event(obj, event, 1); // Set only the wanted events
|
serial_enable_event(obj, event, 1); // Set only the wanted events
|
||||||
|
|
||||||
// Enable interrupt
|
// Enable interrupt
|
||||||
IRQn_Type irq_n = serial_get_irq_n(obj);
|
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
|
||||||
NVIC_ClearPendingIRQ(irq_n);
|
NVIC_ClearPendingIRQ(irq_n);
|
||||||
NVIC_DisableIRQ(irq_n);
|
NVIC_DisableIRQ(irq_n);
|
||||||
NVIC_SetPriority(irq_n, 1);
|
NVIC_SetPriority(irq_n, 1);
|
||||||
|
@ -484,7 +526,7 @@ void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_widt
|
||||||
|
|
||||||
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
|
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
|
||||||
|
|
||||||
IRQn_Type irq_n = serial_get_irq_n(obj);
|
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
|
||||||
NVIC_ClearPendingIRQ(irq_n);
|
NVIC_ClearPendingIRQ(irq_n);
|
||||||
NVIC_DisableIRQ(irq_n);
|
NVIC_DisableIRQ(irq_n);
|
||||||
NVIC_SetPriority(irq_n, 0);
|
NVIC_SetPriority(irq_n, 0);
|
||||||
|
|
|
@ -39,14 +39,19 @@ UART_HandleTypeDef uart_handlers[UART_NUM];
|
||||||
|
|
||||||
static uart_irq_handler irq_handler;
|
static uart_irq_handler irq_handler;
|
||||||
|
|
||||||
|
// Defined in serial_api.c
|
||||||
|
inline int8_t get_uart_index(UARTName uart_name);
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* INTERRUPTS HANDLING
|
* INTERRUPTS HANDLING
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
static void uart_irq(int id)
|
static void uart_irq(UARTName uart_name)
|
||||||
{
|
{
|
||||||
UART_HandleTypeDef * huart = &uart_handlers[id];
|
int8_t id = get_uart_index(uart_name);
|
||||||
|
|
||||||
|
if (id >= 0) {
|
||||||
|
UART_HandleTypeDef * huart = &uart_handlers[id];
|
||||||
if (serial_irq_ids[id] != 0) {
|
if (serial_irq_ids[id] != 0) {
|
||||||
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
|
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
|
||||||
if (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE) != RESET) {
|
if (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE) != RESET) {
|
||||||
|
@ -65,22 +70,29 @@ static void uart_irq(int id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(USART1_BASE)
|
||||||
static void uart1_irq(void)
|
static void uart1_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(0);
|
uart_irq(UART_1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART2_BASE)
|
||||||
static void uart2_irq(void)
|
static void uart2_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(1);
|
uart_irq(UART_2);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART3_BASE)
|
||||||
static void uart3_irq(void)
|
static void uart3_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(2);
|
uart_irq(UART_3);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
|
void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
|
||||||
{
|
{
|
||||||
|
@ -97,20 +109,26 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
|
||||||
IRQn_Type irq_n = (IRQn_Type)0;
|
IRQn_Type irq_n = (IRQn_Type)0;
|
||||||
uint32_t vector = 0;
|
uint32_t vector = 0;
|
||||||
|
|
||||||
|
#if defined(USART1_BASE)
|
||||||
if (obj_s->uart == UART_1) {
|
if (obj_s->uart == UART_1) {
|
||||||
irq_n = USART1_IRQn;
|
irq_n = USART1_IRQn;
|
||||||
vector = (uint32_t)&uart1_irq;
|
vector = (uint32_t)&uart1_irq;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART2_BASE)
|
||||||
if (obj_s->uart == UART_2) {
|
if (obj_s->uart == UART_2) {
|
||||||
irq_n = USART2_IRQn;
|
irq_n = USART2_IRQn;
|
||||||
vector = (uint32_t)&uart2_irq;
|
vector = (uint32_t)&uart2_irq;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART3_BASE)
|
||||||
if (obj_s->uart == UART_3) {
|
if (obj_s->uart == UART_3) {
|
||||||
irq_n = USART3_IRQn;
|
irq_n = USART3_IRQn;
|
||||||
vector = (uint32_t)&uart3_irq;
|
vector = (uint32_t)&uart3_irq;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
if (irq == RxIrq) {
|
if (irq == RxIrq) {
|
||||||
|
@ -261,27 +279,29 @@ static void serial_enable_event(serial_t *obj, int event, uint8_t enable)
|
||||||
/**
|
/**
|
||||||
* Get index of serial object TX IRQ, relating it to the physical peripheral.
|
* Get index of serial object TX IRQ, relating it to the physical peripheral.
|
||||||
*
|
*
|
||||||
* @param obj pointer to serial object
|
* @param uart_name i.e. UART_1, UART_2, ...
|
||||||
* @return internal NVIC TX IRQ index of U(S)ART peripheral
|
* @return internal NVIC TX IRQ index of U(S)ART peripheral
|
||||||
*/
|
*/
|
||||||
static IRQn_Type serial_get_irq_n(serial_t *obj)
|
static IRQn_Type serial_get_irq_n(UARTName uart_name)
|
||||||
{
|
{
|
||||||
struct serial_s *obj_s = SERIAL_S(obj);
|
|
||||||
IRQn_Type irq_n;
|
IRQn_Type irq_n;
|
||||||
|
|
||||||
switch (obj_s->index) {
|
switch (uart_name) {
|
||||||
case 0:
|
#if defined(USART1_BASE)
|
||||||
|
case UART_1:
|
||||||
irq_n = USART1_IRQn;
|
irq_n = USART1_IRQn;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case 1:
|
#if defined(USART2_BASE)
|
||||||
|
case UART_2:
|
||||||
irq_n = USART2_IRQn;
|
irq_n = USART2_IRQn;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case 2:
|
#if defined(USART3_BASE)
|
||||||
|
case UART_3:
|
||||||
irq_n = USART3_IRQn;
|
irq_n = USART3_IRQn;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
irq_n = (IRQn_Type)0;
|
irq_n = (IRQn_Type)0;
|
||||||
}
|
}
|
||||||
|
@ -330,7 +350,7 @@ int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx
|
||||||
serial_enable_event(obj, event, 1); // Set only the wanted events
|
serial_enable_event(obj, event, 1); // Set only the wanted events
|
||||||
|
|
||||||
// Enable interrupt
|
// Enable interrupt
|
||||||
IRQn_Type irq_n = serial_get_irq_n(obj);
|
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
|
||||||
NVIC_ClearPendingIRQ(irq_n);
|
NVIC_ClearPendingIRQ(irq_n);
|
||||||
NVIC_DisableIRQ(irq_n);
|
NVIC_DisableIRQ(irq_n);
|
||||||
NVIC_SetPriority(irq_n, 1);
|
NVIC_SetPriority(irq_n, 1);
|
||||||
|
@ -380,7 +400,7 @@ void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_widt
|
||||||
|
|
||||||
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
|
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
|
||||||
|
|
||||||
IRQn_Type irq_n = serial_get_irq_n(obj);
|
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
|
||||||
NVIC_ClearPendingIRQ(irq_n);
|
NVIC_ClearPendingIRQ(irq_n);
|
||||||
NVIC_DisableIRQ(irq_n);
|
NVIC_DisableIRQ(irq_n);
|
||||||
NVIC_SetPriority(irq_n, 0);
|
NVIC_SetPriority(irq_n, 0);
|
||||||
|
@ -471,7 +491,7 @@ int serial_irq_handler_asynch(serial_t *obj)
|
||||||
if (__HAL_UART_GET_IT_SOURCE(huart, USART_IT_ERR) != RESET) {
|
if (__HAL_UART_GET_IT_SOURCE(huart, USART_IT_ERR) != RESET) {
|
||||||
return_event |= (SERIAL_EVENT_RX_PARITY_ERROR & obj_s->events);
|
return_event |= (SERIAL_EVENT_RX_PARITY_ERROR & obj_s->events);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_FE) != RESET) {
|
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_FE) != RESET) {
|
||||||
if (__HAL_UART_GET_IT_SOURCE(huart, USART_IT_ERR) != RESET) {
|
if (__HAL_UART_GET_IT_SOURCE(huart, USART_IT_ERR) != RESET) {
|
||||||
|
|
|
@ -39,14 +39,19 @@ UART_HandleTypeDef uart_handlers[UART_NUM];
|
||||||
|
|
||||||
static uart_irq_handler irq_handler;
|
static uart_irq_handler irq_handler;
|
||||||
|
|
||||||
|
// Defined in serial_api.c
|
||||||
|
inline int8_t get_uart_index(UARTName uart_name);
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* INTERRUPTS HANDLING
|
* INTERRUPTS HANDLING
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
static void uart_irq(int id)
|
static void uart_irq(UARTName uart_name)
|
||||||
{
|
{
|
||||||
UART_HandleTypeDef * huart = &uart_handlers[id];
|
int8_t id = get_uart_index(uart_name);
|
||||||
|
|
||||||
|
if (id >= 0) {
|
||||||
|
UART_HandleTypeDef * huart = &uart_handlers[id];
|
||||||
if (serial_irq_ids[id] != 0) {
|
if (serial_irq_ids[id] != 0) {
|
||||||
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
|
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
|
||||||
if (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE) != RESET) {
|
if (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE) != RESET) {
|
||||||
|
@ -65,57 +70,62 @@ static void uart_irq(int id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(USART1_BASE)
|
||||||
static void uart1_irq(void)
|
static void uart1_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(0);
|
uart_irq(UART_1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART2_BASE)
|
||||||
static void uart2_irq(void)
|
static void uart2_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(1);
|
uart_irq(UART_2);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(USART3_BASE)
|
#if defined(USART3_BASE)
|
||||||
static void uart3_irq(void)
|
static void uart3_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(2);
|
uart_irq(UART_3);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART4_BASE)
|
#if defined(UART4_BASE)
|
||||||
static void uart4_irq(void)
|
static void uart4_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(3);
|
uart_irq(UART_4);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART5_BASE)
|
#if defined(UART5_BASE)
|
||||||
static void uart5_irq(void)
|
static void uart5_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(4);
|
uart_irq(UART_5);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USART6_BASE)
|
#if defined(USART6_BASE)
|
||||||
static void uart6_irq(void)
|
static void uart6_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(5);
|
uart_irq(UART_6);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART7_BASE)
|
#if defined(UART7_BASE)
|
||||||
static void uart7_irq(void)
|
static void uart7_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(6);
|
uart_irq(UART_7);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART8_BASE)
|
#if defined(UART8_BASE)
|
||||||
static void uart8_irq(void)
|
static void uart8_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(7);
|
uart_irq(UART8);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -134,48 +144,51 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
|
||||||
IRQn_Type irq_n = (IRQn_Type)0;
|
IRQn_Type irq_n = (IRQn_Type)0;
|
||||||
uint32_t vector = 0;
|
uint32_t vector = 0;
|
||||||
|
|
||||||
switch (obj_s->index) {
|
switch (obj_s->uart) {
|
||||||
case 0:
|
#if defined(USART1_BASE)
|
||||||
|
case UART_1:
|
||||||
irq_n = USART1_IRQn;
|
irq_n = USART1_IRQn;
|
||||||
vector = (uint32_t)&uart1_irq;
|
vector = (uint32_t)&uart1_irq;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case 1:
|
#if defined(USART2_BASE)
|
||||||
|
case UART_2:
|
||||||
irq_n = USART2_IRQn;
|
irq_n = USART2_IRQn;
|
||||||
vector = (uint32_t)&uart2_irq;
|
vector = (uint32_t)&uart2_irq;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
#if defined(USART3_BASE)
|
#if defined(USART3_BASE)
|
||||||
case 2:
|
case UART_3:
|
||||||
irq_n = USART3_IRQn;
|
irq_n = USART3_IRQn;
|
||||||
vector = (uint32_t)&uart3_irq;
|
vector = (uint32_t)&uart3_irq;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART4_BASE)
|
#if defined(UART4_BASE)
|
||||||
case 3:
|
case UART_4:
|
||||||
irq_n = UART4_IRQn;
|
irq_n = UART4_IRQn;
|
||||||
vector = (uint32_t)&uart4_irq;
|
vector = (uint32_t)&uart4_irq;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART5_BASE)
|
#if defined(UART5_BASE)
|
||||||
case 4:
|
case UART_5:
|
||||||
irq_n = UART5_IRQn;
|
irq_n = UART5_IRQn;
|
||||||
vector = (uint32_t)&uart5_irq;
|
vector = (uint32_t)&uart5_irq;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(USART6_BASE)
|
#if defined(USART6_BASE)
|
||||||
case 5:
|
case UART_6:
|
||||||
irq_n = USART6_IRQn;
|
irq_n = USART6_IRQn;
|
||||||
vector = (uint32_t)&uart6_irq;
|
vector = (uint32_t)&uart6_irq;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART7_BASE)
|
#if defined(UART7_BASE)
|
||||||
case 6:
|
case UART_7:
|
||||||
irq_n = UART7_IRQn;
|
irq_n = UART7_IRQn;
|
||||||
vector = (uint32_t)&uart7_irq;
|
vector = (uint32_t)&uart7_irq;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART8_BASE)
|
#if defined(UART8_BASE)
|
||||||
case 7:
|
case UART_8:
|
||||||
irq_n = UART8_IRQn;
|
irq_n = UART8_IRQn;
|
||||||
vector = (uint32_t)&uart8_irq;
|
vector = (uint32_t)&uart8_irq;
|
||||||
break;
|
break;
|
||||||
|
@ -323,52 +336,51 @@ static void serial_enable_event(serial_t *obj, int event, uint8_t enable)
|
||||||
/**
|
/**
|
||||||
* Get index of serial object TX IRQ, relating it to the physical peripheral.
|
* Get index of serial object TX IRQ, relating it to the physical peripheral.
|
||||||
*
|
*
|
||||||
* @param obj pointer to serial object
|
* @param uart_name i.e. UART_1, UART_2, ...
|
||||||
* @return internal NVIC TX IRQ index of U(S)ART peripheral
|
* @return internal NVIC TX IRQ index of U(S)ART peripheral
|
||||||
*/
|
*/
|
||||||
static IRQn_Type serial_get_irq_n(serial_t *obj)
|
static IRQn_Type serial_get_irq_n(UARTName uart_name)
|
||||||
{
|
{
|
||||||
struct serial_s *obj_s = SERIAL_S(obj);
|
|
||||||
IRQn_Type irq_n;
|
IRQn_Type irq_n;
|
||||||
|
|
||||||
switch (obj_s->index) {
|
switch (uart_name) {
|
||||||
#if defined(USART1_BASE)
|
#if defined(USART1_BASE)
|
||||||
case 0:
|
case UART_1:
|
||||||
irq_n = USART1_IRQn;
|
irq_n = USART1_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(USART2_BASE)
|
#if defined(USART2_BASE)
|
||||||
case 1:
|
case UART_2:
|
||||||
irq_n = USART2_IRQn;
|
irq_n = USART2_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(USART3_BASE)
|
#if defined(USART3_BASE)
|
||||||
case 2:
|
case UART_3:
|
||||||
irq_n = USART3_IRQn;
|
irq_n = USART3_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART4_BASE)
|
#if defined(UART4_BASE)
|
||||||
case 3:
|
case UART_4:
|
||||||
irq_n = UART4_IRQn;
|
irq_n = UART4_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART5_BASE)
|
#if defined(UART5_BASE)
|
||||||
case 4:
|
case UART_5:
|
||||||
irq_n = UART5_IRQn;
|
irq_n = UART5_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(USART6_BASE)
|
#if defined(USART6_BASE)
|
||||||
case 5:
|
case UART_6:
|
||||||
irq_n = USART6_IRQn;
|
irq_n = USART6_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART7_BASE)
|
#if defined(UART7_BASE)
|
||||||
case 6:
|
case UART_7:
|
||||||
irq_n = UART7_IRQn;
|
irq_n = UART7_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART8_BASE)
|
#if defined(UART8_BASE)
|
||||||
case 7:
|
case UART_8:
|
||||||
irq_n = UART8_IRQn;
|
irq_n = UART8_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
@ -421,7 +433,7 @@ int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx
|
||||||
serial_enable_event(obj, event, 1); // Set only the wanted events
|
serial_enable_event(obj, event, 1); // Set only the wanted events
|
||||||
|
|
||||||
// Enable interrupt
|
// Enable interrupt
|
||||||
IRQn_Type irq_n = serial_get_irq_n(obj);
|
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
|
||||||
NVIC_ClearPendingIRQ(irq_n);
|
NVIC_ClearPendingIRQ(irq_n);
|
||||||
NVIC_DisableIRQ(irq_n);
|
NVIC_DisableIRQ(irq_n);
|
||||||
NVIC_SetPriority(irq_n, 1);
|
NVIC_SetPriority(irq_n, 1);
|
||||||
|
@ -471,7 +483,7 @@ void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_widt
|
||||||
|
|
||||||
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
|
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
|
||||||
|
|
||||||
IRQn_Type irq_n = serial_get_irq_n(obj);
|
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
|
||||||
NVIC_ClearPendingIRQ(irq_n);
|
NVIC_ClearPendingIRQ(irq_n);
|
||||||
NVIC_DisableIRQ(irq_n);
|
NVIC_DisableIRQ(irq_n);
|
||||||
NVIC_SetPriority(irq_n, 0);
|
NVIC_SetPriority(irq_n, 0);
|
||||||
|
|
|
@ -43,14 +43,19 @@ UART_HandleTypeDef uart_handlers[UART_NUM];
|
||||||
|
|
||||||
static uart_irq_handler irq_handler;
|
static uart_irq_handler irq_handler;
|
||||||
|
|
||||||
|
// Defined in serial_api.c
|
||||||
|
inline int8_t get_uart_index(UARTName uart_name);
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* INTERRUPTS HANDLING
|
* INTERRUPTS HANDLING
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
static void uart_irq(int id)
|
static void uart_irq(UARTName uart_name)
|
||||||
{
|
{
|
||||||
UART_HandleTypeDef * huart = &uart_handlers[id];
|
int8_t id = get_uart_index(uart_name);
|
||||||
|
|
||||||
|
if (id >= 0) {
|
||||||
|
UART_HandleTypeDef * huart = &uart_handlers[id];
|
||||||
if (serial_irq_ids[id] != 0) {
|
if (serial_irq_ids[id] != 0) {
|
||||||
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
|
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
|
||||||
if (__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET) {
|
if (__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET) {
|
||||||
|
@ -69,36 +74,41 @@ static void uart_irq(int id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(USART1_BASE)
|
||||||
static void uart1_irq(void)
|
static void uart1_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(0);
|
uart_irq(UART_1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART2_BASE)
|
||||||
static void uart2_irq(void)
|
static void uart2_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(1);
|
uart_irq(UART_2);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(USART3_BASE)
|
#if defined(USART3_BASE)
|
||||||
static void uart3_irq(void)
|
static void uart3_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(2);
|
uart_irq(UART_3);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART4_BASE)
|
#if defined(UART4_BASE)
|
||||||
static void uart4_irq(void)
|
static void uart4_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(3);
|
uart_irq(UART_4);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART5_BASE)
|
#if defined(UART5_BASE)
|
||||||
static void uart5_irq(void)
|
static void uart5_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(4);
|
uart_irq(UART_5);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -117,15 +127,19 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
|
||||||
IRQn_Type irq_n = (IRQn_Type)0;
|
IRQn_Type irq_n = (IRQn_Type)0;
|
||||||
uint32_t vector = 0;
|
uint32_t vector = 0;
|
||||||
|
|
||||||
|
#if defined(USART1_BASE)
|
||||||
if (obj_s->uart == UART_1) {
|
if (obj_s->uart == UART_1) {
|
||||||
irq_n = USART1_IRQn;
|
irq_n = USART1_IRQn;
|
||||||
vector = (uint32_t)&uart1_irq;
|
vector = (uint32_t)&uart1_irq;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART2_BASE)
|
||||||
if (obj_s->uart == UART_2) {
|
if (obj_s->uart == UART_2) {
|
||||||
irq_n = USART2_IRQn;
|
irq_n = USART2_IRQn;
|
||||||
vector = (uint32_t)&uart2_irq;
|
vector = (uint32_t)&uart2_irq;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(USART3_BASE)
|
#if defined(USART3_BASE)
|
||||||
if (obj_s->uart == UART_3) {
|
if (obj_s->uart == UART_3) {
|
||||||
|
@ -297,35 +311,36 @@ static void serial_enable_event(serial_t *obj, int event, uint8_t enable)
|
||||||
/**
|
/**
|
||||||
* Get index of serial object TX IRQ, relating it to the physical peripheral.
|
* Get index of serial object TX IRQ, relating it to the physical peripheral.
|
||||||
*
|
*
|
||||||
* @param obj pointer to serial object
|
* @param uart_name i.e. UART_1, UART_2, ...
|
||||||
* @return internal NVIC TX IRQ index of U(S)ART peripheral
|
* @return internal NVIC TX IRQ index of U(S)ART peripheral
|
||||||
*/
|
*/
|
||||||
static IRQn_Type serial_get_irq_n(serial_t *obj)
|
static IRQn_Type serial_get_irq_n(UARTName uart_name)
|
||||||
{
|
{
|
||||||
struct serial_s *obj_s = SERIAL_S(obj);
|
|
||||||
IRQn_Type irq_n;
|
IRQn_Type irq_n;
|
||||||
|
|
||||||
switch (obj_s->index) {
|
switch (uart_name) {
|
||||||
case 0:
|
#if defined(USART1_BASE)
|
||||||
|
case UART_1:
|
||||||
irq_n = USART1_IRQn;
|
irq_n = USART1_IRQn;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case 1:
|
#if defined(USART2_BASE)
|
||||||
|
case UART_2:
|
||||||
irq_n = USART2_IRQn;
|
irq_n = USART2_IRQn;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
#if defined(USART3_BASE)
|
#if defined(USART3_BASE)
|
||||||
case 2:
|
case UART_3:
|
||||||
irq_n = USART3_IRQn;
|
irq_n = USART3_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART4_BASE)
|
#if defined(UART4_BASE)
|
||||||
case 3:
|
case UART_4:
|
||||||
irq_n = UART4_IRQn;
|
irq_n = UART4_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART5_BASE)
|
#if defined(UART5_BASE)
|
||||||
case 4:
|
case UART_5:
|
||||||
irq_n = UART5_IRQn;
|
irq_n = UART5_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
@ -378,7 +393,7 @@ int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx
|
||||||
serial_enable_event(obj, event, 1); // Set only the wanted events
|
serial_enable_event(obj, event, 1); // Set only the wanted events
|
||||||
|
|
||||||
// Enable interrupt
|
// Enable interrupt
|
||||||
IRQn_Type irq_n = serial_get_irq_n(obj);
|
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
|
||||||
NVIC_ClearPendingIRQ(irq_n);
|
NVIC_ClearPendingIRQ(irq_n);
|
||||||
NVIC_DisableIRQ(irq_n);
|
NVIC_DisableIRQ(irq_n);
|
||||||
NVIC_SetPriority(irq_n, 1);
|
NVIC_SetPriority(irq_n, 1);
|
||||||
|
@ -428,7 +443,7 @@ void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_widt
|
||||||
|
|
||||||
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
|
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
|
||||||
|
|
||||||
IRQn_Type irq_n = serial_get_irq_n(obj);
|
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
|
||||||
NVIC_ClearPendingIRQ(irq_n);
|
NVIC_ClearPendingIRQ(irq_n);
|
||||||
NVIC_DisableIRQ(irq_n);
|
NVIC_DisableIRQ(irq_n);
|
||||||
NVIC_SetPriority(irq_n, 0);
|
NVIC_SetPriority(irq_n, 0);
|
||||||
|
|
|
@ -49,14 +49,19 @@ UART_HandleTypeDef uart_handlers[UART_NUM];
|
||||||
|
|
||||||
static uart_irq_handler irq_handler;
|
static uart_irq_handler irq_handler;
|
||||||
|
|
||||||
|
// Defined in serial_api.c
|
||||||
|
inline int8_t get_uart_index(UARTName uart_name);
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* INTERRUPTS HANDLING
|
* INTERRUPTS HANDLING
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
static void uart_irq(int id)
|
static void uart_irq(UARTName uart_name)
|
||||||
{
|
{
|
||||||
UART_HandleTypeDef * huart = &uart_handlers[id];
|
int8_t id = get_uart_index(uart_name);
|
||||||
|
|
||||||
|
if (id >= 0) {
|
||||||
|
UART_HandleTypeDef * huart = &uart_handlers[id];
|
||||||
if (serial_irq_ids[id] != 0) {
|
if (serial_irq_ids[id] != 0) {
|
||||||
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
|
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
|
||||||
if (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE) != RESET) {
|
if (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE) != RESET) {
|
||||||
|
@ -75,71 +80,76 @@ static void uart_irq(int id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(USART1_BASE)
|
||||||
static void uart1_irq(void)
|
static void uart1_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(0);
|
uart_irq(UART_1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART2_BASE)
|
||||||
static void uart2_irq(void)
|
static void uart2_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(1);
|
uart_irq(UART_2);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(USART3_BASE)
|
#if defined(USART3_BASE)
|
||||||
static void uart3_irq(void)
|
static void uart3_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(2);
|
uart_irq(UART_3);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART4_BASE)
|
#if defined(UART4_BASE)
|
||||||
static void uart4_irq(void)
|
static void uart4_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(3);
|
uart_irq(UART_4);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART5_BASE)
|
#if defined(UART5_BASE)
|
||||||
static void uart5_irq(void)
|
static void uart5_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(4);
|
uart_irq(UART_5);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USART6_BASE)
|
#if defined(USART6_BASE)
|
||||||
static void uart6_irq(void)
|
static void uart6_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(5);
|
uart_irq(UART_6);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART7_BASE)
|
#if defined(UART7_BASE)
|
||||||
static void uart7_irq(void)
|
static void uart7_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(6);
|
uart_irq(UART_7);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART8_BASE)
|
#if defined(UART8_BASE)
|
||||||
static void uart8_irq(void)
|
static void uart8_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(7);
|
uart_irq(UART_8);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART9_BASE)
|
#if defined(UART9_BASE)
|
||||||
static void uart9_irq(void)
|
static void uart9_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(8);
|
uart_irq(UART_9);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART10_BASE)
|
#if defined(UART10_BASE)
|
||||||
static void uart10_irq(void)
|
static void uart10_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(9);
|
uart_irq(UART_10);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -158,60 +168,63 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
|
||||||
IRQn_Type irq_n = (IRQn_Type)0;
|
IRQn_Type irq_n = (IRQn_Type)0;
|
||||||
uint32_t vector = 0;
|
uint32_t vector = 0;
|
||||||
|
|
||||||
switch (obj_s->index) {
|
switch (obj_s->uart) {
|
||||||
case 0:
|
#if defined(USART1_BASE)
|
||||||
|
case UART_1:
|
||||||
irq_n = USART1_IRQn;
|
irq_n = USART1_IRQn;
|
||||||
vector = (uint32_t)&uart1_irq;
|
vector = (uint32_t)&uart1_irq;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case 1:
|
#if defined(USART2_BASE)
|
||||||
|
case UART_2:
|
||||||
irq_n = USART2_IRQn;
|
irq_n = USART2_IRQn;
|
||||||
vector = (uint32_t)&uart2_irq;
|
vector = (uint32_t)&uart2_irq;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
#if defined(USART3_BASE)
|
#if defined(USART3_BASE)
|
||||||
case 2:
|
case UART_3:
|
||||||
irq_n = USART3_IRQn;
|
irq_n = USART3_IRQn;
|
||||||
vector = (uint32_t)&uart3_irq;
|
vector = (uint32_t)&uart3_irq;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART4_BASE)
|
#if defined(UART4_BASE)
|
||||||
case 3:
|
case UART_4:
|
||||||
irq_n = UART4_IRQn;
|
irq_n = UART4_IRQn;
|
||||||
vector = (uint32_t)&uart4_irq;
|
vector = (uint32_t)&uart4_irq;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART5_BASE)
|
#if defined(UART5_BASE)
|
||||||
case 4:
|
case UART_5:
|
||||||
irq_n = UART5_IRQn;
|
irq_n = UART5_IRQn;
|
||||||
vector = (uint32_t)&uart5_irq;
|
vector = (uint32_t)&uart5_irq;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(USART6_BASE)
|
#if defined(USART6_BASE)
|
||||||
case 5:
|
case UART_6:
|
||||||
irq_n = USART6_IRQn;
|
irq_n = USART6_IRQn;
|
||||||
vector = (uint32_t)&uart6_irq;
|
vector = (uint32_t)&uart6_irq;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART7_BASE)
|
#if defined(UART7_BASE)
|
||||||
case 6:
|
case UART_7:
|
||||||
irq_n = UART7_IRQn;
|
irq_n = UART7_IRQn;
|
||||||
vector = (uint32_t)&uart7_irq;
|
vector = (uint32_t)&uart7_irq;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART8_BASE)
|
#if defined(UART8_BASE)
|
||||||
case 7:
|
case UART_8:
|
||||||
irq_n = UART8_IRQn;
|
irq_n = UART8_IRQn;
|
||||||
vector = (uint32_t)&uart8_irq;
|
vector = (uint32_t)&uart8_irq;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART9_BASE)
|
#if defined(UART9_BASE)
|
||||||
case 8:
|
case UART_9:
|
||||||
irq_n = UART9_IRQn;
|
irq_n = UART9_IRQn;
|
||||||
vector = (uint32_t)&uart9_irq;
|
vector = (uint32_t)&uart9_irq;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART10_BASE)
|
#if defined(UART10_BASE)
|
||||||
case 9:
|
case UART_10:
|
||||||
irq_n = UART10_IRQn;
|
irq_n = UART10_IRQn;
|
||||||
vector = (uint32_t)&uart10_irq;
|
vector = (uint32_t)&uart10_irq;
|
||||||
break;
|
break;
|
||||||
|
@ -359,62 +372,61 @@ static void serial_enable_event(serial_t *obj, int event, uint8_t enable)
|
||||||
/**
|
/**
|
||||||
* Get index of serial object TX IRQ, relating it to the physical peripheral.
|
* Get index of serial object TX IRQ, relating it to the physical peripheral.
|
||||||
*
|
*
|
||||||
* @param obj pointer to serial object
|
* @param uart_name i.e. UART_1, UART_2, ...
|
||||||
* @return internal NVIC TX IRQ index of U(S)ART peripheral
|
* @return internal NVIC TX IRQ index of U(S)ART peripheral
|
||||||
*/
|
*/
|
||||||
static IRQn_Type serial_get_irq_n(serial_t *obj)
|
static IRQn_Type serial_get_irq_n(UARTName uart_name)
|
||||||
{
|
{
|
||||||
struct serial_s *obj_s = SERIAL_S(obj);
|
|
||||||
IRQn_Type irq_n;
|
IRQn_Type irq_n;
|
||||||
|
|
||||||
switch (obj_s->index) {
|
switch (uart_name) {
|
||||||
#if defined(USART1_BASE)
|
#if defined(USART1_BASE)
|
||||||
case 0:
|
case UART_1:
|
||||||
irq_n = USART1_IRQn;
|
irq_n = USART1_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(USART2_BASE)
|
#if defined(USART2_BASE)
|
||||||
case 1:
|
case UART_2:
|
||||||
irq_n = USART2_IRQn;
|
irq_n = USART2_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(USART3_BASE)
|
#if defined(USART3_BASE)
|
||||||
case 2:
|
case UART_3:
|
||||||
irq_n = USART3_IRQn;
|
irq_n = USART3_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART4_BASE)
|
#if defined(UART4_BASE)
|
||||||
case 3:
|
case UART_4:
|
||||||
irq_n = UART4_IRQn;
|
irq_n = UART4_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(USART5_BASE)
|
#if defined(UART5_BASE)
|
||||||
case 4:
|
case UART_5:
|
||||||
irq_n = UART5_IRQn;
|
irq_n = UART5_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(USART6_BASE)
|
#if defined(USART6_BASE)
|
||||||
case 5:
|
case UART_6:
|
||||||
irq_n = USART6_IRQn;
|
irq_n = USART6_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART7_BASE)
|
#if defined(UART7_BASE)
|
||||||
case 6:
|
case UART_7:
|
||||||
irq_n = UART7_IRQn;
|
irq_n = UART7_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART8_BASE)
|
#if defined(UART8_BASE)
|
||||||
case 7:
|
case UART_8:
|
||||||
irq_n = UART8_IRQn;
|
irq_n = UART8_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART9_BASE)
|
#if defined(UART9_BASE)
|
||||||
case 8:
|
case UART_9:
|
||||||
irq_n = UART9_IRQn;
|
irq_n = UART9_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART10_BASE)
|
#if defined(UART10_BASE)
|
||||||
case 9:
|
case UART_10:
|
||||||
irq_n = UART10_IRQn;
|
irq_n = UART10_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
@ -466,7 +478,7 @@ int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx
|
||||||
serial_enable_event(obj, event, 1); // Set only the wanted events
|
serial_enable_event(obj, event, 1); // Set only the wanted events
|
||||||
|
|
||||||
// Enable interrupt
|
// Enable interrupt
|
||||||
IRQn_Type irq_n = serial_get_irq_n(obj);
|
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
|
||||||
NVIC_ClearPendingIRQ(irq_n);
|
NVIC_ClearPendingIRQ(irq_n);
|
||||||
NVIC_DisableIRQ(irq_n);
|
NVIC_DisableIRQ(irq_n);
|
||||||
NVIC_SetPriority(irq_n, 1);
|
NVIC_SetPriority(irq_n, 1);
|
||||||
|
@ -516,7 +528,7 @@ void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_widt
|
||||||
|
|
||||||
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
|
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
|
||||||
|
|
||||||
IRQn_Type irq_n = serial_get_irq_n(obj);
|
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
|
||||||
NVIC_ClearPendingIRQ(irq_n);
|
NVIC_ClearPendingIRQ(irq_n);
|
||||||
NVIC_DisableIRQ(irq_n);
|
NVIC_DisableIRQ(irq_n);
|
||||||
NVIC_SetPriority(irq_n, 0);
|
NVIC_SetPriority(irq_n, 0);
|
||||||
|
|
|
@ -38,14 +38,19 @@ UART_HandleTypeDef uart_handlers[UART_NUM];
|
||||||
|
|
||||||
static uart_irq_handler irq_handler;
|
static uart_irq_handler irq_handler;
|
||||||
|
|
||||||
|
// Defined in serial_api.c
|
||||||
|
inline int8_t get_uart_index(UARTName uart_name);
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* INTERRUPTS HANDLING
|
* INTERRUPTS HANDLING
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
static void uart_irq(int id)
|
static void uart_irq(UARTName uart_name)
|
||||||
{
|
{
|
||||||
UART_HandleTypeDef * huart = &uart_handlers[id];
|
int8_t id = get_uart_index(uart_name);
|
||||||
|
|
||||||
|
if (id >= 0) {
|
||||||
|
UART_HandleTypeDef * huart = &uart_handlers[id];
|
||||||
if (serial_irq_ids[id] != 0) {
|
if (serial_irq_ids[id] != 0) {
|
||||||
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
|
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
|
||||||
if (__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET) {
|
if (__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET) {
|
||||||
|
@ -64,55 +69,62 @@ static void uart_irq(int id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(USART1_BASE)
|
||||||
static void uart1_irq(void)
|
static void uart1_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(0);
|
uart_irq(UART_1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART2_BASE)
|
||||||
static void uart2_irq(void)
|
static void uart2_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(1);
|
uart_irq(UART_2);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(USART3_BASE)
|
#if defined(USART3_BASE)
|
||||||
static void uart3_irq(void)
|
static void uart3_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(2);
|
uart_irq(UART_3);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART4_BASE)
|
#if defined(UART4_BASE)
|
||||||
static void uart4_irq(void)
|
static void uart4_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(3);
|
uart_irq(UART_4);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART5_BASE)
|
#if defined(UART5_BASE)
|
||||||
static void uart5_irq(void)
|
static void uart5_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(4);
|
uart_irq(UART_5);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART6_BASE)
|
||||||
static void uart6_irq(void)
|
static void uart6_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(5);
|
uart_irq(UART_6);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(UART7_BASE)
|
#if defined(UART7_BASE)
|
||||||
static void uart7_irq(void)
|
static void uart7_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(6);
|
uart_irq(UART_7);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART8_BASE)
|
#if defined(UART8_BASE)
|
||||||
static void uart8_irq(void)
|
static void uart8_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(7);
|
uart_irq(UART_8);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -132,15 +144,18 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
|
||||||
uint32_t vector = 0;
|
uint32_t vector = 0;
|
||||||
|
|
||||||
switch (obj_s->uart) {
|
switch (obj_s->uart) {
|
||||||
|
#if defined(USART1_BASE)
|
||||||
case UART_1:
|
case UART_1:
|
||||||
irq_n = USART1_IRQn;
|
irq_n = USART1_IRQn;
|
||||||
vector = (uint32_t)&uart1_irq;
|
vector = (uint32_t)&uart1_irq;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#if defined(USART2_BASE)
|
||||||
case UART_2:
|
case UART_2:
|
||||||
irq_n = USART2_IRQn;
|
irq_n = USART2_IRQn;
|
||||||
vector = (uint32_t)&uart2_irq;
|
vector = (uint32_t)&uart2_irq;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
#if defined(USART3_BASE)
|
#if defined(USART3_BASE)
|
||||||
case UART_3:
|
case UART_3:
|
||||||
irq_n = USART3_IRQn;
|
irq_n = USART3_IRQn;
|
||||||
|
@ -159,10 +174,12 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
|
||||||
vector = (uint32_t)&uart5_irq;
|
vector = (uint32_t)&uart5_irq;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(USART6_BASE)
|
||||||
case UART_6:
|
case UART_6:
|
||||||
irq_n = USART6_IRQn;
|
irq_n = USART6_IRQn;
|
||||||
vector = (uint32_t)&uart6_irq;
|
vector = (uint32_t)&uart6_irq;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
#if defined(UART7_BASE)
|
#if defined(UART7_BASE)
|
||||||
case UART_7:
|
case UART_7:
|
||||||
irq_n = UART7_IRQn;
|
irq_n = UART7_IRQn;
|
||||||
|
@ -318,48 +335,51 @@ static void serial_enable_event(serial_t *obj, int event, uint8_t enable)
|
||||||
/**
|
/**
|
||||||
* Get index of serial object TX IRQ, relating it to the physical peripheral.
|
* Get index of serial object TX IRQ, relating it to the physical peripheral.
|
||||||
*
|
*
|
||||||
* @param obj pointer to serial object
|
* @param uart_name i.e. UART_1, UART_2, ...
|
||||||
* @return internal NVIC TX IRQ index of U(S)ART peripheral
|
* @return internal NVIC TX IRQ index of U(S)ART peripheral
|
||||||
*/
|
*/
|
||||||
static IRQn_Type serial_get_irq_n(serial_t *obj)
|
static IRQn_Type serial_get_irq_n(UARTName uart_name)
|
||||||
{
|
{
|
||||||
struct serial_s *obj_s = SERIAL_S(obj);
|
|
||||||
IRQn_Type irq_n;
|
IRQn_Type irq_n;
|
||||||
|
|
||||||
switch (obj_s->index) {
|
switch (uart_name) {
|
||||||
|
#if defined(USART1_BASE)
|
||||||
case 0:
|
case UART_1:
|
||||||
irq_n = USART1_IRQn;
|
irq_n = USART1_IRQn;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case 1:
|
#if defined(USART2_BASE)
|
||||||
|
case UART_2:
|
||||||
irq_n = USART2_IRQn;
|
irq_n = USART2_IRQn;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
#if defined(USART3_BASE)
|
#if defined(USART3_BASE)
|
||||||
case 2:
|
case UART_3:
|
||||||
irq_n = USART3_IRQn;
|
irq_n = USART3_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART4_BASE)
|
#if defined(UART4_BASE)
|
||||||
case 3:
|
case UART_4:
|
||||||
irq_n = UART4_IRQn;
|
irq_n = UART4_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART5_BASE)
|
#if defined(UART5_BASE)
|
||||||
case 4:
|
case UART_5:
|
||||||
irq_n = UART5_IRQn;
|
irq_n = UART5_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 5:
|
#if defined(USART6_BASE)
|
||||||
|
case UART_6:
|
||||||
irq_n = USART6_IRQn;
|
irq_n = USART6_IRQn;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
#if defined(UART7_BASE)
|
#if defined(UART7_BASE)
|
||||||
case 6:
|
case UART_7:
|
||||||
irq_n = UART7_IRQn;
|
irq_n = UART7_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART8_BASE)
|
#if defined(UART8_BASE)
|
||||||
case 7:
|
case UART_8:
|
||||||
irq_n = UART8_IRQn;
|
irq_n = UART8_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
@ -411,7 +431,7 @@ int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx
|
||||||
serial_enable_event(obj, event, 1); // Set only the wanted events
|
serial_enable_event(obj, event, 1); // Set only the wanted events
|
||||||
|
|
||||||
// Enable interrupt
|
// Enable interrupt
|
||||||
IRQn_Type irq_n = serial_get_irq_n(obj);
|
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
|
||||||
NVIC_ClearPendingIRQ(irq_n);
|
NVIC_ClearPendingIRQ(irq_n);
|
||||||
NVIC_DisableIRQ(irq_n);
|
NVIC_DisableIRQ(irq_n);
|
||||||
NVIC_SetPriority(irq_n, 1);
|
NVIC_SetPriority(irq_n, 1);
|
||||||
|
@ -461,7 +481,7 @@ void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_widt
|
||||||
|
|
||||||
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
|
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
|
||||||
|
|
||||||
IRQn_Type irq_n = serial_get_irq_n(obj);
|
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
|
||||||
NVIC_ClearPendingIRQ(irq_n);
|
NVIC_ClearPendingIRQ(irq_n);
|
||||||
NVIC_DisableIRQ(irq_n);
|
NVIC_DisableIRQ(irq_n);
|
||||||
NVIC_SetPriority(irq_n, 0);
|
NVIC_SetPriority(irq_n, 0);
|
||||||
|
|
|
@ -45,14 +45,19 @@ UART_HandleTypeDef uart_handlers[UART_NUM];
|
||||||
|
|
||||||
static uart_irq_handler irq_handler;
|
static uart_irq_handler irq_handler;
|
||||||
|
|
||||||
|
// Defined in serial_api.c
|
||||||
|
inline int8_t get_uart_index(UARTName uart_name);
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* INTERRUPTS HANDLING
|
* INTERRUPTS HANDLING
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
static void uart_irq(int id)
|
static void uart_irq(UARTName uart_name)
|
||||||
{
|
{
|
||||||
UART_HandleTypeDef * huart = &uart_handlers[id];
|
int8_t id = get_uart_index(uart_name);
|
||||||
|
|
||||||
|
if (id >= 0) {
|
||||||
|
UART_HandleTypeDef * huart = &uart_handlers[id];
|
||||||
if (serial_irq_ids[id] != 0) {
|
if (serial_irq_ids[id] != 0) {
|
||||||
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
|
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
|
||||||
if (__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET) {
|
if (__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET) {
|
||||||
|
@ -71,36 +76,41 @@ static void uart_irq(int id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(USART1_BASE)
|
#if defined(USART1_BASE)
|
||||||
static void uart1_irq(void)
|
static void uart1_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(0);
|
uart_irq(UART_1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART2_BASE)
|
||||||
static void uart2_irq(void)
|
static void uart2_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(1);
|
uart_irq(UART_2);
|
||||||
}
|
|
||||||
|
|
||||||
static void lpuart1_irq(void)
|
|
||||||
{
|
|
||||||
uart_irq(2);
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(USART4_BASE)
|
#if defined(USART4_BASE)
|
||||||
static void uart4_irq(void)
|
static void uart4_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(3);
|
uart_irq(UART_4);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USART5_BASE)
|
#if defined(USART5_BASE)
|
||||||
static void uart5_irq(void)
|
static void uart5_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(4);
|
uart_irq(UART_5);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(LPUART1_BASE)
|
||||||
|
static void lpuart1_irq(void)
|
||||||
|
{
|
||||||
|
uart_irq(LPUART_1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -126,15 +136,12 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART2_BASE)
|
||||||
if (obj_s->uart == UART_2) {
|
if (obj_s->uart == UART_2) {
|
||||||
irq_n = USART2_IRQn;
|
irq_n = USART2_IRQn;
|
||||||
vector = (uint32_t)&uart2_irq;
|
vector = (uint32_t)&uart2_irq;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (obj_s->uart == LPUART_1) {
|
|
||||||
irq_n = RNG_LPUART1_IRQn;
|
|
||||||
vector = (uint32_t)&lpuart1_irq;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(USART4_BASE)
|
#if defined(USART4_BASE)
|
||||||
if (obj_s->uart == UART_4) {
|
if (obj_s->uart == UART_4) {
|
||||||
|
@ -150,6 +157,13 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(LPUART1_BASE)
|
||||||
|
if (obj_s->uart == LPUART_1) {
|
||||||
|
irq_n = RNG_LPUART1_IRQn;
|
||||||
|
vector = (uint32_t)&lpuart1_irq;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
if (irq == RxIrq) {
|
if (irq == RxIrq) {
|
||||||
__HAL_UART_ENABLE_IT(huart, UART_IT_RXNE);
|
__HAL_UART_ENABLE_IT(huart, UART_IT_RXNE);
|
||||||
|
@ -291,36 +305,38 @@ static void serial_enable_event(serial_t *obj, int event, uint8_t enable)
|
||||||
/**
|
/**
|
||||||
* Get index of serial object TX IRQ, relating it to the physical peripheral.
|
* Get index of serial object TX IRQ, relating it to the physical peripheral.
|
||||||
*
|
*
|
||||||
* @param obj pointer to serial object
|
* @param uart_name i.e. UART_1, UART_2, ...
|
||||||
* @return internal NVIC TX IRQ index of U(S)ART peripheral
|
* @return internal NVIC TX IRQ index of U(S)ART peripheral
|
||||||
*/
|
*/
|
||||||
static IRQn_Type serial_get_irq_n(serial_t *obj)
|
static IRQn_Type serial_get_irq_n(UARTName uart_name)
|
||||||
{
|
{
|
||||||
struct serial_s *obj_s = SERIAL_S(obj);
|
|
||||||
IRQn_Type irq_n;
|
IRQn_Type irq_n;
|
||||||
|
|
||||||
switch (obj_s->index) {
|
switch (uart_name) {
|
||||||
#if defined(USART1_BASE)
|
#if defined(USART1_BASE)
|
||||||
case 0:
|
case UART_1:
|
||||||
irq_n = USART1_IRQn;
|
irq_n = USART1_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 1:
|
#if defined(USART2_BASE)
|
||||||
|
case UART_2:
|
||||||
irq_n = USART2_IRQn;
|
irq_n = USART2_IRQn;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case 2:
|
|
||||||
irq_n = RNG_LPUART1_IRQn;
|
|
||||||
break;
|
|
||||||
#if defined(USART4_BASE)
|
#if defined(USART4_BASE)
|
||||||
case 3:
|
case UART_4:
|
||||||
irq_n = USART4_5_IRQn;
|
irq_n = USART4_5_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(USART5_BASE)
|
#if defined(USART5_BASE)
|
||||||
case 4:
|
case UART_5:
|
||||||
irq_n = USART4_5_IRQn;
|
irq_n = USART4_5_IRQn;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#if defined(LPUART1_BASE)
|
||||||
|
case LPUART_1:
|
||||||
|
irq_n = RNG_LPUART1_IRQn;
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
irq_n = (IRQn_Type)0;
|
irq_n = (IRQn_Type)0;
|
||||||
|
@ -371,7 +387,7 @@ int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx
|
||||||
serial_enable_event(obj, event, 1); // Set only the wanted events
|
serial_enable_event(obj, event, 1); // Set only the wanted events
|
||||||
|
|
||||||
// Enable interrupt
|
// Enable interrupt
|
||||||
IRQn_Type irq_n = serial_get_irq_n(obj);
|
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
|
||||||
NVIC_ClearPendingIRQ(irq_n);
|
NVIC_ClearPendingIRQ(irq_n);
|
||||||
NVIC_DisableIRQ(irq_n);
|
NVIC_DisableIRQ(irq_n);
|
||||||
NVIC_SetPriority(irq_n, 1);
|
NVIC_SetPriority(irq_n, 1);
|
||||||
|
@ -421,7 +437,7 @@ void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_widt
|
||||||
|
|
||||||
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
|
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
|
||||||
|
|
||||||
IRQn_Type irq_n = serial_get_irq_n(obj);
|
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
|
||||||
NVIC_ClearPendingIRQ(irq_n);
|
NVIC_ClearPendingIRQ(irq_n);
|
||||||
NVIC_DisableIRQ(irq_n);
|
NVIC_DisableIRQ(irq_n);
|
||||||
NVIC_SetPriority(irq_n, 0);
|
NVIC_SetPriority(irq_n, 0);
|
||||||
|
|
|
@ -39,14 +39,19 @@ UART_HandleTypeDef uart_handlers[UART_NUM];
|
||||||
|
|
||||||
static uart_irq_handler irq_handler;
|
static uart_irq_handler irq_handler;
|
||||||
|
|
||||||
|
// Defined in serial_api.c
|
||||||
|
inline int8_t get_uart_index(UARTName uart_name);
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* INTERRUPTS HANDLING
|
* INTERRUPTS HANDLING
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
static void uart_irq(int id)
|
static void uart_irq(UARTName uart_name)
|
||||||
{
|
{
|
||||||
UART_HandleTypeDef * huart = &uart_handlers[id];
|
int8_t id = get_uart_index(uart_name);
|
||||||
|
|
||||||
|
if (id >= 0) {
|
||||||
|
UART_HandleTypeDef * huart = &uart_handlers[id];
|
||||||
if (serial_irq_ids[id] != 0) {
|
if (serial_irq_ids[id] != 0) {
|
||||||
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
|
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
|
||||||
if (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE) != RESET) {
|
if (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE) != RESET) {
|
||||||
|
@ -65,33 +70,41 @@ static void uart_irq(int id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(USART1_BASE)
|
||||||
static void uart1_irq(void)
|
static void uart1_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(0);
|
uart_irq(UART_1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART2_BASE)
|
||||||
static void uart2_irq(void)
|
static void uart2_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(1);
|
uart_irq(UART_2);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART3_BASE)
|
||||||
static void uart3_irq(void)
|
static void uart3_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(2);
|
uart_irq(UART_3);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(UART4_BASE)
|
#if defined(UART4_BASE)
|
||||||
static void uart4_irq(void)
|
static void uart4_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(3);
|
uart_irq(UART_4);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART5_BASE)
|
#if defined(UART5_BASE)
|
||||||
static void uart5_irq(void)
|
static void uart5_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(4);
|
uart_irq(UART_5);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -110,32 +123,38 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
|
||||||
IRQn_Type irq_n = (IRQn_Type)0;
|
IRQn_Type irq_n = (IRQn_Type)0;
|
||||||
uint32_t vector = 0;
|
uint32_t vector = 0;
|
||||||
|
|
||||||
if (obj_s->uart == UART_1) {
|
switch (obj_s->uart) {
|
||||||
|
#if defined(USART1_BASE)
|
||||||
|
case UART_1:
|
||||||
irq_n = USART1_IRQn;
|
irq_n = USART1_IRQn;
|
||||||
vector = (uint32_t)&uart1_irq;
|
vector = (uint32_t)&uart1_irq;
|
||||||
}
|
break;
|
||||||
|
#endif
|
||||||
if (obj_s->uart == UART_2) {
|
#if defined(USART2_BASE)
|
||||||
|
case UART_2:
|
||||||
irq_n = USART2_IRQn;
|
irq_n = USART2_IRQn;
|
||||||
vector = (uint32_t)&uart2_irq;
|
vector = (uint32_t)&uart2_irq;
|
||||||
}
|
break;
|
||||||
|
#endif
|
||||||
if (obj_s->uart == UART_3) {
|
#if defined(USART3_BASE)
|
||||||
|
case UART_3:
|
||||||
irq_n = USART3_IRQn;
|
irq_n = USART3_IRQn;
|
||||||
vector = (uint32_t)&uart3_irq;
|
vector = (uint32_t)&uart3_irq;
|
||||||
}
|
break;
|
||||||
|
#endif
|
||||||
#if defined(UART4_BASE)
|
#if defined(UART4_BASE)
|
||||||
if (obj_s->uart == UART_4) {
|
case UART_4:
|
||||||
irq_n = UART4_IRQn;
|
irq_n = UART4_IRQn;
|
||||||
vector = (uint32_t)&uart4_irq;
|
vector = (uint32_t)&uart4_irq;
|
||||||
}
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART5_BASE)
|
#if defined(UART5_BASE)
|
||||||
if (obj_s->uart == UART_5) {
|
case UART_5:
|
||||||
irq_n = UART5_IRQn;
|
irq_n = UART5_IRQn;
|
||||||
vector = (uint32_t)&uart5_irq;
|
vector = (uint32_t)&uart5_irq;
|
||||||
}
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
if (irq == RxIrq) {
|
if (irq == RxIrq) {
|
||||||
|
@ -286,33 +305,36 @@ static void serial_enable_event(serial_t *obj, int event, uint8_t enable)
|
||||||
/**
|
/**
|
||||||
* Get index of serial object TX IRQ, relating it to the physical peripheral.
|
* Get index of serial object TX IRQ, relating it to the physical peripheral.
|
||||||
*
|
*
|
||||||
* @param obj pointer to serial object
|
* @param uart_name i.e. UART_1, UART_2, ...
|
||||||
* @return internal NVIC TX IRQ index of U(S)ART peripheral
|
* @return internal NVIC TX IRQ index of U(S)ART peripheral
|
||||||
*/
|
*/
|
||||||
static IRQn_Type serial_get_irq_n(serial_t *obj)
|
static IRQn_Type serial_get_irq_n(UARTName uart_name)
|
||||||
{
|
{
|
||||||
struct serial_s *obj_s = SERIAL_S(obj);
|
|
||||||
IRQn_Type irq_n;
|
IRQn_Type irq_n;
|
||||||
|
|
||||||
switch (obj_s->index) {
|
switch (uart_name) {
|
||||||
case 0:
|
#if defined(USART1_BASE)
|
||||||
|
case UART_1:
|
||||||
irq_n = USART1_IRQn;
|
irq_n = USART1_IRQn;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case 1:
|
#if defined(USART2_BASE)
|
||||||
|
case UART_2:
|
||||||
irq_n = USART2_IRQn;
|
irq_n = USART2_IRQn;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case 2:
|
#if defined(USART3_BASE)
|
||||||
|
case UART_3:
|
||||||
irq_n = USART3_IRQn;
|
irq_n = USART3_IRQn;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
#if defined(UART4_BASE)
|
#if defined(UART4_BASE)
|
||||||
case 3:
|
case UART_4:
|
||||||
irq_n = UART4_IRQn;
|
irq_n = UART4_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART5_BASE)
|
#if defined(UART5_BASE)
|
||||||
case 4:
|
case UART_5:
|
||||||
irq_n = UART5_IRQn;
|
irq_n = UART5_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
@ -364,7 +386,7 @@ int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx
|
||||||
serial_enable_event(obj, event, 1); // Set only the wanted events
|
serial_enable_event(obj, event, 1); // Set only the wanted events
|
||||||
|
|
||||||
// Enable interrupt
|
// Enable interrupt
|
||||||
IRQn_Type irq_n = serial_get_irq_n(obj);
|
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
|
||||||
NVIC_ClearPendingIRQ(irq_n);
|
NVIC_ClearPendingIRQ(irq_n);
|
||||||
NVIC_DisableIRQ(irq_n);
|
NVIC_DisableIRQ(irq_n);
|
||||||
NVIC_SetPriority(irq_n, 1);
|
NVIC_SetPriority(irq_n, 1);
|
||||||
|
@ -414,7 +436,7 @@ void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_widt
|
||||||
|
|
||||||
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
|
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
|
||||||
|
|
||||||
IRQn_Type irq_n = serial_get_irq_n(obj);
|
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
|
||||||
NVIC_ClearPendingIRQ(irq_n);
|
NVIC_ClearPendingIRQ(irq_n);
|
||||||
NVIC_DisableIRQ(irq_n);
|
NVIC_DisableIRQ(irq_n);
|
||||||
NVIC_SetPriority(irq_n, 0);
|
NVIC_SetPriority(irq_n, 0);
|
||||||
|
|
|
@ -45,14 +45,19 @@ UART_HandleTypeDef uart_handlers[UART_NUM];
|
||||||
|
|
||||||
static uart_irq_handler irq_handler;
|
static uart_irq_handler irq_handler;
|
||||||
|
|
||||||
|
// Defined in serial_api.c
|
||||||
|
inline int8_t get_uart_index(UARTName uart_name);
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* INTERRUPTS HANDLING
|
* INTERRUPTS HANDLING
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
static void uart_irq(int id)
|
static void uart_irq(UARTName uart_name)
|
||||||
{
|
{
|
||||||
UART_HandleTypeDef * huart = &uart_handlers[id];
|
int8_t id = get_uart_index(uart_name);
|
||||||
|
|
||||||
|
if (id >= 0) {
|
||||||
|
UART_HandleTypeDef * huart = &uart_handlers[id];
|
||||||
if (serial_irq_ids[id] != 0) {
|
if (serial_irq_ids[id] != 0) {
|
||||||
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
|
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
|
||||||
if (__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET) {
|
if (__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET) {
|
||||||
|
@ -71,43 +76,48 @@ static void uart_irq(int id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(USART1_BASE)
|
||||||
static void uart1_irq(void)
|
static void uart1_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(0);
|
uart_irq(UART_1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART2_BASE)
|
||||||
static void uart2_irq(void)
|
static void uart2_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(1);
|
uart_irq(UART_2);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(USART3_BASE)
|
#if defined(USART3_BASE)
|
||||||
static void uart3_irq(void)
|
static void uart3_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(2);
|
uart_irq(UART_3);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART4_BASE)
|
#if defined(UART4_BASE)
|
||||||
static void uart4_irq(void)
|
static void uart4_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(3);
|
uart_irq(UART_4);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART5_BASE)
|
#if defined(UART5_BASE)
|
||||||
static void uart5_irq(void)
|
static void uart5_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(4);
|
uart_irq(UART_5);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(LPUART1_BASE)
|
#if defined(LPUART1_BASE)
|
||||||
static void lpuart1_irq(void)
|
static void lpuart1_irq(void)
|
||||||
{
|
{
|
||||||
uart_irq(5);
|
uart_irq(LPUART_1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -126,41 +136,44 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
|
||||||
IRQn_Type irq_n = (IRQn_Type)0;
|
IRQn_Type irq_n = (IRQn_Type)0;
|
||||||
uint32_t vector = 0;
|
uint32_t vector = 0;
|
||||||
|
|
||||||
if (obj_s->uart == UART_1) {
|
switch (obj_s->uart) {
|
||||||
|
#if defined(USART1_BASE)
|
||||||
|
case UART_1:
|
||||||
irq_n = USART1_IRQn;
|
irq_n = USART1_IRQn;
|
||||||
vector = (uint32_t)&uart1_irq;
|
vector = (uint32_t)&uart1_irq;
|
||||||
}
|
break;
|
||||||
|
#endif
|
||||||
if (obj_s->uart == UART_2) {
|
#if defined(USART2_BASE)
|
||||||
|
case UART_2:
|
||||||
irq_n = USART2_IRQn;
|
irq_n = USART2_IRQn;
|
||||||
vector = (uint32_t)&uart2_irq;
|
vector = (uint32_t)&uart2_irq;
|
||||||
}
|
break;
|
||||||
|
#endif
|
||||||
#if defined(USART3_BASE)
|
#if defined(USART3_BASE)
|
||||||
if (obj_s->uart == UART_3) {
|
case UART_3:
|
||||||
irq_n = USART3_IRQn;
|
irq_n = USART3_IRQn;
|
||||||
vector = (uint32_t)&uart3_irq;
|
vector = (uint32_t)&uart3_irq;
|
||||||
}
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART4_BASE)
|
#if defined(UART4_BASE)
|
||||||
if (obj_s->uart == UART_4) {
|
case UART_4:
|
||||||
irq_n = UART4_IRQn;
|
irq_n = UART4_IRQn;
|
||||||
vector = (uint32_t)&uart4_irq;
|
vector = (uint32_t)&uart4_irq;
|
||||||
}
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART5_BASE)
|
#if defined(UART5_BASE)
|
||||||
if (obj_s->uart == UART_5) {
|
case UART_5:
|
||||||
irq_n = UART5_IRQn;
|
irq_n = UART5_IRQn;
|
||||||
vector = (uint32_t)&uart5_irq;
|
vector = (uint32_t)&uart5_irq;
|
||||||
}
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(LPUART1_BASE)
|
#if defined(LPUART1_BASE)
|
||||||
if (obj_s->uart == LPUART_1) {
|
case LPUART_1:
|
||||||
irq_n = LPUART1_IRQn;
|
irq_n = LPUART1_IRQn;
|
||||||
vector = (uint32_t)&lpuart1_irq;
|
vector = (uint32_t)&lpuart1_irq;
|
||||||
}
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
if (irq == RxIrq) {
|
if (irq == RxIrq) {
|
||||||
|
@ -311,44 +324,44 @@ static void serial_enable_event(serial_t *obj, int event, uint8_t enable)
|
||||||
/**
|
/**
|
||||||
* Get index of serial object TX IRQ, relating it to the physical peripheral.
|
* Get index of serial object TX IRQ, relating it to the physical peripheral.
|
||||||
*
|
*
|
||||||
* @param obj pointer to serial object
|
* @param uart_name i.e. UART_1, UART_2, ...
|
||||||
* @return internal NVIC TX IRQ index of U(S)ART peripheral
|
* @return internal NVIC TX IRQ index of U(S)ART peripheral
|
||||||
*/
|
*/
|
||||||
static IRQn_Type serial_get_irq_n(serial_t *obj)
|
static IRQn_Type serial_get_irq_n(UARTName uart_name)
|
||||||
{
|
{
|
||||||
struct serial_s *obj_s = SERIAL_S(obj);
|
|
||||||
IRQn_Type irq_n;
|
IRQn_Type irq_n;
|
||||||
|
|
||||||
switch (obj_s->index) {
|
switch (uart_name) {
|
||||||
case 0:
|
#if defined(USART1_BASE)
|
||||||
|
case UART_1:
|
||||||
irq_n = USART1_IRQn;
|
irq_n = USART1_IRQn;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case 1:
|
#if defined(USART2_BASE)
|
||||||
|
case UART_2:
|
||||||
irq_n = USART2_IRQn;
|
irq_n = USART2_IRQn;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
#if defined(USART3_BASE)
|
#if defined(USART3_BASE)
|
||||||
case 2:
|
case UART_3:
|
||||||
irq_n = USART3_IRQn;
|
irq_n = USART3_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART4_BASE)
|
#if defined(UART4_BASE)
|
||||||
case 3:
|
case UART_4:
|
||||||
irq_n = UART4_IRQn;
|
irq_n = UART4_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(UART5_BASE)
|
#if defined(UART5_BASE)
|
||||||
case 4:
|
case UART_5:
|
||||||
irq_n = UART5_IRQn;
|
irq_n = UART5_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(LPUART1_BASE)
|
#if defined(LPUART1_BASE)
|
||||||
case 5:
|
case LPUART_1:
|
||||||
irq_n = LPUART1_IRQn;
|
irq_n = LPUART1_IRQn;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
irq_n = (IRQn_Type)0;
|
irq_n = (IRQn_Type)0;
|
||||||
}
|
}
|
||||||
|
@ -397,7 +410,7 @@ int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx
|
||||||
serial_enable_event(obj, event, 1); // Set only the wanted events
|
serial_enable_event(obj, event, 1); // Set only the wanted events
|
||||||
|
|
||||||
// Enable interrupt
|
// Enable interrupt
|
||||||
IRQn_Type irq_n = serial_get_irq_n(obj);
|
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
|
||||||
NVIC_ClearPendingIRQ(irq_n);
|
NVIC_ClearPendingIRQ(irq_n);
|
||||||
NVIC_DisableIRQ(irq_n);
|
NVIC_DisableIRQ(irq_n);
|
||||||
NVIC_SetPriority(irq_n, 1);
|
NVIC_SetPriority(irq_n, 1);
|
||||||
|
@ -447,7 +460,7 @@ void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_widt
|
||||||
|
|
||||||
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
|
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
|
||||||
|
|
||||||
IRQn_Type irq_n = serial_get_irq_n(obj);
|
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
|
||||||
NVIC_ClearPendingIRQ(irq_n);
|
NVIC_ClearPendingIRQ(irq_n);
|
||||||
NVIC_DisableIRQ(irq_n);
|
NVIC_DisableIRQ(irq_n);
|
||||||
NVIC_SetPriority(irq_n, 0);
|
NVIC_SetPriority(irq_n, 0);
|
||||||
|
|
|
@ -38,10 +38,13 @@ serial_t stdio_uart;
|
||||||
extern UART_HandleTypeDef uart_handlers[];
|
extern UART_HandleTypeDef uart_handlers[];
|
||||||
extern uint32_t serial_irq_ids[];
|
extern uint32_t serial_irq_ids[];
|
||||||
|
|
||||||
|
// Utility functions
|
||||||
|
HAL_StatusTypeDef init_uart(serial_t *obj);
|
||||||
|
int8_t get_uart_index(UARTName uart_name);
|
||||||
|
|
||||||
void serial_init(serial_t *obj, PinName tx, PinName rx)
|
void serial_init(serial_t *obj, PinName tx, PinName rx)
|
||||||
{
|
{
|
||||||
struct serial_s *obj_s = SERIAL_S(obj);
|
struct serial_s *obj_s = SERIAL_S(obj);
|
||||||
int IndexNumber = 0;
|
|
||||||
uint8_t stdio_config = 0;
|
uint8_t stdio_config = 0;
|
||||||
|
|
||||||
// Determine the UART to use (UART_1, UART_2, ...)
|
// Determine the UART to use (UART_1, UART_2, ...)
|
||||||
|
@ -61,15 +64,13 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable USART clock
|
// Reset and enable clock
|
||||||
#if defined(USART1_BASE)
|
#if defined(USART1_BASE)
|
||||||
if (obj_s->uart == UART_1) {
|
if (obj_s->uart == UART_1) {
|
||||||
__HAL_RCC_USART1_FORCE_RESET();
|
__HAL_RCC_USART1_FORCE_RESET();
|
||||||
__HAL_RCC_USART1_RELEASE_RESET();
|
__HAL_RCC_USART1_RELEASE_RESET();
|
||||||
__HAL_RCC_USART1_CLK_ENABLE();
|
__HAL_RCC_USART1_CLK_ENABLE();
|
||||||
obj_s->index = IndexNumber;
|
|
||||||
}
|
}
|
||||||
IndexNumber++;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined (USART2_BASE)
|
#if defined (USART2_BASE)
|
||||||
|
@ -77,9 +78,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
||||||
__HAL_RCC_USART2_FORCE_RESET();
|
__HAL_RCC_USART2_FORCE_RESET();
|
||||||
__HAL_RCC_USART2_RELEASE_RESET();
|
__HAL_RCC_USART2_RELEASE_RESET();
|
||||||
__HAL_RCC_USART2_CLK_ENABLE();
|
__HAL_RCC_USART2_CLK_ENABLE();
|
||||||
obj_s->index = IndexNumber;
|
|
||||||
}
|
}
|
||||||
IndexNumber++;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USART3_BASE)
|
#if defined(USART3_BASE)
|
||||||
|
@ -87,9 +86,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
||||||
__HAL_RCC_USART3_FORCE_RESET();
|
__HAL_RCC_USART3_FORCE_RESET();
|
||||||
__HAL_RCC_USART3_RELEASE_RESET();
|
__HAL_RCC_USART3_RELEASE_RESET();
|
||||||
__HAL_RCC_USART3_CLK_ENABLE();
|
__HAL_RCC_USART3_CLK_ENABLE();
|
||||||
obj_s->index = IndexNumber;
|
|
||||||
}
|
}
|
||||||
IndexNumber++;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART4_BASE)
|
#if defined(UART4_BASE)
|
||||||
|
@ -97,9 +94,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
||||||
__HAL_RCC_UART4_FORCE_RESET();
|
__HAL_RCC_UART4_FORCE_RESET();
|
||||||
__HAL_RCC_UART4_RELEASE_RESET();
|
__HAL_RCC_UART4_RELEASE_RESET();
|
||||||
__HAL_RCC_UART4_CLK_ENABLE();
|
__HAL_RCC_UART4_CLK_ENABLE();
|
||||||
obj_s->index = IndexNumber;
|
|
||||||
}
|
}
|
||||||
IndexNumber++;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USART4_BASE)
|
#if defined(USART4_BASE)
|
||||||
|
@ -107,9 +102,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
||||||
__HAL_RCC_USART4_FORCE_RESET();
|
__HAL_RCC_USART4_FORCE_RESET();
|
||||||
__HAL_RCC_USART4_RELEASE_RESET();
|
__HAL_RCC_USART4_RELEASE_RESET();
|
||||||
__HAL_RCC_USART4_CLK_ENABLE();
|
__HAL_RCC_USART4_CLK_ENABLE();
|
||||||
obj_s->index = IndexNumber;
|
|
||||||
}
|
}
|
||||||
IndexNumber++;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART5_BASE)
|
#if defined(UART5_BASE)
|
||||||
|
@ -117,9 +110,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
||||||
__HAL_RCC_UART5_FORCE_RESET();
|
__HAL_RCC_UART5_FORCE_RESET();
|
||||||
__HAL_RCC_UART5_RELEASE_RESET();
|
__HAL_RCC_UART5_RELEASE_RESET();
|
||||||
__HAL_RCC_UART5_CLK_ENABLE();
|
__HAL_RCC_UART5_CLK_ENABLE();
|
||||||
obj_s->index = IndexNumber;
|
|
||||||
}
|
}
|
||||||
IndexNumber++;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USART5_BASE)
|
#if defined(USART5_BASE)
|
||||||
|
@ -127,9 +118,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
||||||
__HAL_RCC_USART5_FORCE_RESET();
|
__HAL_RCC_USART5_FORCE_RESET();
|
||||||
__HAL_RCC_USART5_RELEASE_RESET();
|
__HAL_RCC_USART5_RELEASE_RESET();
|
||||||
__HAL_RCC_USART5_CLK_ENABLE();
|
__HAL_RCC_USART5_CLK_ENABLE();
|
||||||
obj_s->index = IndexNumber;
|
|
||||||
}
|
}
|
||||||
IndexNumber++;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USART6_BASE)
|
#if defined(USART6_BASE)
|
||||||
|
@ -137,9 +126,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
||||||
__HAL_RCC_USART6_FORCE_RESET();
|
__HAL_RCC_USART6_FORCE_RESET();
|
||||||
__HAL_RCC_USART6_RELEASE_RESET();
|
__HAL_RCC_USART6_RELEASE_RESET();
|
||||||
__HAL_RCC_USART6_CLK_ENABLE();
|
__HAL_RCC_USART6_CLK_ENABLE();
|
||||||
obj_s->index = IndexNumber;
|
|
||||||
}
|
}
|
||||||
IndexNumber++;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART7_BASE)
|
#if defined(UART7_BASE)
|
||||||
|
@ -147,9 +134,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
||||||
__HAL_RCC_UART7_FORCE_RESET();
|
__HAL_RCC_UART7_FORCE_RESET();
|
||||||
__HAL_RCC_UART7_RELEASE_RESET();
|
__HAL_RCC_UART7_RELEASE_RESET();
|
||||||
__HAL_RCC_UART7_CLK_ENABLE();
|
__HAL_RCC_UART7_CLK_ENABLE();
|
||||||
obj_s->index = IndexNumber;
|
|
||||||
}
|
}
|
||||||
IndexNumber++;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USART7_BASE)
|
#if defined(USART7_BASE)
|
||||||
|
@ -157,9 +142,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
||||||
__HAL_RCC_USART7_FORCE_RESET();
|
__HAL_RCC_USART7_FORCE_RESET();
|
||||||
__HAL_RCC_USART7_RELEASE_RESET();
|
__HAL_RCC_USART7_RELEASE_RESET();
|
||||||
__HAL_RCC_USART7_CLK_ENABLE();
|
__HAL_RCC_USART7_CLK_ENABLE();
|
||||||
obj_s->index = IndexNumber;
|
|
||||||
}
|
}
|
||||||
IndexNumber++;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART8_BASE)
|
#if defined(UART8_BASE)
|
||||||
|
@ -167,9 +150,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
||||||
__HAL_RCC_UART8_FORCE_RESET();
|
__HAL_RCC_UART8_FORCE_RESET();
|
||||||
__HAL_RCC_UART8_RELEASE_RESET();
|
__HAL_RCC_UART8_RELEASE_RESET();
|
||||||
__HAL_RCC_UART8_CLK_ENABLE();
|
__HAL_RCC_UART8_CLK_ENABLE();
|
||||||
obj_s->index = IndexNumber;
|
|
||||||
}
|
}
|
||||||
IndexNumber++;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USART8_BASE)
|
#if defined(USART8_BASE)
|
||||||
|
@ -177,9 +158,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
||||||
__HAL_RCC_USART8_FORCE_RESET();
|
__HAL_RCC_USART8_FORCE_RESET();
|
||||||
__HAL_RCC_USART8_RELEASE_RESET();
|
__HAL_RCC_USART8_RELEASE_RESET();
|
||||||
__HAL_RCC_USART8_CLK_ENABLE();
|
__HAL_RCC_USART8_CLK_ENABLE();
|
||||||
obj_s->index = IndexNumber;
|
|
||||||
}
|
}
|
||||||
IndexNumber++;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART9_BASE)
|
#if defined(UART9_BASE)
|
||||||
|
@ -187,9 +166,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
||||||
__HAL_RCC_UART9_FORCE_RESET();
|
__HAL_RCC_UART9_FORCE_RESET();
|
||||||
__HAL_RCC_UART9_RELEASE_RESET();
|
__HAL_RCC_UART9_RELEASE_RESET();
|
||||||
__HAL_RCC_UART9_CLK_ENABLE();
|
__HAL_RCC_UART9_CLK_ENABLE();
|
||||||
obj_s->index = IndexNumber;
|
|
||||||
}
|
}
|
||||||
IndexNumber++;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UART10_BASE)
|
#if defined(UART10_BASE)
|
||||||
|
@ -197,22 +174,21 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
||||||
__HAL_RCC_UART10_FORCE_RESET();
|
__HAL_RCC_UART10_FORCE_RESET();
|
||||||
__HAL_RCC_UART10_RELEASE_RESET();
|
__HAL_RCC_UART10_RELEASE_RESET();
|
||||||
__HAL_RCC_UART10_CLK_ENABLE();
|
__HAL_RCC_UART10_CLK_ENABLE();
|
||||||
obj_s->index = IndexNumber;
|
|
||||||
}
|
}
|
||||||
IndexNumber++;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined(LPUART1_BASE)
|
#if defined(LPUART1_BASE)
|
||||||
if (obj_s->uart == LPUART_1) {
|
if (obj_s->uart == LPUART_1) {
|
||||||
__HAL_RCC_LPUART1_FORCE_RESET();
|
__HAL_RCC_LPUART1_FORCE_RESET();
|
||||||
__HAL_RCC_LPUART1_RELEASE_RESET();
|
__HAL_RCC_LPUART1_RELEASE_RESET();
|
||||||
__HAL_RCC_LPUART1_CLK_ENABLE();
|
__HAL_RCC_LPUART1_CLK_ENABLE();
|
||||||
obj_s->index = IndexNumber;
|
|
||||||
}
|
}
|
||||||
IndexNumber++;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Assign serial object index
|
||||||
|
obj_s->index = get_uart_index(obj_s->uart);
|
||||||
|
MBED_ASSERT(obj_s->index >= 0);
|
||||||
|
|
||||||
// Configure UART pins
|
// Configure UART pins
|
||||||
pinmap_pinout(tx, PinMap_UART_TX);
|
pinmap_pinout(tx, PinMap_UART_TX);
|
||||||
pinmap_pinout(rx, PinMap_UART_RX);
|
pinmap_pinout(rx, PinMap_UART_RX);
|
||||||
|
@ -423,38 +399,6 @@ void serial_baud(serial_t *obj, int baudrate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_StatusTypeDef init_uart(serial_t *obj)
|
|
||||||
{
|
|
||||||
struct serial_s *obj_s = SERIAL_S(obj);
|
|
||||||
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
|
|
||||||
huart->Instance = (USART_TypeDef *)(obj_s->uart);
|
|
||||||
|
|
||||||
huart->Init.BaudRate = obj_s->baudrate;
|
|
||||||
huart->Init.WordLength = obj_s->databits;
|
|
||||||
huart->Init.StopBits = obj_s->stopbits;
|
|
||||||
huart->Init.Parity = obj_s->parity;
|
|
||||||
#if DEVICE_SERIAL_FC
|
|
||||||
huart->Init.HwFlowCtl = obj_s->hw_flow_ctl;
|
|
||||||
#else
|
|
||||||
huart->Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
||||||
#endif
|
|
||||||
huart->Init.OverSampling = UART_OVERSAMPLING_16;
|
|
||||||
huart->TxXferCount = 0;
|
|
||||||
huart->TxXferSize = 0;
|
|
||||||
huart->RxXferCount = 0;
|
|
||||||
huart->RxXferSize = 0;
|
|
||||||
|
|
||||||
if (obj_s->pin_rx == NC) {
|
|
||||||
huart->Init.Mode = UART_MODE_TX;
|
|
||||||
} else if (obj_s->pin_tx == NC) {
|
|
||||||
huart->Init.Mode = UART_MODE_RX;
|
|
||||||
} else {
|
|
||||||
huart->Init.Mode = UART_MODE_TX_RX;
|
|
||||||
}
|
|
||||||
|
|
||||||
return HAL_UART_Init(huart);
|
|
||||||
}
|
|
||||||
|
|
||||||
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits)
|
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits)
|
||||||
{
|
{
|
||||||
struct serial_s *obj_s = SERIAL_S(obj);
|
struct serial_s *obj_s = SERIAL_S(obj);
|
||||||
|
@ -550,4 +494,152 @@ void serial_break_clear(serial_t *obj)
|
||||||
(void)obj;
|
(void)obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* UTILITY FUNCTIONS
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
HAL_StatusTypeDef init_uart(serial_t *obj)
|
||||||
|
{
|
||||||
|
struct serial_s *obj_s = SERIAL_S(obj);
|
||||||
|
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
|
||||||
|
huart->Instance = (USART_TypeDef *)(obj_s->uart);
|
||||||
|
|
||||||
|
huart->Init.BaudRate = obj_s->baudrate;
|
||||||
|
huart->Init.WordLength = obj_s->databits;
|
||||||
|
huart->Init.StopBits = obj_s->stopbits;
|
||||||
|
huart->Init.Parity = obj_s->parity;
|
||||||
|
#if DEVICE_SERIAL_FC
|
||||||
|
huart->Init.HwFlowCtl = obj_s->hw_flow_ctl;
|
||||||
|
#else
|
||||||
|
huart->Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||||
|
#endif
|
||||||
|
huart->Init.OverSampling = UART_OVERSAMPLING_16;
|
||||||
|
huart->TxXferCount = 0;
|
||||||
|
huart->TxXferSize = 0;
|
||||||
|
huart->RxXferCount = 0;
|
||||||
|
huart->RxXferSize = 0;
|
||||||
|
|
||||||
|
if (obj_s->pin_rx == NC) {
|
||||||
|
huart->Init.Mode = UART_MODE_TX;
|
||||||
|
} else if (obj_s->pin_tx == NC) {
|
||||||
|
huart->Init.Mode = UART_MODE_RX;
|
||||||
|
} else {
|
||||||
|
huart->Init.Mode = UART_MODE_TX_RX;
|
||||||
|
}
|
||||||
|
|
||||||
|
return HAL_UART_Init(huart);
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t get_uart_index(UARTName uart_name)
|
||||||
|
{
|
||||||
|
uint8_t index = 0;
|
||||||
|
|
||||||
|
#if defined(USART1_BASE)
|
||||||
|
if (uart_name == UART_1) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART2_BASE)
|
||||||
|
if (uart_name == UART_2) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART3_BASE)
|
||||||
|
if (uart_name == UART_3) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(UART4_BASE)
|
||||||
|
if (uart_name == UART_4) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART4_BASE)
|
||||||
|
if (uart_name == UART_4) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(UART5_BASE)
|
||||||
|
if (uart_name == UART_5) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART5_BASE)
|
||||||
|
if (uart_name == UART_5) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART6_BASE)
|
||||||
|
if (uart_name == UART_6) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(UART7_BASE)
|
||||||
|
if (uart_name == UART_7) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART7_BASE)
|
||||||
|
if (uart_name == UART_7) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(UART8_BASE)
|
||||||
|
if (uart_name == UART_8) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USART8_BASE)
|
||||||
|
if (uart_name == UART_8) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(UART9_BASE)
|
||||||
|
if (uart_name == UART_9) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(UART10_BASE)
|
||||||
|
if (uart_name == UART_10) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(LPUART1_BASE)
|
||||||
|
if (uart_name == LPUART_1) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* DEVICE_SERIAL */
|
#endif /* DEVICE_SERIAL */
|
||||||
|
|
Loading…
Reference in New Issue