We use Keil tools to generate C++ embedded application that run in our embedded controller.
My initialization code jumps to __main as follows:
IMPORT __main LDR R0, =__main BX R0
Wher is "__main" ?
I searched C:\Keil but could not find definition of __main.
This is what my map file says about __main
__main 0x00008308 ARM Code 8 __main.o(!!!main)
My application starts at 0x8000. __main is at 0x00008308. Where is __main.o ?
you have to write main function. it is where your program starts.
>>it is where your program starts.
No it's not. It eventually gets to main(), but before that it uses start up code in the library which initializes the static space (BSS) with initialized variables which are copied, and zero'd space.
I never make it to my main() because it looks like static variable nr_mutex never gets intialized.
// Filename RTX_lib.c ... ... static U32 nr_mutex; .. ... ..
int _mutex_initialize (OS_ID *mutex)
{ /* Allocate and initialize a system mutex. */
if (nr_mutex >= OS_MUTEXCNT)
{
/* If you are here, you need to increase the number OS_MUTEXCNT. */
for (;;);
}
*mutex = &std_libmutex[nr_mutex++];
mutex_init (*mutex);
return (1);
I enter forever loop because 'nr_mutex' has bogus value 0x00800080. I should never enter this forever loop.
When __main() starts running, there is a lot of code. I can see assembly language code. What portion of this code is responsible for intializing static variables? My peer runs to our main() function. How might my build environment different than his. There must be something different. Please advise! Thank you!
__main is the entry to the Keil "secret sauce" that run before getting to your main()
What portion of this code is responsible for intializing static variables?
no concern of yours
My peer runs to our main() function.
what is "my peer"?
How might my build environment different than his you do NOT want to.
I am not working with Keil at this moment, but do recall that if you have not done something (wish I remember) and are using printf() you get exactly that __main bum out.
If you are using printf() state so and ask "what is it I have to do to make printf() not blow __main" and someone will tell yo
Thank you! Your response is helpful but I cannot get to my main() function. I get stuck in forever loop between __main() and my main(). I can't debug the code because it's Keil code. How do I resolve this problem? What do I need to do to get Keil to jump to my main(). I'm not using any printf() statements.
in forever loop between __main() and my main(). I se two possibilities a) active watchdog b) no infinite loop in main
I can't debug the code because it's Keil HUH? I know of no means of loading an ARM processor that can not be used for debugging code.
How do I resolve this problem? What do I need to do to get Keil to jump to my main().
you state above "loop between __main() and my main()" so it must "jump to my main()" That you need to clarify.
Erik
Well you should probably review your startup.s file, and your target memory settings. Check also if you need to configure registers within your chip, or initialize external RAM, before C can start.
You'll likely have to uncheck "Run to main()" in order to debug the situation.
my main() is as follows:
int main()
os_sys_init(init);
return 0;
After my startup assembly file executes, Keil __main() runs and then I enter forever loop mentioned earlier in this message thread. I never hit my main().
My co-worker is up and running. He hits the main(). I took his source code and Keil RL-ARM (Real-Time Library) from my machine and encountered the exact same problem.
I can try your suggestions but doesn't it look like the problem is with Keil RL-ARM code. Maybe should I re-install Keil uVision4?
THIS IS NOT PC PROGRAMMING!!!
in embedded you can not return from main
If you want to do embedded there is one rule
"the embbeded chip aint no PC"
return 0 should never execute. We should never get to return 0 statement.
did you set a breakpoint and verify that "return 0 should never execute"
return 0 should never execute. We should never get to return 0 statement. I assume you want to say that the code should never exit main(). True. But when using RTOS, main() is terminated. And, "return" in main() is not good for embedded designs.
Coming back to the topic what is your startup code? possibly post your code. And use Tips for Posting Messages
But when using RTOS, main() is terminated.
Really?
Correct me if i am wrong
The os_sys_init(MasterTask) is called before termination. Hence it is valid if the while(1) statement is not written at the end of main(), because the controller executes "os_idle_demon()" even if there are no other tasks. And other tasks, if present, also have code written in infinite loop. Hence the controller will always have atleast one infinite loop.
int main(void) { . . . os_sys_init(MasterTask); //while(1); // }
Currently, I'm not working on this project. If I resume this project, I'll continue the thread.
Thank you so much for valuable feedback.