Skip to content

Add more uarts for STM32F103xG #14976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F1/serial_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@

#include "serial_api_hal.h"

#if defined(TARGET_STM32F103xG)
#define UART_NUM (5)
#else
#define UART_NUM (3)
#endif

uint32_t serial_irq_ids[UART_NUM] = {0};
UART_HandleTypeDef uart_handlers[UART_NUM];
Expand Down Expand Up @@ -94,6 +98,20 @@ static void uart3_irq(void)
}
#endif

#if defined(USART4_BASE)
static void uart4_irq(void)
{
uart_irq(UART_4);
}
#endif

#if defined(USART5_BASE)
static void uart5_irq(void)
{
uart_irq(UART_5);
}
#endif

void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
{
struct serial_s *obj_s = SERIAL_S(obj);
Expand Down Expand Up @@ -130,6 +148,20 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
}
#endif

#if defined(USART4_BASE)
if (obj_s->uart == UART_4) {
irq_n = USART4_IRQn;
vector = (uint32_t)&uart4_irq;
}
#endif

#if defined(USART5_BASE)
if (obj_s->uart == UART_5) {
irq_n = USART5_IRQn;
vector = (uint32_t)&uart5_irq;
}
#endif

if (enable) {
if (irq == RxIrq) {
__HAL_UART_ENABLE_IT(huart, UART_IT_RXNE);
Expand Down Expand Up @@ -302,6 +334,16 @@ static IRQn_Type serial_get_irq_n(UARTName uart_name)
case UART_3:
irq_n = USART3_IRQn;
break;
#endif
#if defined(USART4_BASE)
case UART_4:
irq_n = USART4_IRQn;
break;
#endif
#if defined(USART5_BASE)
case UART_5:
irq_n = USART5_IRQn;
break;
#endif
default:
irq_n = (IRQn_Type)0;
Expand Down