Table of Contents        Previous topic       Next topic       

C/C++ COMPILER->Compiler Support Files->Startup Files

If you create a new ColdFire C project using the Embedded Development Studio it will optional create a number of files for configuring the ColdFire chip.  These files will be named startup.asm, xstdsys.c and xstdsys.h.  You will probably need to modify these files to suit your particular target system, but do not change there names otherwise the Embedded Development Studio will not recognise them.

Startup.asm contains symbols that will be set by the Embedded Development Studio in accordance with the settings that you choose for the compiler and linker.  Xstdsys.c and Xstdsys.h are variant specific and will be automatically swapped for different versions if you change the ColdFire variant in Embedded Development Studio.  Startup.asm will also be switched if you change between the MCF5407 (which has two SRAM banks) and any other variant (which will have only one SRAM bank).

Startup.asm contains the entry point to your program.  There are two possible entry methods.  One is via a reset and the other is via a command from a debug monitor or debugger which sets the program counter to the entry point address and starts execution.

Startup.asm chooses the entry point type depending on the value of symbol __NoRom.  Symbol __NoRom is set to one if you have selected Code and Data in Ram in the Embedded Development Studio linker settings, otherwise it is set to zero.  If __NoRom is zero, then startup.asm configures the program for entry via a reset. If __NoRom is one then startup.asm configures the program for entry via a debug command.  You can examine startup.asm to see how this is done.

For a reset entry point, startup.asm also setup MBAR and RAMBAR (or RAMBAR0 and RAMBAR1 for the MCF5407) using assembler symbols defined in xstdsys.h.  It will set the stack pointer so that it uses SRAM and then call two C functions init_chip_selects() and init_dram() which are defined in xstdsys.c.  It will then reset the stack pointer to the __STACK section and set VBR to the address that you have specified for the Interrupt Vector Offset in the Embedded Development Studio compiler settings.  It will then carry out some initialisation that is required for the C environment set the status register to enable all interrupt and then call main().

In xstdsys.h, you may wish to change the addresses for MBAR and SRAM.   You may also wish to change the CLKIN frequency and PCLK so that you can use BCLKO to calculate settings for baud rates etc.  (Note that PCLK only affects BCLKO for the MCF5307.)

If you examine xstdsys.h, you will see that it defines a variant symbol _CF5206, _CF5206E, _CF5307, _CF5307A, _CF5307B or _CF5407 and then includes xsim.h.  Xsim.h contains definitions of structures that can be used to access the SIM.  You can see two of these structures being used in xstdsys.c where g_pCHIPSELECT and g_pDRAM are used to access the chip select module and DRAM controller.  Other structures can be accessed using g_pSYSTEM, g_pINTERRUPT,  g_pTIMER0, g_pTIMER1, g_pUART0, g_pUART1, g_pPARALLELPORT, g_pI2C, g_pDMA0, g_pDMA1, g_pDMA2 and g_pDMA3.  To use these pointers you simply include xstdsys.h in your C file.

Xsim.h is located in <installation directory>\ColdFire\include.  The quickest way to open if from the Embedded Development Studio is to open xstdsys.h, right mouse click on the line containing #include <xsim.h> and select the Open command near the bottom of the context menu.  You can then see how the variant symbol is used to setup the various structures appropriate to the specific chip.  There is no difference between _CF5307A and CF5307B but for all other variants there are.  (CF5307 is for mask H55J, _CF5307A is for mask 1J20C and _CF5307B is for mask 2J20C).