cancel
Showing results for 
Search instead for 
Did you mean: 

UART don't initialize

JAgue.1
Associate II

Hello,

I'm working on a NucleoF746ZG, for the past week i'm unable to communicate with board tought UART.

The problem seems to be that HAL_UART_Init(&huartX) return 0 which means that the UART is not initialized.

I tried to check if it was a hardware problem with a previous work and the UART is prefectly fine.

So i tried to check with a brand new code generate with MX with no modification except the USART6 on pin PG14 & PG9 and the clock (i tested also the basic clock config did't work)

There code send "Hello\r\n\0" to my board and blink the redled if the state return by HAL_UART_Transmit is 0

There is the main:

int main(void)

{

 HAL_Init();

 /* Configure the system clock */

 SystemClock_Config();

 MX_GPIO_Init();

 MX_ETH_Init();

 MX_USART3_UART_Init();

 MX_USB_OTG_FS_PCD_Init();

 MX_USART6_UART_Init();

 HAL_UART_StateTypeDef uartState = HAL_UART_GetState(&huart6);

uint8_t * ping = "Hello\r\n\0";

uint16_t len = strlen((char*) ping);

 while (1)

 {

 uartState = HAL_UART_Transmit(&huart6, ping, len, 100);

 if(uartState == 0x00U)

 HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);

 HAL_Delay(1000);

 }

}

Thanks for your time.

4 REPLIES 4
Javier1
Principal

could you post your cubemx file

we dont need to firmware by ourselves, lets talk

There you have it

Bob S
Principal

> HAL_UART_Init(&huartX) return 0 which means that the UART is not initialized

No, it does not. 0 == HAL_OK, so HAL thinks the UART **is** initialized.

And HAL_UART_StateTypeDef is NOT the data type returned from HAL_UART_Transmit(). It is (like HAL_UART_Init()) HAL_StatusTypeDef. Though since you are comparing with "0" and not one of the typedef values that is only an issue for people reading your code.

So, what exactly is the issue? Do you see the LED blink? Have you pu a scope on the UART pins to see if data appears? At the desired bit rate?

JAgue.1
Associate II

Ok, nvm. I simplified my problem to test, so yes the mixed up the HAL_StatusTypeDef (which HAL_OK is 0) and HAL_UART_StateTypeDef (which 0 means not initialised)

My problem in my initial projet has related to a variable going out of its scope, and returning a HAL_UART_StateTypeDef being 0

Thanks for you help.