Code Templates for GB60

C Startup Code for CodeWarrior


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:

  • Remove the VECTOR 0 _Startup line from Project.prm
  • Remove the file Start08.c from your project.
  • Insert the following code into the file containing main():
#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() 
  { 
  ....
  • You're done! That's all that's required to make C code run without the debugger!

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.

 
Back to top
projects/securouter/codetemplates.txt · Last modified: 2009/01/29 21:29 by jazzman
 
 
chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0