cancel
Showing results for 
Search instead for 
Did you mean: 

What is the difference between HAL UART and HAL USART?

Muscle Man
Associate III
Posted on March 30, 2017 at 16:22

Hi to all!,

Having to write a simple UART device driver for my application (based on a STM32L073 mcu),

I noticed that HAL presents two kind of uart drivers: an HAL UART and an HAL USART.

Digging a little bit into the related HAL code, I would say that 

HAL USART are more suited to

use USART macrocell as a simple uart; instead HAL UART seems to be more useful when 

a need for LIN/Multimaster mode or IrDA arises. Am I right?

Thanks in advance to everyone would take me a feedback!

Scrat75.

2 REPLIES 2
S.Ma
Principal
Posted on March 30, 2017 at 17:49

Actually it should be the opposite. With UART, you get RX/TX only. With USART superset, you also get RTS/CTS/CK signals, plus some additional serial protocols in there (Lin, sometime smart card interface with TX and CK pins, etc...)

Guenael Cadier
ST Employee
Posted on March 31, 2017 at 18:37

Hi Stefano,

My answer is different from previous one. Actually, HAL USART is dedicated to operation in Synchronous mode, I mean transfers are synchronized with SCLK signal (controlled by CPHA and CPOL).

When transmitting => as soon as some data are to be transferred, SCLK will be output.

When Receiving => as soon as SCLK is generated, some acquisition is done on RX line (no need for start bit for instance).

Usart way of working is more close to a SPI master mode.

HAL UART is related to asynchronous transfers (for example, reception is triggerred by detection of a start bit). HW flow control, LIN, ... are to be served using HAL_UART_xxx() APIs.

For IRDA, a HAL_IRDA group is available.

Now aside from available HAL services, your device embedds several UART/USART instances. In corresponding datasheet (

http://www.st.com/content/ccc/resource/technical/document/datasheet/d8/b3/7b/dc/18/22/44/f5/DM00141036.pdf/files/DM00141036.pdf/jcr:content/translations/en.DM00141036.pdf

) you should be able to find capabilities of each USART instance available on your L073. Some features are available only on some instances :

For example, you could use USART1/2/3/4 instance for achieving UART transfers (using HAL_UART functions), USART1/2/3/4 instance for achieving USART transfers (using HAL_USART functions), but if you want to use HAL_IRDA functions, you will have to use either USART1 or USART2 instance in the device (USART3 and 4 not supporting Irda). Please extracted table below.

0690X00000606gMQAQ.png

Hope this helps.

Regards

Guenael