6.19. UART

The uart module is part of the Driver layer.

The uart module provides the capability to send and receive data using the RS232/UART interface.

6.19.1. Module Files

  • embedded-software\mcu-common\src\driver\uart\uart.c (uart.c)
  • embedded-software\mcu-common\src\driver\uart\uart.h (uart.h)
Driver Configuration:
  • embedded-software\mcu-primary\src\driver\config\uart_cfg.c (uart_cfg.c)
  • embedded-software\mcu-primary\src\driver\config\uart_cfg.h (uart_cfg.h)

6.19.2. Detailed Description

The uart module uses a user-defined buffer for transmitting data. A custom IRQ handler is responsible for handling all receive/transmit processes. Those operations are dispatched to sub-functions according to the set flags in the status register.

6.19.3. UART Configuration

The default configuration is done within the UART_Init() function, which gets called during startup. Below is an example showing the UART configuration which uses usart3 with a baud rate of 115200Bd:

            .Instance = USART3,
            .Init.BaudRate = 115200,
            .Init.WordLength = UART_WORDLENGTH_8B,
            .Init.StopBits = UART_STOPBITS_1,
            .Init.Parity = UART_PARITY_NONE,
            .Init.Mode = UART_MODE_TX_RX,
            .Init.HwFlowCtl = UART_HWCONTROL_NONE,
            .Init.OverSampling = UART_OVERSAMPLING_16,

6.19.4. Usage

The initialization has to be done during startup for subsequent function calls to succeed. UART_IntRx and UART_IntTx are interrupt driven and do not need to be called by the user. Assuming initialization was done properly, the user only needs to copy content from the internal ring buffer for reading purpose, or call UART_vWrite for writing purpose.