Skip to main content
HF.Wang
Associate II
January 11, 2023
Solved

How to enable USART driver in CubeMX?

  • January 11, 2023
  • 3 replies
  • 3076 views

The code generated by the STM32CubeMX is using the UART rather than the USART.

How do we generate the code using the USART driver lib via the CubeMX?

This topic has been closed for replies.
Best answer by Guenael Cadier

Hi @Community member​ 

USART1, USART2, ... and/or UART4 or UART5, ... are instances of peripherals, able to achieve UART/USART communications.

Usually, USARTx instances are able to handle :

- UART comms : Asynchronous communication, no CLK signal

- USART comms : Synchronous, based on a CLK signal

while UARTy instances only handle :

- UART comms : Asynchronous communication, no CLK signal

So depending on what type of communication you want to handle, you need to select the appropriate type in CubeMx configuration :

"Asynchronous" => Use of HAL UART API, UART comm type

"Synchronous" => Use of HAL USART API, USART comm type

0693W00000Y7wnqQAB.png 

Hope this answers your question

Regards

3 replies

HF.Wang
HF.WangAuthor
Associate II
January 11, 2023

Using the STM32L412 with the latest CubMx and Lib.

Karl Yamashita
Principal
January 11, 2023

It's the same driver for both types

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
Guenael Cadier
Guenael CadierBest answer
ST Employee
January 11, 2023

Hi @Community member​ 

USART1, USART2, ... and/or UART4 or UART5, ... are instances of peripherals, able to achieve UART/USART communications.

Usually, USARTx instances are able to handle :

- UART comms : Asynchronous communication, no CLK signal

- USART comms : Synchronous, based on a CLK signal

while UARTy instances only handle :

- UART comms : Asynchronous communication, no CLK signal

So depending on what type of communication you want to handle, you need to select the appropriate type in CubeMx configuration :

"Asynchronous" => Use of HAL UART API, UART comm type

"Synchronous" => Use of HAL USART API, USART comm type

0693W00000Y7wnqQAB.png 

Hope this answers your question

Regards

HF.Wang
HF.WangAuthor
Associate II
January 11, 2023

Thanks. Got it. That mean the USART only be used when the synchronous mode selected. If the only asynchronous mode used, the CubeMX will only use the UART lib.