diff --git a/os/hal/ports/AT32/LLD/USARTv2/hal_serial_lld.c b/os/hal/ports/AT32/LLD/USARTv2/hal_serial_lld.c index 6363aa9be0..ecfbc5fb2b 100644 --- a/os/hal/ports/AT32/LLD/USARTv2/hal_serial_lld.c +++ b/os/hal/ports/AT32/LLD/USARTv2/hal_serial_lld.c @@ -62,6 +62,21 @@ SerialDriver SD4; SerialDriver SD5; #endif +/** @brief USART6 serial driver identifier.*/ +#if AT32_SERIAL_USE_USART6 || defined(__DOXYGEN__) +SerialDriver SD6; +#endif + +/** @brief UART7 serial driver identifier.*/ +#if AT32_SERIAL_USE_UART7 || defined(__DOXYGEN__) +SerialDriver SD7; +#endif + +/** @brief UART8 serial driver identifier.*/ +#if AT32_SERIAL_USE_UART8 || defined(__DOXYGEN__) +SerialDriver SD8; +#endif + /*===========================================================================*/ /* Driver local variables and types. */ /*===========================================================================*/ @@ -189,6 +204,30 @@ static void notify5(io_queue_t *qp) { } #endif +#if AT32_SERIAL_USE_USART6 || defined(__DOXYGEN__) +static void notify6(io_queue_t *qp) { + + (void)qp; + USART6->CTRL1 |= USART_CTRL1_TDBEIEN | USART_CTRL1_TDCIEN; +} +#endif + +#if AT32_SERIAL_USE_UART7 || defined(__DOXYGEN__) +static void notify7(io_queue_t *qp) { + + (void)qp; + UART7->CTRL1 |= USART_CTRL1_TDBEIEN | USART_CTRL1_TDCIEN; +} +#endif + +#if AT32_SERIAL_USE_UART8 || defined(__DOXYGEN__) +static void notify8(io_queue_t *qp) { + + (void)qp; + UART8->CTRL1 |= USART_CTRL1_TDBEIEN | USART_CTRL1_TDCIEN; +} +#endif + /*===========================================================================*/ /* Driver interrupt handlers. */ /*===========================================================================*/ @@ -298,6 +337,69 @@ OSAL_IRQ_HANDLER(AT32_UART5_HANDLER) { #endif #endif +#if AT32_SERIAL_USE_USART6 || defined(__DOXYGEN__) +#if !defined(AT32_USART6_SUPPRESS_ISR) +#if !defined(AT32_USART6_HANDLER) +#error "AT32_USART6_HANDLER not defined" +#endif +/** + * @brief USART6 interrupt handler. + * + * @isr + */ +OSAL_IRQ_HANDLER(AT32_USART6_HANDLER) { + + OSAL_IRQ_PROLOGUE(); + + sd_lld_serve_interrupt(&SD6); + + OSAL_IRQ_EPILOGUE(); +} +#endif +#endif + +#if AT32_SERIAL_USE_UART7 || defined(__DOXYGEN__) +#if !defined(AT32_UART7_SUPPRESS_ISR) +#if !defined(AT32_UART7_HANDLER) +#error "AT32_UART7_HANDLER not defined" +#endif +/** + * @brief UART7 interrupt handler. + * + * @isr + */ +OSAL_IRQ_HANDLER(AT32_UART7_HANDLER) { + + OSAL_IRQ_PROLOGUE(); + + sd_lld_serve_interrupt(&SD7); + + OSAL_IRQ_EPILOGUE(); +} +#endif +#endif + +#if AT32_SERIAL_USE_UART8 || defined(__DOXYGEN__) +#if !defined(AT32_UART8_SUPPRESS_ISR) +#if !defined(AT32_UART8_HANDLER) +#error "AT32_UART8_HANDLER not defined" +#endif +/** + * @brief UART8 interrupt handler. + * + * @isr + */ +OSAL_IRQ_HANDLER(AT32_UART8_HANDLER) { + + OSAL_IRQ_PROLOGUE(); + + sd_lld_serve_interrupt(&SD8); + + OSAL_IRQ_EPILOGUE(); +} +#endif +#endif + /*===========================================================================*/ /* Driver exported functions. */ /*===========================================================================*/ @@ -353,6 +455,34 @@ void sd_lld_init(void) { nvicEnableVector(AT32_UART5_NUMBER, AT32_SERIAL_UART5_PRIORITY); #endif #endif + +#if AT32_SERIAL_USE_USART6 + sdObjectInit(&SD6, NULL, notify3); + SD6.usart = USART6; + SD6.clock = AT32_PCLK2; +#if !defined(AT32_USART6_SUPPRESS_ISR) && defined(AT32_USART6_NUMBER) + nvicEnableVector(AT32_USART6_NUMBER, AT32_SERIAL_USART6_PRIORITY); +#endif +#endif + +#if AT32_SERIAL_USE_UART7 + sdObjectInit(&SD7, NULL, notify4); + SD7.usart = UART7; + SD7.clock = AT32_PCLK1; +#if !defined(AT32_UART7_SUPPRESS_ISR) && defined(AT32_UART7_NUMBER) + nvicEnableVector(AT32_UART7_NUMBER, AT32_SERIAL_UART7_PRIORITY); +#endif +#endif + +#if AT32_SERIAL_USE_UART8 + sdObjectInit(&SD8, NULL, notify5); + SD8.usart = UART8; + SD8.clock = AT32_PCLK1; +#if !defined(AT32_UART8_SUPPRESS_ISR) && defined(AT32_UART8_NUMBER) + nvicEnableVector(AT32_UART8_NUMBER, AT32_SERIAL_UART8_PRIORITY); +#endif +#endif + } /** @@ -395,6 +525,21 @@ void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) { if (&SD5 == sdp) { crmEnableUART5(true); } +#endif +#if AT32_SERIAL_USE_USART6 + if (&SD6 == sdp) { + crmEnableUSART6(true); + } +#endif +#if AT32_SERIAL_USE_UART7 + if (&SD7 == sdp) { + crmEnableUART7(true); + } +#endif +#if AT32_SERIAL_USE_UART8 + if (&SD8 == sdp) { + crmEnableUART8(true); + } #endif } usart_init(sdp, config); @@ -442,6 +587,24 @@ void sd_lld_stop(SerialDriver *sdp) { crmDisableUART5(); return; } +#endif +#if AT32_SERIAL_USE_USART6 + if (&SD6 == sdp) { + crmDisableUSART6(); + return; + } +#endif +#if AT32_SERIAL_USE_UART7 + if (&SD7 == sdp) { + crmDisableUART7(); + return; + } +#endif +#if AT32_SERIAL_USE_UART8 + if (&SD8 == sdp) { + crmDisableUART8(); + return; + } #endif } } diff --git a/os/hal/ports/AT32/LLD/USARTv2/hal_serial_lld.h b/os/hal/ports/AT32/LLD/USARTv2/hal_serial_lld.h index 1deba135c5..86998e70cd 100644 --- a/os/hal/ports/AT32/LLD/USARTv2/hal_serial_lld.h +++ b/os/hal/ports/AT32/LLD/USARTv2/hal_serial_lld.h @@ -87,6 +87,33 @@ #define AT32_SERIAL_USE_UART5 FALSE #endif +/** + * @brief USART6 driver enable switch. + * @details If set to @p TRUE the support for USART6 is included. + * @note The default is @p FALSE. + */ +#if !defined(AT32_SERIAL_USE_USART6) || defined(__DOXYGEN__) +#define AT32_SERIAL_USE_USART6 FALSE +#endif + +/** + * @brief UART7 driver enable switch. + * @details If set to @p TRUE the support for UART7 is included. + * @note The default is @p FALSE. + */ +#if !defined(AT32_SERIAL_USE_UART7) || defined(__DOXYGEN__) +#define AT32_SERIAL_USE_UART7 FALSE +#endif + +/** + * @brief UART8 driver enable switch. + * @details If set to @p TRUE the support for UART8 is included. + * @note The default is @p FALSE. + */ +#if !defined(AT32_SERIAL_USE_UART8) || defined(__DOXYGEN__) +#define AT32_SERIAL_USE_UART8 FALSE +#endif + /** * @brief USART1 interrupt priority level setting. */ @@ -121,6 +148,28 @@ #if !defined(AT32_SERIAL_UART5_PRIORITY) || defined(__DOXYGEN__) #define AT32_SERIAL_UART5_PRIORITY 12 #endif + +/** + * @brief USART6 interrupt priority level setting. + */ +#if !defined(AT32_SERIAL_USART6_PRIORITY) || defined(__DOXYGEN__) +#define AT32_SERIAL_USART6_PRIORITY 12 +#endif + +/** + * @brief UART7 interrupt priority level setting. + */ +#if !defined(AT32_SERIAL_UART7_PRIORITY) || defined(__DOXYGEN__) +#define AT32_SERIAL_UART7_PRIORITY 12 +#endif + +/** + * @brief UART8 interrupt priority level setting. + */ +#if !defined(AT32_SERIAL_UART8_PRIORITY) || defined(__DOXYGEN__) +#define AT32_SERIAL_UART8_PRIORITY 12 +#endif + /** @} */ /*===========================================================================*/ @@ -147,9 +196,22 @@ #error "UART5 not present in the selected device" #endif +#if AT32_SERIAL_USE_USART6 && !AT32_HAS_USART6 +#error "USART6 not present in the selected device" +#endif + +#if AT32_SERIAL_USE_UART7 && !AT32_HAS_UART7 +#error "UART7 not present in the selected device" +#endif + +#if AT32_SERIAL_USE_UART8 && !AT32_HAS_UART8 +#error "UART8 not present in the selected device" +#endif + #if !AT32_SERIAL_USE_USART1 && !AT32_SERIAL_USE_USART2 && \ !AT32_SERIAL_USE_USART3 && !AT32_SERIAL_USE_UART4 && \ - !AT32_SERIAL_USE_UART5 + !AT32_SERIAL_USE_UART5 && !AT32_SERIAL_USE_USART6 && \ + !AT32_SERIAL_USE_UART7 && !AT32_SERIAL_USE_UART8 #error "SERIAL driver activated but no USART/UART peripheral assigned" #endif @@ -178,6 +240,21 @@ #error "Invalid IRQ priority assigned to UART5" #endif +#if AT32_SERIAL_USE_USART6 && \ + !OSAL_IRQ_IS_VALID_PRIORITY(AT32_SERIAL_USART6_PRIORITY) +#error "Invalid IRQ priority assigned to USART6" +#endif + +#if AT32_SERIAL_USE_UART7 && \ + !OSAL_IRQ_IS_VALID_PRIORITY(AT32_SERIAL_UART7_PRIORITY) +#error "Invalid IRQ priority assigned to UART7" +#endif + +#if AT32_SERIAL_USE_UART8 && \ + !OSAL_IRQ_IS_VALID_PRIORITY(AT32_SERIAL_UART8_PRIORITY) +#error "Invalid IRQ priority assigned to UART8" +#endif + /* Checks on allocation of USARTx units.*/ #if AT32_SERIAL_USE_USART1 #if defined(AT32_USART1_IS_USED) @@ -219,6 +296,30 @@ #endif #endif +#if AT32_SERIAL_USE_USART6 +#if defined(AT32_USART6_IS_USED) +#error "SD6 requires USART6 but it is already used" +#else +#define AT32_USART6_IS_USED +#endif +#endif + +#if AT32_SERIAL_USE_UART7 +#if defined(AT32_UART7_IS_USED) +#error "SD7 requires UART7 but it is already used" +#else +#define AT32_UART7_IS_USED +#endif +#endif + +#if AT32_SERIAL_USE_UART8 +#if defined(AT32_UART8_IS_USED) +#error "SD8 requires UART8 but it is already used" +#else +#define AT32_UART8_IS_USED +#endif +#endif + /*===========================================================================*/ /* Driver data structures and types. */ /*===========================================================================*/ @@ -305,6 +406,15 @@ extern SerialDriver SD4; #if AT32_SERIAL_USE_UART5 && !defined(__DOXYGEN__) extern SerialDriver SD5; #endif +#if AT32_SERIAL_USE_USART6 && !defined(__DOXYGEN__) +extern SerialDriver SD6; +#endif +#if AT32_SERIAL_USE_UART7 && !defined(__DOXYGEN__) +extern SerialDriver SD7; +#endif +#if AT32_SERIAL_USE_UART8 && !defined(__DOXYGEN__) +extern SerialDriver SD8; +#endif #ifdef __cplusplus extern "C" { diff --git a/os/hal/ports/AT32/LLD/USARTv2/hal_uart_lld.c b/os/hal/ports/AT32/LLD/USARTv2/hal_uart_lld.c index 1e6f3533b4..a8c507490c 100644 --- a/os/hal/ports/AT32/LLD/USARTv2/hal_uart_lld.c +++ b/os/hal/ports/AT32/LLD/USARTv2/hal_uart_lld.c @@ -70,6 +70,21 @@ UARTDriver UARTD4; UARTDriver UARTD5; #endif +/** @brief USART6 UART driver identifier.*/ +#if AT32_UART_USE_USART6 || defined(__DOXYGEN__) +UARTDriver UARTD6; +#endif + +/** @brief UART7 UART driver identifier.*/ +#if AT32_UART_USE_UART7 || defined(__DOXYGEN__) +UARTDriver UARTD7; +#endif + +/** @brief UART8 UART driver identifier.*/ +#if AT32_UART_USE_UART8 || defined(__DOXYGEN__) +UARTDriver UARTD8; +#endif + /*===========================================================================*/ /* Driver local variables and types. */ /*===========================================================================*/ @@ -339,6 +354,69 @@ OSAL_IRQ_HANDLER(AT32_UART5_HANDLER) { #endif #endif /* AT32_UART_USE_UART5 */ +#if AT32_UART_USE_USART6 || defined(__DOXYGEN__) +#if !defined(AT32_USART6_SUPPRESS_ISR) +#if !defined(AT32_USART6_HANDLER) +#error "AT32_USART6_HANDLER not defined" +#endif +/** + * @brief USART6 IRQ handler. + * + * @isr + */ +OSAL_IRQ_HANDLER(AT32_USART6_HANDLER) { + + OSAL_IRQ_PROLOGUE(); + + uart_lld_serve_interrupt(&UARTD6); + + OSAL_IRQ_EPILOGUE(); +} +#endif +#endif /* AT32_UART_USE_USART6 */ + +#if AT32_UART_USE_UART7 || defined(__DOXYGEN__) +#if !defined(AT32_UART7_SUPPRESS_ISR) +#if !defined(AT32_UART7_HANDLER) +#error "AT32_UART7_HANDLER not defined" +#endif +/** + * @brief UART7 IRQ handler. + * + * @isr + */ +OSAL_IRQ_HANDLER(AT32_UART7_HANDLER) { + + OSAL_IRQ_PROLOGUE(); + + uart_lld_serve_interrupt(&UARTD7); + + OSAL_IRQ_EPILOGUE(); +} +#endif +#endif /* AT32_UART_USE_UART7 */ + +#if AT32_UART_USE_UART8 || defined(__DOXYGEN__) +#if !defined(AT32_UART8_SUPPRESS_ISR) +#if !defined(AT32_UART8_HANDLER) +#error "AT32_UART8_HANDLER not defined" +#endif +/** + * @brief UART5 IRQ handler. + * + * @isr + */ +OSAL_IRQ_HANDLER(AT32_UART8_HANDLER) { + + OSAL_IRQ_PROLOGUE(); + + uart_lld_serve_interrupt(&UARTD8); + + OSAL_IRQ_EPILOGUE(); +} +#endif +#endif /* AT32_UART_USE_UART5 */ + /*===========================================================================*/ /* Driver exported functions. */ /*===========================================================================*/ @@ -399,6 +477,36 @@ void uart_lld_init(void) { UARTD5.dmarx = NULL; UARTD5.dmatx = NULL; #endif + +#if AT32_UART_USE_USART6 + uartObjectInit(&UARTD6); + UARTD6.usart = USART6; + UARTD6.clock = AT32_PCLK2; + UARTD6.dmarxmode = AT32_DMA_CCTRL_DTERRIEN; + UARTD6.dmatxmode = AT32_DMA_CCTRL_DTERRIEN; + UARTD6.dmarx = NULL; + UARTD6.dmatx = NULL; +#endif + +#if AT32_UART_USE_UART7 + uartObjectInit(&UARTD7); + UARTD7.usart = UART7; + UARTD7.clock = AT32_PCLK1; + UARTD7.dmarxmode = AT32_DMA_CCTRL_DTERRIEN; + UARTD7.dmatxmode = AT32_DMA_CCTRL_DTERRIEN; + UARTD7.dmarx = NULL; + UARTD7.dmatx = NULL; +#endif + +#if AT32_UART_USE_UART8 + uartObjectInit(&UARTD8); + UARTD8.usart = UART8; + UARTD8.clock = AT32_PCLK1; + UARTD8.dmarxmode = AT32_DMA_CCTRL_DTERRIEN; + UARTD8.dmatxmode = AT32_DMA_CCTRL_DTERRIEN; + UARTD8.dmarx = NULL; + UARTD8.dmatx = NULL; +#endif } /** @@ -548,6 +656,93 @@ void uart_lld_start(UARTDriver *uartp) { } #endif +#if AT32_UART_USE_USART6 + if (&UARTD6 == uartp) { + uartp->dmarx = dmaStreamAllocI(AT32_UART_USART6_RX_DMA_STREAM, + AT32_UART_USART6_IRQ_PRIORITY, + (at32_dmasts_t)uart_lld_serve_rx_end_irq, + (void *)uartp); + osalDbgAssert(uartp->dmarx != NULL, "unable to allocate stream"); + uartp->dmatx = dmaStreamAllocI(AT32_UART_USART6_TX_DMA_STREAM, + AT32_UART_USART6_IRQ_PRIORITY, + (at32_dmasts_t)uart_lld_serve_tx_end_irq, + (void *)uartp); + osalDbgAssert(uartp->dmatx != NULL, "unable to allocate stream"); + +#if AT32_DMA_SUPPORTS_DMAMUX + dmaSetRequestSource(uartp->dmarx, AT32_DMAMUX_USART6_RX); + dmaSetRequestSource(uartp->dmatx, AT32_DMAMUX_USART6_TX); +#endif + + crmEnableUSART6(true); + nvicEnableVector(AT32_USART6_NUMBER, AT32_UART_USART6_IRQ_PRIORITY); + uartp->dmarxmode |= AT32_DMA_CCTRL_CHPL(AT32_UART_USART6_DMA_PRIORITY); + uartp->dmatxmode |= AT32_DMA_CCTRL_CHPL(AT32_UART_USART6_DMA_PRIORITY); + } +#endif + +#if AT32_UART_USE_UART7 + if (&UARTD7 == uartp) { + + osalDbgAssert((uartp->config->ctrl2 & AT32_UART_CTRL2_CHECK_MASK) == 0, + "specified invalid bits in UART7 CTRL2 register settings"); + osalDbgAssert((uartp->config->ctrl3 & AT32_UART_CTRL3_CHECK_MASK) == 0, + "specified invalid bits in UART7 CTRL3 register settings"); + + uartp->dmarx = dmaStreamAllocI(AT32_UART_UART7_RX_DMA_STREAM, + AT32_UART_UART7_IRQ_PRIORITY, + (at32_dmasts_t)uart_lld_serve_rx_end_irq, + (void *)uartp); + osalDbgAssert(uartp->dmarx != NULL, "unable to allocate stream"); + uartp->dmatx = dmaStreamAllocI(AT32_UART_UART7_TX_DMA_STREAM, + AT32_UART_UART7_IRQ_PRIORITY, + (at32_dmasts_t)uart_lld_serve_tx_end_irq, + (void *)uartp); + osalDbgAssert(uartp->dmatx != NULL, "unable to allocate stream"); + +#if AT32_DMA_SUPPORTS_DMAMUX + dmaSetRequestSource(uartp->dmarx, AT32_DMAMUX_UART7_RX); + dmaSetRequestSource(uartp->dmatx, AT32_DMAMUX_UART7_TX); +#endif + + crmEnableUART7(true); + nvicEnableVector(AT32_UART7_NUMBER, AT32_UART_UART7_IRQ_PRIORITY); + uartp->dmarxmode |= AT32_DMA_CCTRL_CHPL(AT32_UART_UART7_DMA_PRIORITY); + uartp->dmatxmode |= AT32_DMA_CCTRL_CHPL(AT32_UART_UART7_DMA_PRIORITY); + } +#endif + +#if AT32_UART_USE_UART8 + if (&UARTD8 == uartp) { + + osalDbgAssert((uartp->config->ctrl2 & AT32_UART_CTRL2_CHECK_MASK) == 0, + "specified invalid bits in UART8 CTRL2 register settings"); + osalDbgAssert((uartp->config->ctrl3 & AT32_UART_CTRL3_CHECK_MASK) == 0, + "specified invalid bits in UART8 CTRL3 register settings"); + + uartp->dmarx = dmaStreamAllocI(AT32_UART_UART8_RX_DMA_STREAM, + AT32_UART_UART8_IRQ_PRIORITY, + (at32_dmasts_t)uart_lld_serve_rx_end_irq, + (void *)uartp); + osalDbgAssert(uartp->dmarx != NULL, "unable to allocate stream"); + uartp->dmatx = dmaStreamAllocI(AT32_UART_UART8_TX_DMA_STREAM, + AT32_UART_UART8_IRQ_PRIORITY, + (at32_dmasts_t)uart_lld_serve_tx_end_irq, + (void *)uartp); + osalDbgAssert(uartp->dmatx != NULL, "unable to allocate stream"); + +#if AT32_DMA_SUPPORTS_DMAMUX + dmaSetRequestSource(uartp->dmarx, AT32_DMAMUX_UART8_RX); + dmaSetRequestSource(uartp->dmatx, AT32_DMAMUX_UART8_TX); +#endif + + crmEnableUART8(true); + nvicEnableVector(AT32_UART5_NUMBER, AT32_UART_UART8_IRQ_PRIORITY); + uartp->dmarxmode |= AT32_DMA_CCTRL_CHPL(AT32_UART_UART8_DMA_PRIORITY); + uartp->dmatxmode |= AT32_DMA_CCTRL_CHPL(AT32_UART_UART8_DMA_PRIORITY); + } +#endif + /* Static DMA setup, the transfer size depends on the USART settings, it is 16 bits if M=1 and PEN=0 else it is 8 bits.*/ if ((uartp->config->ctrl1 & (USART_CTRL1_DBN | USART_CTRL1_PEN)) == USART_CTRL1_DBN) { @@ -619,6 +814,31 @@ void uart_lld_stop(UARTDriver *uartp) { return; } #endif + +#if AT32_UART_USE_USART6 + if (&UARTD6 == uartp) { + nvicDisableVector(AT32_USART6_NUMBER); + crmDisableUSART6(); + return; + } +#endif + +#if AT32_UART_USE_UART7 + if (&UARTD7 == uartp) { + nvicDisableVector(AT32_UART7_NUMBER); + crmDisableUART7(); + return; + } +#endif + +#if AT32_UART_USE_UART8 + if (&UARTD8 == uartp) { + nvicDisableVector(AT32_UART8_NUMBER); + crmDisableUART8(); + return; + } +#endif + } } diff --git a/os/hal/ports/AT32/LLD/USARTv2/hal_uart_lld.h b/os/hal/ports/AT32/LLD/USARTv2/hal_uart_lld.h index cd1edb4f3c..4c808717cd 100644 --- a/os/hal/ports/AT32/LLD/USARTv2/hal_uart_lld.h +++ b/os/hal/ports/AT32/LLD/USARTv2/hal_uart_lld.h @@ -87,6 +87,33 @@ #define AT32_UART_USE_UART5 FALSE #endif +/** + * @brief UART driver on USART6 enable switch. + * @details If set to @p TRUE the support for USART6 is included. + * @note The default is @p FALSE. + */ +#if !defined(AT32_UART_USE_USART6) || defined(__DOXYGEN__) +#define AT32_UART_USE_USART6 FALSE +#endif + +/** + * @brief UART driver on UART7 enable switch. + * @details If set to @p TRUE the support for UART7 is included. + * @note The default is @p FALSE. + */ +#if !defined(AT32_UART_USE_UART7) || defined(__DOXYGEN__) +#define AT32_UART_USE_UART7 FALSE +#endif + +/** + * @brief UART driver on UART8 enable switch. + * @details If set to @p TRUE the support for UART8 is included. + * @note The default is @p FALSE. + */ +#if !defined(AT32_UART_USE_UART8) || defined(__DOXYGEN__) +#define AT32_UART_USE_UART8 FALSE +#endif + /** * @brief USART1 interrupt priority level setting. */ @@ -122,6 +149,27 @@ #define AT32_UART_UART5_IRQ_PRIORITY 12 #endif +/** + * @brief USART6 interrupt priority level setting. + */ +#if !defined(AT32_UART_USART6_IRQ_PRIORITY) || defined(__DOXYGEN__) +#define AT32_UART_USART6_IRQ_PRIORITY 12 +#endif + +/** + * @brief UART7 interrupt priority level setting. + */ +#if !defined(AT32_UART_UART7_IRQ_PRIORITY) || defined(__DOXYGEN__) +#define AT32_UART_UART7_IRQ_PRIORITY 12 +#endif + +/** + * @brief UART8 interrupt priority level setting. + */ +#if !defined(AT32_UART_UART8_IRQ_PRIORITY) || defined(__DOXYGEN__) +#define AT32_UART_UART8_IRQ_PRIORITY 12 +#endif + /** * @brief USART1 DMA priority (0..3|lowest..highest). * @note The priority level is used for both the TX and RX DMA channels but @@ -172,6 +220,36 @@ #define AT32_UART_UART5_DMA_PRIORITY 0 #endif +/** + * @brief USART6 DMA priority (0..3|lowest..highest). + * @note The priority level is used for both the TX and RX DMA channels but + * because of the channels ordering the RX channel has always priority + * over the TX channel. + */ +#if !defined(AT32_UART_USART6_DMA_PRIORITY) || defined(__DOXYGEN__) +#define AT32_UART_USART6_DMA_PRIORITY 0 +#endif + +/** + * @brief UART7 DMA priority (0..3|lowest..highest). + * @note The priority level is used for both the TX and RX DMA channels but + * because of the channels ordering the RX channel has always priority + * over the TX channel. + */ +#if !defined(AT32_UART_UART7_DMA_PRIORITY) || defined(__DOXYGEN__) +#define AT32_UART_UART7_DMA_PRIORITY 0 +#endif + +/** + * @brief UART8 DMA priority (0..3|lowest..highest). + * @note The priority level is used for both the TX and RX DMA channels but + * because of the channels ordering the RX channel has always priority + * over the TX channel. + */ +#if !defined(AT32_UART_UART8_DMA_PRIORITY) || defined(__DOXYGEN__) +#define AT32_UART_UART8_DMA_PRIORITY 0 +#endif + /** * @brief USART DMA error hook. * @note The default action for DMA errors is a system halt because DMA @@ -206,9 +284,22 @@ #error "UART5 not present in the selected device" #endif +#if AT32_UART_USE_USART6 && !AT32_HAS_USART6 +#error "USART6 not present in the selected device" +#endif + +#if AT32_UART_USE_UART7 && !AT32_HAS_UART7 +#error "UART7 not present in the selected device" +#endif + +#if AT32_UART_USE_UART8 && !AT32_HAS_UART8 +#error "UART8 not present in the selected device" +#endif + #if !AT32_UART_USE_USART1 && !AT32_UART_USE_USART2 && \ !AT32_UART_USE_USART3 && !AT32_UART_USE_UART4 && \ - !AT32_UART_USE_UART5 + !AT32_UART_USE_UART5 && !AT32_UART_USE_USART6 && \ + !AT32_UART_USE_UART7 && !AT32_UART_USE_UART8 #error "UART driver activated but no USART/UART peripheral assigned" #endif @@ -237,6 +328,21 @@ #error "Invalid IRQ priority assigned to UART5" #endif +#if AT32_UART_USE_USART6 && \ + !OSAL_IRQ_IS_VALID_PRIORITY(AT32_UART_USART6_IRQ_PRIORITY) +#error "Invalid IRQ priority assigned to USART6" +#endif + +#if AT32_UART_USE_UART7 && \ + !OSAL_IRQ_IS_VALID_PRIORITY(AT32_UART_UART7_IRQ_PRIORITY) +#error "Invalid IRQ priority assigned to UART7" +#endif + +#if AT32_UART_USE_UART8 && \ + !OSAL_IRQ_IS_VALID_PRIORITY(AT32_UART_UART8_IRQ_PRIORITY) +#error "Invalid IRQ priority assigned to UART8" +#endif + #if AT32_UART_USE_USART1 && \ !AT32_DMA_IS_VALID_PRIORITY(AT32_UART_USART1_DMA_PRIORITY) #error "Invalid DMA priority assigned to USART1" @@ -262,6 +368,21 @@ #error "Invalid DMA priority assigned to UART5" #endif +#if AT32_UART_USE_USART6 && \ + !AT32_DMA_IS_VALID_PRIORITY(AT32_UART_USART6_DMA_PRIORITY) +#error "Invalid DMA priority assigned to USART6" +#endif + +#if AT32_UART_USE_UART7 && \ + !AT32_DMA_IS_VALID_PRIORITY(AT32_UART_UART7_DMA_PRIORITY) +#error "Invalid DMA priority assigned to UART7" +#endif + +#if AT32_UART_USE_UART8 && \ + !AT32_DMA_IS_VALID_PRIORITY(AT32_UART_UART8_DMA_PRIORITY) +#error "Invalid DMA priority assigned to UART8" +#endif + #if !defined(AT32_DMA_REQUIRED) #define AT32_DMA_REQUIRED #endif @@ -307,6 +428,30 @@ #endif #endif +#if AT32_UART_USE_USART6 +#if defined(AT32_USART6_IS_USED) +#error "UARTD6 requires USART6 but it is already used" +#else +#define AT32_USART6_IS_USED +#endif +#endif + +#if AT32_UART_USE_UART7 +#if defined(AT32_UART7_IS_USED) +#error "UARTD7 requires UART7 but it is already used" +#else +#define AT32_UART7_IS_USED +#endif +#endif + +#if AT32_UART_USE_UART8 +#if defined(AT32_UART8_IS_USED) +#error "UARTD8 requires UART8 but it is already used" +#else +#define AT32_UART8_IS_USED +#endif +#endif + /*===========================================================================*/ /* Driver data structures and types. */ /*===========================================================================*/ @@ -496,6 +641,18 @@ extern UARTDriver UARTD4; extern UARTDriver UARTD5; #endif +#if AT32_UART_USE_USART6 && !defined(__DOXYGEN__) +extern UARTDriver UARTD6; +#endif + +#if AT32_UART_USE_UART7 && !defined(__DOXYGEN__) +extern UARTDriver UARTD7; +#endif + +#if AT32_UART_USE_UART8 && !defined(__DOXYGEN__) +extern UARTDriver UARTD8; +#endif + #ifdef __cplusplus extern "C" { #endif