I have written some code for a Silabs C8051F330 CPU, compiled it and then obviously some C51STARTUP code is generated that initialize the variables. Using my USB debug adaptor I discover the execution got stuck in the C51STARTUP code and it never exits it to the main program. What could be a possible cause for this and how can I fix it?
Doesn't the standard startup code include zeroing all of XDATA...?
To understand what is happening during start up you need to look at the the file <STARTUP.A51> supplied with the compiler and added during link time. From this file it can be seen that all memory variables are setup and initialized. Looking at this assembler code, if big xdata arrays and constants are setup it will take a while to do so. Only four bytes in external memory were set to a value, but even after removing them it still did not work. What I have done is not to initialize any variable in the definition of it but rather later, just before running the main program. This then also allow me to control what must happen and the possibility of a watchdog reset is eliminated, because the watchdog will be stopped before that. This seems to work well, but I still don't know why the startup code got stuck!
After removing all variable initialization from the start up code, all the start up code is doing now is to fill the internal memory from 7fh to 0h with 0, setup the stack pointer and get out. This works well!
Paste your startup code.
You can modify your startup code to initialize (or de-initialize) any peripheral if you want.
What I have done is not to initialize any variable in the definition of it but rather later, just before running the main program. That cannot make much of a difference. XDATA variables are always of static storage duration, and such variables are always initialized to something, regardless of whether there's an initializer in the definition or not. If you don't supply one, the initializer is zero by default.
So you've only switched those variables from being, effectively, initialized via a big memcpy() from ROM to RAM, to a big memset(). That's at most a factor of two faster itself, and at lesst 50% slower in total, once your manual post-initialization has been done.
To really have an effect, you would have to disable the intialization mechanism centrally in the runtime environment. And the place for doing that is not in STARTUP.A51, but rather INIT.A51