One thing which came out after a great deal of suffering is that if you want C code to work on the microcontroller without the debugger, you have to change the startup code. If you look into the default template created for C code by codewarrior, you will see that the Project.prm file contains the line
VECTOR 0 _Startup /* Reset vector: this is the default entry point for an application. */
This references the file Start08.c, which contains assloads of ugly mixed assembler/C code punctuated by #defines switching various things. What it does, apparently, is to take a symbol table generated by the linker and use it to initialize various segments in RAM upon startup.
Somehow, this process is bunged up by not having the debugger loaded. Maybe the symbol table it requires is only loaded into RAM and thus lost on restart. Or something.
Anyway, the important point is to understand that this _Startup function is actually unnecessary. All it does for you is initialize your variables. This probably is not required.
The only possible case where it might matter is if you use static variables, where it might be what initializes them. But I don't know yet about that.
What I do know is that my code works and compiles and runs quite well without _Startup, or the entire Start08.c file.
What you do is this:
#pragma NO_EXIT void interrupt VectorNumber_Vreset _Startup(void) { SOPT = 0x22; __asm ldhx #$107F + 1 // Initialize Stack Pointer __asm txs __asm jmp main } #pragma NO_EXIT void main(void) // jumped to by _Startup() { ....
note: if you want your code to run at the same speed, you also have to set up the clock generator to what the bootloader does. Otherwise it will run much slower by default.
I will upload that code soon.
The clock setup code is below. You must use this so that the C code will run at the same rate as tested in debugger mode.
/***************************************************************************/
// call this to set up the clock speed when not in debugger
/***************************************************************************/
void setup_Clock(void) {
ICGC1 = 0x38;
ICGC2 = 0x78;
ICGC1_OSCSTEN = 1; //have clock still running during stop3 mode
}
Just call the setup_Clock() function once in the main before the infinite while/for loop.