diff options
Diffstat (limited to 'os')
| -rw-r--r-- | os/hal/platforms/STM32/USARTv1/uart_lld.c | 69 | ||||
| -rw-r--r-- | os/hal/platforms/STM32/USARTv1/uart_lld.h | 74 | 
2 files changed, 142 insertions, 1 deletions
| diff --git a/os/hal/platforms/STM32/USARTv1/uart_lld.c b/os/hal/platforms/STM32/USARTv1/uart_lld.c index 03648585a..01c5627ac 100644 --- a/os/hal/platforms/STM32/USARTv1/uart_lld.c +++ b/os/hal/platforms/STM32/USARTv1/uart_lld.c @@ -59,6 +59,14 @@    STM32_DMA_GETCHANNEL(STM32_UART_USART3_TX_DMA_STREAM,                     \
                         STM32_USART3_TX_DMA_CHN)
 +#define USART6_RX_DMA_CHANNEL                                               \
 +  STM32_DMA_GETCHANNEL(STM32_UART_USART6_RX_DMA_STREAM,                     \
 +                       STM32_USART6_RX_DMA_CHN)
 +
 +#define USART6_TX_DMA_CHANNEL                                               \
 +  STM32_DMA_GETCHANNEL(STM32_UART_USART6_TX_DMA_STREAM,                     \
 +                       STM32_USART6_TX_DMA_CHN)
 +
  /*===========================================================================*/
  /* Driver exported variables.                                                */
  /*===========================================================================*/
 @@ -78,6 +86,12 @@ UARTDriver UARTD2;  UARTDriver UARTD3;
  #endif
 +
 +/** @brief USART6 UART driver identifier.*/
 +#if STM32_UART_USE_USART6 || defined(__DOXYGEN__)
 +UARTDriver UARTD6;
 +#endif
 +
  /*===========================================================================*/
  /* Driver local variables.                                                   */
  /*===========================================================================*/
 @@ -344,6 +358,25 @@ CH_IRQ_HANDLER(STM32_USART3_HANDLER) {  }
  #endif /* STM32_UART_USE_USART3 */
 +#if STM32_UART_USE_USART6 || defined(__DOXYGEN__)
 +#if !defined(STM32_USART6_HANDLER)
 +#error "STM32_USART6_HANDLER not defined"
 +#endif
 +/**
 + * @brief   USART6 IRQ handler.
 + *
 + * @isr
 + */
 +CH_IRQ_HANDLER(STM32_USART6_HANDLER) {
 +
 +  CH_IRQ_PROLOGUE();
 +
 +  serve_usart_irq(&UARTD6);
 +
 +  CH_IRQ_EPILOGUE();
 +}
 +#endif /* STM32_UART_USE_USART6 */
 +
  /*===========================================================================*/
  /* Driver exported functions.                                                */
  /*===========================================================================*/
 @@ -375,6 +408,13 @@ void uart_lld_init(void) {    UARTD3.dmarx   = STM32_DMA_STREAM(STM32_UART_USART3_RX_DMA_STREAM);
    UARTD3.dmatx   = STM32_DMA_STREAM(STM32_UART_USART3_TX_DMA_STREAM);
  #endif
 +
 +#if STM32_UART_USE_USART6
 +  uartObjectInit(&UARTD6);
 +  UARTD6.usart   = USART6;
 +  UARTD6.dmarx   = STM32_DMA_STREAM(STM32_UART_USART6_RX_DMA_STREAM);
 +  UARTD6.dmatx   = STM32_DMA_STREAM(STM32_UART_USART6_TX_DMA_STREAM);
 +#endif
  }
  /**
 @@ -452,6 +492,27 @@ void uart_lld_start(UARTDriver *uartp) {      }
  #endif
 +#if STM32_UART_USE_USART6
 +    if (&UARTD6 == uartp) {
 +      bool_t b;
 +      b = dmaStreamAllocate(uartp->dmarx,
 +                            STM32_UART_USART6_IRQ_PRIORITY,
 +                            (stm32_dmaisr_t)uart_lld_serve_rx_end_irq,
 +                            (void *)uartp);
 +      chDbgAssert(!b, "uart_lld_start(), #5", "stream already allocated");
 +      b = dmaStreamAllocate(uartp->dmatx,
 +                            STM32_UART_USART6_IRQ_PRIORITY,
 +                            (stm32_dmaisr_t)uart_lld_serve_tx_end_irq,
 +                            (void *)uartp);
 +      chDbgAssert(!b, "uart_lld_start(), #6", "stream already allocated");
 +      rccEnableUSART6(FALSE);
 +      nvicEnableVector(STM32_USART6_NUMBER,
 +                       CORTEX_PRIORITY_MASK(STM32_UART_USART6_IRQ_PRIORITY));
 +      uartp->dmamode |= STM32_DMA_CR_CHSEL(USART6_RX_DMA_CHANNEL) |
 +                        STM32_DMA_CR_PL(STM32_UART_USART6_DMA_PRIORITY);
 +    }
 +#endif
 +
      /* Static DMA setup, the transfer size depends on the USART settings,
         it is 16 bits if M=1 and PCE=0 else it is 8 bits.*/
      if ((uartp->config->cr1 & (USART_CR1_M | USART_CR1_PCE)) == USART_CR1_M)
 @@ -503,6 +564,14 @@ void uart_lld_stop(UARTDriver *uartp) {        return;
      }
  #endif
 +
 +#if STM32_UART_USE_USART6
 +    if (&UARTD6 == uartp) {
 +      nvicDisableVector(STM32_USART6_NUMBER);
 +      rccDisableUSART6(FALSE);
 +      return;
 +    }
 +#endif
    }
  }
 diff --git a/os/hal/platforms/STM32/USARTv1/uart_lld.h b/os/hal/platforms/STM32/USARTv1/uart_lld.h index 0e3576987..7994b1e62 100644 --- a/os/hal/platforms/STM32/USARTv1/uart_lld.h +++ b/os/hal/platforms/STM32/USARTv1/uart_lld.h @@ -71,6 +71,15 @@  #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(STM32_UART_USE_USART6) || defined(__DOXYGEN__)
 +#define STM32_UART_USE_USART6               FALSE
 +#endif
 +
 +/**
   * @brief   USART1 interrupt priority level setting.
   */
  #if !defined(STM32_UART_USART1_IRQ_PRIORITY) || defined(__DOXYGEN__)
 @@ -92,6 +101,13 @@  #endif
  /**
 + * @brief   USART6 interrupt priority level setting.
 + */
 +#if !defined(STM32_UART_USART6_IRQ_PRIORITY) || defined(__DOXYGEN__)
 +#define STM32_UART_USART6_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
   *          because of the channels ordering the RX channel has always priority
 @@ -122,6 +138,16 @@  #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(STM32_UART_USART6_DMA_PRIORITY) || defined(__DOXYGEN__)
 +#define STM32_UART_USART6_DMA_PRIORITY      0
 +#endif
 +
 +/**
   * @brief   USART1 DMA error hook.
   * @note    The default action for DMA errors is a system halt because DMA
   *          error can only happen because programming errors.
 @@ -180,6 +206,22 @@  #define STM32_UART_USART3_TX_DMA_STREAM     STM32_DMA_STREAM_ID(1, 3)
  #endif
 +/**
 + * @brief   DMA stream used for USART6 RX operations.
 + * @note    This option is only available on platforms with enhanced DMA.
 + */
 +#if !defined(STM32_UART_USART6_RX_DMA_STREAM) || defined(__DOXYGEN__)
 +#define STM32_UART_USART6_RX_DMA_STREAM     STM32_DMA_STREAM_ID(2, 2)
 +#endif
 +
 +/**
 + * @brief   DMA stream used for USART6 TX operations.
 + * @note    This option is only available on platforms with enhanced DMA.
 + */
 +#if !defined(STM32_UART_USART6_TX_DMA_STREAM) || defined(__DOXYGEN__)
 +#define STM32_UART_USART6_TX_DMA_STREAM     STM32_DMA_STREAM_ID(2, 7)
 +#endif
 +
  #else /* !STM32_ADVANCED_DMA */
  /* Fixed streams for platforms using the old DMA peripheral, the values are
 @@ -210,8 +252,12 @@  #error "USART3 not present in the selected device"
  #endif
 +#if STM32_UART_USE_USART6 && !STM32_HAS_USART6
 +#error "USART6 not present in the selected device"
 +#endif
 +
  #if !STM32_UART_USE_USART1 && !STM32_UART_USE_USART2 &&                     \
 -    !STM32_UART_USE_USART3
 +    !STM32_UART_USE_USART3 && !STM32_UART_USE_USART6
  #error "UART driver activated but no USART/UART peripheral assigned"
  #endif
 @@ -230,6 +276,11 @@  #error "Invalid IRQ priority assigned to USART3"
  #endif
 +#if STM32_UART_USE_USART6 &&                                                \
 +    !CORTEX_IS_VALID_KERNEL_PRIORITY(STM32_UART_USART6_IRQ_PRIORITY)
 +#error "Invalid IRQ priority assigned to USART6"
 +#endif
 +
  #if STM32_UART_USE_USART1 &&                                                \
      !STM32_DMA_IS_VALID_PRIORITY(STM32_UART_USART1_DMA_PRIORITY)
  #error "Invalid DMA priority assigned to USART1"
 @@ -245,6 +296,11 @@  #error "Invalid DMA priority assigned to USART3"
  #endif
 +#if STM32_UART_USE_USART6 &&                                                \
 +    !STM32_DMA_IS_VALID_PRIORITY(STM32_UART_USART6_DMA_PRIORITY)
 +#error "Invalid DMA priority assigned to USART6"
 +#endif
 +
  #if STM32_UART_USE_USART1 &&                                                \
      !STM32_DMA_IS_VALID_ID(STM32_UART_USART1_RX_DMA_STREAM,                 \
                             STM32_USART1_RX_DMA_MSK)
 @@ -281,6 +337,18 @@  #error "invalid DMA stream associated to USART3 TX"
  #endif
 +#if STM32_UART_USE_USART6 &&                                                \
 +    !STM32_DMA_IS_VALID_ID(STM32_UART_USART6_RX_DMA_STREAM,                 \
 +                           STM32_USART6_RX_DMA_MSK)
 +#error "invalid DMA stream associated to USART6 RX"
 +#endif
 +
 +#if STM32_UART_USE_USART6 &&                                                \
 +    !STM32_DMA_IS_VALID_ID(STM32_UART_USART6_TX_DMA_STREAM,                 \
 +                           STM32_USART6_TX_DMA_MSK)
 +#error "invalid DMA stream associated to USART6 TX"
 +#endif
 +
  #if !defined(STM32_DMA_REQUIRED)
  #define STM32_DMA_REQUIRED
  #endif
 @@ -432,6 +500,10 @@ extern UARTDriver UARTD2;  extern UARTDriver UARTD3;
  #endif
 +#if STM32_UART_USE_USART6 && !defined(__DOXYGEN__)
 +extern UARTDriver UARTD6;
 +#endif
 +
  #ifdef __cplusplus
  extern "C" {
  #endif
 | 
