cancel
Showing results for 
Search instead for 
Did you mean: 

huart1 initialized with some value, HOW ?

Manojkumar Subramaniam
Associate II

I have a question out of curiously, how the values inside the huart1 initialized with some values without any function calling.. the breakpoints is at start of main()

This discussion is locked. Please start a new topic to ask your question.
4 REPLIES 4

huart1 is an uninitialized global variable, being in .bss section[1] (or equivalent) it shouldn't have any initialized values until the MX_USART1_UART_Init is called. C standard doesn't require uninitialized data to be zeros.

I guess when you are restarting your debugging session, the microcontroller's SRAM isn't being reset (no power off-on) so you are inheriting some "garbage" data from the previous session.

[1] - https://en.wikipedia.org/wiki/.bss

tried unplugging the power.. and it's the same. somehow it's initialized to 0 ..

Local/auto variables will contain random stack junk unless explicitly initialized.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

To zero? That's OK, I thought by "initialized with some values" you meant something non-zero. I was wrong about the C standard:

If an object that has static storage duration is not initialized explicitly, it is initialized implicitly as if every member that has arithmetic type were assigned 0 and every member that has pointer type were assigned a null pointer constant.

So the startup code does initialize the bss section with zeros. The startup code is being called before main.