My mcu is S12XEQ.
I suppose that the XGATE thread codes must put into Flash page 0xE0,0xE1,so i try to find the keyword "#pragma" in the xgate.cxgate,but get nothing about it .
But in the map file,the thread function is already putted into Flash page 0xE0,0xE1.To me,the only track is keyword "XGATE_CODE",but i cann't find it's definition.
Is there something special processing to file xgate.cxgate?where can i get any meterials?
To put XGATE code to flash add this above your function(s):
#pragma CODE_SEG XGATE_CODE_FLASH
To make XGATE code executed from RAM use line below. Code will be placed to flash, copied from flash to RAM by startup routine and executed from RAM when called.
#pragma CODE_SEG XGATE_CODE_RAM
Where to place each routine depends on your requirements. Not enough RAM - put to flash, need better performance - put to RAM.
When you use Project Wizard to create new project you have 3 choices, put to RAM, to FLASH, RAM and FLASH. 3rd choice puts #pragma CONST_SEG prior to each function in generated xgate.cxgate. First two options produce different PRM files. Wizard choice "to RAM" places default XGATE_CODE placement into RAM, "to flash" choice makes XGATE_CODE placed to flash.
Hi,Edward.Thank you very much for you reply.
Now i have three questions:
1.CodeWarrior default put codes of xgate.cxgate to XGATE_CODE,is it right?
2.If XGATE_CODE is placed to RAM,codes will be copied to RAM by function _Startup(),or this should be done by user?
3.what's different between XGATE_CODE and XGATE_CODE_RAM?If XGATE_CODE is copied by _Startup(),who do this for XGATE_CODE_RAM?
1. Right.
2. Right, by _Startup()
3. Do you use #pragma to explicitly assign code to RAM or use default code placement (XGATE_CODE placement is specified to go to RAM in PRM), in both cases _Startup() will initialize code in RAM from flash. Of course in Project Wizard you should not choose minimal startup code over ANSI (standard) startup code. Only standard startup routine initializes everything.
Even if you specify placement for all you code lines, XGATE_CODE placement is sill important for XGATE library routines.
Even if i create a project by following the Project Wizard and choose the minimal startup code,there is a Start12.c.But in the official bootloader project,there is only a StartS12X.s,is this project created all by manually?If not,how to create a such project?
Where can i get more details about macros,such as XGATE_CODE...?
I try to make myself understand the function _Startup(),if there is anything help document exist,it will be very nice.
You need to choose ANSI startup (default setting). Minimal startup doesn't initialize RAM (zeroout bss section, initialize implicitly initialized variables, initialize code in RAM).
Do you use XGATE in bootloader? What for? Unless required bootloader startup routine may not initialize anything, jump from bootloader to application should go through applications _Startup.
_Startup() uses _startupData struct defined in library include folder, start12.h. nofZeroOuts specifies the number of zeroout areas, pZeroOut - array of zerout structs etc. _Startup initializes zerouout areas with zero, then uses copy down structs to initialize what has to be initialized from flash to RAM.
In the offcial bootloader's prm file,there is line:
RAM_CODE_SEG = READ_ONLY 0xFD00 TO 0xFEFF RELOCATE_TO 0x3D00
The keyword RELOCATE_TO tell compiler compile codes using address 0x3D00 but put to 0xFD00.
But is it neccessary?
In the official app project,just like "Simple SCI",there are codes put to RAM exist,but no keyword RELOCATE_TO.
It is much easier to place code to RAM without RELOCATE_TO and custom CopyCodeToRAM() routine. You need dedicated PLACEMENT to RAM for code. You can't place variables and code to the same PLACEMENT since this will lead to build errors. Once code is redirected using #pragma to your dedicated code in RAM placement, the rest will do _Startup(). Without this automatic initialization one needs to care to compile code for one address (think about absolute addressing), but place it to different address so that it lands in nonvolatile memory.
In AN4258 RELOCATE_TO is present in prm/Project.prm file. AN4258 SCI interrupt routine keeps running in RAM ro receive new data. Interrupt vectors table at top of RAM is set up in static void InterruptModuleSetup(void). Only one vector for SCI is initialized in RAM vectors table. So if you wish to abandon RELOCATE_TO usage edit PRM like this
SEGMENTS
//RAM = READ_WRITE 0x3900 TO 0x3CFF;
//RAM_CODE_SEG = READ_ONLY 0xFD00 TO 0xFEFF RELOCATE_TO 0x3D00;
//ROM_F000 = READ_ONLY 0xF000 TO 0xFCFF;
RAM = READ_WRITE 0x3900 TO 0x3EFF;
// no need to split RAM SEGMENT INTO dedicated pieces for code and RAM
ROM_F000 = READ_ONLY 0xF000 TO 0xFEFF;
..
PLACEMENT
// RAM_CODE INTO RAM_CODE_SEG;
RAM_CODE INTO RAM;
..
I misguided you in previous messages to use dedicated PLACEMENT for code, no, it should be dedicated SEGMENT for code. No, I was right previously, you need dedicated PLACEMENT's for code and variables, updated PRM mods above, sorry.
Then add default Start12.c, edit bootloaders StartS12X.s to jump to _Startup instead of main:
xref _Startup ; was xref main
...
jmp _Startup ; was jmp main
I just want to create a project like official bootloader project,cuase i don't know why it use the CopyCodeToRAM() rather than _Startup().
I will use XGATE to speed up communication speed to speed up the upgrade processing.Why does official bootloader not use XGATE?
Regarding CopyCodeToRAM(), I hink older linker+compiler perhaps didn't allow to place code in READ_WRITE segments or perhaps this method just wan't used.
I don't know what is official bootloader project.
Regarding speeding bootload up, bottleneck is flash erase and flash write times. First of all CPU can't execute from flash while it is being programmed/erased. So there are two choices: wait in small routine in RAM while flash erase/write completes, then continue. Or keep running in RAM *AND* receiving new data while flash is being erased/programmed, this way not wasting all flash program/erase time just for wait but also preload new data while flash is busy. XGATE won't help you with this, CPU still has plenty of executing time while flash programs/erases.
officail bootloader is from AN4258.