CMSIS-Driver_STM32  
CMSIS Drivers for STMicroelectronics STM32 Series devices
 
Loading...
Searching...
No Matches
USART

Revision History

  • Version 3.0
    • Initial release

Requirements

This driver requires the STM32 device specific HAL and STM32CubeMX (CubeMX) initialization code generator. The driver instance is mapped to hardware as shown in the table below:

CMSIS Driver Instance STM32 Hardware Resource
Driver_USART1 U(S)ART1
Driver_USART2 U(S)ART2
Driver_USART3 U(S)ART3
Driver_USART4 U(S)ART4
Driver_USART5 U(S)ART5
Driver_USART6 U(S)ART6
Driver_USART7 U(S)ART7
Driver_USART8 U(S)ART8
Driver_USART9 U(S)ART9
Driver_USART10 U(S)ART10
Driver_USART11 U(S)ART11
Driver_USART12 U(S)ART12
Driver_USART13 U(S)ART13
Driver_USART14 U(S)ART14
Driver_USART15 U(S)ART15
Driver_USART21 LPUART1
Driver_USART22 LPUART2
Driver_USART23 LPUART3

Deviations

This driver has the following deviations from the CMSIS-Driver specification:

Conceptual deviations:

  • CubeMX generated initialization code (function MX_UARTn_Init or MX_USARTn_UART_Init) already configures the peripheral. Power, clocks, pins, and interrupts are enabled after execution of initialization that executes in main.c.

Functional deviations:

  • GetCapabilities:
    • depends on the code generated by CubeMX.
  • Initialize:
    • depends on the code generated by CubeMX.
    • disables Transmitter and Receiver.
    • does not initialize the pins.
  • Uninitialize:
    • does not de-initialize the pins.
  • PowerControl:
    • depends on the code generated by CubeMX.
    • low-power mode is not supported by HAL.
  • Send:
    • maximum number of data items supported with a single send request is 65535.
  • Receive:
    • maximum number of data items supported with a single receive request is 65535.
  • Control:
    • Tx break generation is not supported by HAL.
    • manual control of flow control lines is not supported by HAL.
  • GetStatus:
    • Rx break status is not supported by HAL (always 0).
    • Rx overflow cannot be detected until Receive is started.
  • SetModemControl:
    • not supported by HAL.
  • GetModemStatus:
    • not supported by HAL.
  • SignalEvent:
    • Rx break detection and signaling is not supported by HAL.
    • Rx overflow detection does not work until Receive is started.

CubeMX Configuration

This driver requires the following configuration in CubeMX:

  • clock: UART/USART peripheral clock.
  • peripheral: UART/USART peripheral configured as Asynchronous with optional Hardware Flow Control and Parameter Setting configured as desired, except Advanced Parameters: Fifo Mode, if it exists, should be set to Disable.
  • pins: UART/USART TX and UART/USART RX pins, and optional Hardware flow Control pins.
  • DMA: optional DMA configuration for transfers.
  • interrupts: enabled UART/USART interrupts and IRQ handlers that Call HAL handlers and enabled DMA interrupts and IRQ handlers that Call HAL handlers if DMA is used.

Notes

  • configuration information in the MX_Device.h file is based on CubeMX configuration.
  • DMA configuration can differ between devices series so configure DMA as required by the used device.
  • for DMA usage on devices with cache, ensure that data buffers for Send and Receive functions are in non-cacheable memory, or ensure that memory for send is updated (cache clean) before Send function is called and that memory containing received data is updated after the reception finishes (cache invalidate).
  • some DMA controllers can only access specific memories, so ensure that proper memory is used for the buffers according to the DMA requirement.

Example

Pinout & Configuration tab

  1. In the Pinout view window click on a pin and select it's functionality:
    Pin Functionality
    PA11 USART1_CTS
    PA12 USART1_RTS
    PB14 USART1_TX
    PB15 USART1_RX

  2. Under Categories: Connectivity select USART1:

    Mode:

    • Mode: Asynchronous
    • Hardware Flow Control (RS232): CTS/RTS

    Configuration:

    • Parameter Settings: as desired, except Advanced Parameters: Fifo Mode which should be set to Disable
    • GPIO Settings:
      Pin Name Signal on Pin Pin Context.. GPIO output.. GPIO mode GPIO Pull-up/Pull.. Maximum out.. Fast Mode User Label
      PA11 USART1_CTS n/a n/a Alternate Function Push Pull No pull-up and no.. Low n/a .
      PA12 USART1_RTS n/a n/a Alternate Function Push Pull No pull-up and no.. Low n/a .
      PB14 USART1_TX n/a n/a Alternate Function Push Pull No pull-up and no.. Low n/a .
      PB15 USART1_RX n/a n/a Alternate Function Push Pull No pull-up and no.. Low n/a .

  3. Under Categories: System Core select DMA (might be different on other device series, or for some peripherals might be BDMA):

    Configuration:

    • DMA1, DMA2:

      Click on Add button and add DMA Requests as in table below:

      DMA Request Stream Direction Priority
      USART1_RX DMA1 Stream 0 Peripheral to Memory Low
      USART1_TX DMA1 Stream 1 Memory to Peripheral Low


  4. Under Categories: System Core select NVIC:

    Configuration:

    • NVIC:
      NVIC Interrupt Table Enabled Preemption Priority Sub Priority
      DMA1 stream0 global interrupt checked 0 0
      DMA1 stream1 global interrupt checked 0 0
      USART1 global interrupt checked 0 0

    • Code generation:
      Enabled interrupt table Select for.. Generate Enable in.. Generate IRQ h.. Call HAL handler
      DMA1 stream0 global interrupt unchecked checked checked checked
      DMA1 stream1 global interrupt unchecked checked checked checked
      USART1 global interrupt unchecked checked checked checked

Clock Configuration tab

  1. Configure To USART1,6,9,10 (MHz): 100

Project Manager tab

  1. Under Advanced Settings:

    Generated Function Calls:

    Generate Code Function Name Peripheral Inst.. Do not generate .. Visibility (Static)
    checked MX_USART1_UART_Init USART1 unchecked checked