2017-04-20 10:05 AM
To who may help:
I am a beginer with stm32. Today, I have some promble with my board(stm32f407xx): the main fuction will automatically cycle three times. codes are follow:
#include ''stm32f4xx.h''
int main(void)
{/* this function just do some init work for uart1 */
uart_init(115200);
/* printf already r
edirect to UART1
*/ printf(''please....\r\n\r\n''); return 0;}the result from Serial debugging assistant:
My friend told me I should add while(1) at the end of code. But I have write some test code without while(1) before, and it work well. It is really puzzled me. Why?Why?Why? By the way, I use Keil MDK5 to build my code. hope someone can help me.
Solved! Go to Solution.
2017-04-20 12:53 PM
Your friend is right, you shouldn't exit main(), it goes nowhere you want to go. Most likely crashing. It is called with no expectation of returning. Look at code in startup_stm32xxxx.s
2017-04-20 12:53 PM
Your friend is right, you shouldn't exit main(), it goes nowhere you want to go. Most likely crashing. It is called with no expectation of returning. Look at code in startup_stm32xxxx.s
2017-04-20 11:27 PM
MCU main function is not called from a command prompt with passing parameter.
Typically, bare metal would look like this:
int main(void) {
// Init functions
while(1) {
// here is the main loop as long as MCU has power
};
return 0;
}
2017-04-21 02:39 AM
What it means - there is no OS (like Windows, Linux, etc.) your application can return to.
It goes nowhere, as Clive mentioned, or, if the startup code contains a kind of 'safety net', catches a return from main in an endless loop.
That is one major characteristic difference of embedded software.
2017-04-21 07:52 AM
haha, it is a stupid question of a beginer.thank you so much.
2017-04-21 07:54 AM
thanks AvaTar, you let me know more about
embedded software.