cancel
Showing results for 
Search instead for 
Did you mean: 

Confusion between stm32l1xx_hal_usart.c and stm32l1xx_hal_uart.c

dean
Associate II
Posted on January 27, 2016 at 01:18

Hi, can anyone clear up as to why, when I configure the USART2 interrupt  using the STM32CubeMX utility, the intialization code it generates calls functions in stm32l1xx_hal_uart.c instead of stm32l1xx_hal_usart.c?  I am surprised at this since I am configuring a USART perhiperal, not one of the UART perhiperals.

I see no difference between the data structures 

USART_HandleTypeDef

and 

UART_HandleTypeDef

, but the generated initialization code seems to prefer the latter for use.

Is there a document (other than the code modules themselves) that explains the difference between the UART functions compared with the USART modules?

Thanks!
3 REPLIES 3
qwer.asdf
Senior
Posted on January 27, 2016 at 09:21

It's an unfortunate naming convention used by the HAL developers.

USART means Universal Synchronous/Asynchronous Receiver/Transmitter, so the peripherals with USARTx name support both Synchronous and Asynchronous modes, while the peripherals named UARTx support only the Asynchronous mode.

In the HAL library, (I suppose) it's different: when you want to use a peripheral in Asynchronous mode you use the UART_xxx functions, when you want to use the peripheral in Synchronous mode (if it supports that mode) then you use the USART_xxx functions.

Maybe they should had been named the latter family of functions as USRT_xxx.

And you can find the documentation of STM32L1 HAL library

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/DM00132099.pdf

.

Nesrine M_O
Lead II
Posted on January 27, 2016 at 10:01

Hi lopez.dean,

I cannot reproduce your issue, I generated a project with MX4.12 witch enable the USART2 peripheral (Mode: Synchronous ), the generated project call functions from the stm32l1xx_hal_usart driver.

so it seems that you configure the USART2 en mode Asynchronous in this case the project have to use the UART driver.

-Syrine-

dean
Associate II
Posted on January 27, 2016 at 15:48

Hi Syrine,

Yes, you are correct, my USART is configured in asynchronous mode.  As long as the UART initialization code addresses and configures the USART2 perhiperal correctly, I have no problem with it choosing the UART module.  But it sounds like the choice between invoking either of the two modules is triggered by configuring in synchronous vs asynchronous mode, and not by configuring a USART perhiperal vs a UART perhiperal.

That is a reasonable explanation, thank you for taking the time to reply.