Hi,
is it possible to call a c-function during the initalization of the startup-file? Could you give me one simple example?
; Reset Handler EXPORT Reset_Handler Reset_Handler ; open lowlevelinit c-function ; IMPORT LowLevelInit ; Setup Power Management Controller (PMC) -------------------------------------- IF :DEF:NO_PMC_INIT ELSE IF PMC_SETUP != 0 LDR R0, =PMC_BASE
Do you know any important things writing this init-function? How do the startup-file know the place / the c-file , where the function is declared?
best regards Alan
When I try,
; Reset Handler EXPORT Reset_Handler ; Perform low-level initialization of the chip using LowLevelInit() IMPORT LowLevelInit Reset_Handler ; Call Low level init LDR r0, =LowLevelInit MOV lr, pc BX r0
the user-code is not working...
Presumably because the 'C' code relies upon things that have not yet been (properly) initialised...?
This is usually why startup code is in assembler!
What, exactly, is it that you are trying to achieve here?
what do you mean by that? is the function not called?
because I've problems with the startup-code provided by keil. If I use this LowLevelInit function at the beginning of the main function, the processor is running and the pll etc. is working. If I use the pll init and osciallator init the processor is not running properly - but I don't know why.
I also test to call my function LowLevelInit() at the end of the startup file (just befor the mode section) -> but I also have not the ability to start the processor properly.
I don't know what is going wrong, using the original startup code....
best regards Scott
If I use the pll init and osciallator init the processor is not running properly from the original startup file from keil.
It is perfectly fine using C in your start up code, provided that you follow some guidelines:
1. All (C-)functions that are called from startup code must be located in a root region (load address == exec address)
Scatter loading has not been taken place, yet.
2. The supervisor stack has been set up.
We need some stack for local variables, etc. You never know what the compiler does exactly.
3. No functions from the C library must be called directly or indirectly.
The C library initialization has not been executed.
4. Know what you are doing.
Some startup tasks might be easier to implement in C, others are not.
Regards Marcus http://www.doulos.com/arm/
excellent comments, Marcus. If the OP is indeed busy with some EmbeddedArtists code as it looks like, then the LowLevelInit function certainly uses C library function calls, as far as I can recall!
Thanks, Tamir. One more:
6. Don't rely on initial values of global variables
What happened to 5?
Left as exercise :-) We are a training company you know.
Tamir was expected to have written #5
the lowlevelinit function use c-level functions (start main oscillator and pll for example).
for example:
//turn on main oscillator AT91C_BASE_PMC->PMC_MOR = AT91C_CKGR_MOSCEN; while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS));
what about "console" initialization...?
what about "console" initialization...? what do you mean by console init?
can you post the function that is called?