cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX 407s USART/UART inconsistancy

Posted on December 12, 2014 at 22:31

I'm working on a system where we use a STM32F407VGT6. I set up the project in CubeMX (latest version). We are using USARTs 1,2, and 3 with interrupts for receive.

I'm having some issues with the USART portion of the HAL. I looked at the code in usart.c and I noticed that it is calling HAL_UART_init instead of HAL_USART_init (uart rather than uSart).

Actually, the code in stm32f4xx_hal_usart.c is mostly compiled out and the compiler bitches when I call HAL_USART_Receive_IT (as recommended in UM1725, the users manual for the F4 HAL).

Has the USART code been depreciated and I should always use the UART code?

#hal-usart-uart
1 REPLY 1
stm32cube-t
Senior III
Posted on January 09, 2015 at 09:17

Hello,

The HAL init function corresponds to the peripheral functional mode: UART for asynchronous mode, USART for synchronous mode.

See the example below when setting USART1 in asynchronous mode, USART2 in synchronous mode, and USART3 in irDa mode:

* USART1 init function */

void MX_USART1_UART_Init(void)

{

  huart1.Instance = USART1;

  huart1.Init.BaudRate = 115200;

  huart1.Init.WordLength = UART_WORDLENGTH_8B;

  huart1.Init.StopBits = UART_STOPBITS_1;

  huart1.Init.Parity = UART_PARITY_NONE;

  huart1.Init.Mode = UART_MODE_TX_RX;

  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;

  huart1.Init.OverSampling = UART_OVERSAMPLING_16;

  HAL_UART_Init(&huart1);

}

/* USART2 init function */

void MX_USART2_Init(void)

{

  husart2.Instance = USART2;

  husart2.Init.BaudRate = 115200;

  husart2.Init.WordLength = USART_WORDLENGTH_8B;

  husart2.Init.StopBits = USART_STOPBITS_1;

  husart2.Init.Parity = USART_PARITY_NONE;

  husart2.Init.Mode = USART_MODE_TX_RX;

  husart2.Init.CLKPolarity = USART_POLARITY_LOW;

  husart2.Init.CLKPhase = USART_PHASE_1EDGE;

  husart2.Init.CLKLastBit = USART_LASTBIT_DISABLE;

  HAL_USART_Init(&husart2);

}

/* USART3 init function */

void MX_USART3_IRDA_Init(void)

{

  hirda3.Instance = USART3;

  hirda3.Init.BaudRate = 115200;

  hirda3.Init.WordLength = IRDA_WORDLENGTH_8B;

  hirda3.Init.Parity = IRDA_PARITY_NONE;

  hirda3.Init.Mode = IRDA_MODE_TX_RX;

  hirda3.Init.Prescaler = 10;

  hirda3.Init.IrDAMode = IRDA_POWERMODE_LOWPOWER;

  HAL_IRDA_Init(&hirda3);

}