cancel
Showing results for 
Search instead for 
Did you mean: 

UART Problem when using default initialization

skon.1
Senior

Hello,

I've encountered a problem while using the STM32CubeIDE.

I have a project targeting the NUCLEO-F722ZE EVB - the purpose is to print "Hello World!" to the PC console connected to the ST-LINK USB. 

When creating a new project, at the MXCube I'm presented with an option to "Initialize all peripherals with their default Mode".

If I choose "yes" my code prints ASCII garbage to the screen.

If I choose "no" and set the UART peripheral manually - it works fine (prints "Hello World!").

This is my code (inside the main function) after all the auto-generated initialization:

while (1)
{
  uint8_t buffer[] = "Hello World!\n\r";
  HAL_UART_Transmit(&huart3, buffer, sizeof(buffer), 0xFFFF);
}

I checked that the UART settings in both cases (auto initialized and manual) are the same. So what may cause such a problem ? Is it a bug in the tool ?

3 REPLIES 3

I don't use Cubes and have no idea what's that option. Maybe somebody knowledgeable will chime in, but meantime:

> my code prints ASCII garbage to the screen.

Observe the line using oscilloscope/logic analyzer. Compare to working case.

> I checked that the UART settings in both cases (auto initialized and manual) are the same

Checked how? Did you read out the UART registers content in both cases and compared? If yes, can't the clocks in RCC be set differently?

JW

Googling yielded:

0693W000003BH15QAG.png

So, I'd recommend to check the GPIO registers for whatever pin are you using for Tx, too.

Or just don't use this option. I can't imagine what would it be good for.

JW

TDK
Guru

Has to be a difference in the code somewhere.

It's possible the HSE_VALUE is different between your setup and the board setup. Blink an LED at 1Hz to verify the clock is (about) correct.

If you feel a post has answered your question, please click "Accept as Solution".