2017-03-30 07:22 AM
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.
2017-03-30 08:49 AM
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...)
2017-03-31 09:37 AM
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 (
) 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.
Hope this helps.
Regards
Guenael