diff --git a/targets/TARGET_STM/TARGET_STM32F1/serial_device.c b/targets/TARGET_STM/TARGET_STM32F1/serial_device.c index eb7a66b7063..6902da9672c 100644 --- a/targets/TARGET_STM/TARGET_STM32F1/serial_device.c +++ b/targets/TARGET_STM/TARGET_STM32F1/serial_device.c @@ -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]; @@ -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); @@ -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); @@ -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;