Sebastian Paul

bootloader - problem while erasing and writing flash sector

Discussion created by Sebastian Paul on Feb 10, 2012
Latest reply on Feb 20, 2012 by Robert Bailey

Hi @all,

i have one project with CAN-bootloader code and app code in it. I have read a lot about the risks by don't seperating bootloader and app in different projects and i have changed every failure source in my C code project... i thought so.

 

Afters reset bootloader starts and when receiving special CAN-FLASH-messages, it starts flashing sector by sector. That works fine for the first 15 sectors! But then it stops and break up. When i debug step by step, i see that the bootloader assembler code which is generated by the compiler (my project is written in C), jumps to an address in application segment that i have erased before!

What the hell is this?!? Why did he do that? All my bootloader C-functions are placed in seperate segment by #pragma CODE_SEG assignment.

Anyway the bootloader code jumps out of its segment in the app segment. Here is the code where it crashes:

//in my Boot.c#pragma CODE_SEG BOOT_CODE#pragma DATA_SEG BOOT_DATA#pragma CONST_SEG BOOT_CONST#pragma STRING_SEG BOOT_STRING //therefor everything that follows belongs to bootloader segment: BOOTLOADER = READ_ONLY 0xD600 TO 0xF9FF;...void FirmwareCanRx(...)  {  unsigned long id_var = 0; //Hilfsvariable zur ID Umrechnung  id_var = CANRIDR0;  id_var <<= 8;       //here assembler code jumps to CODE_SEG application  id_var |= CANRIDR1;  ...  }//////////////////////////////////////////////////////////Debug Code and have a look at generated assembler code//////////////////////////////////////////////////////////C code:id_var = 0CANRIDR0; //to assembler code:LDA _CANRIDR.Dword //PC=DCAF -> BOOTLOADER (everything above 0xD600)TAX                //PC=DCB2STHX  3,SP         //PC=DCB3CLRX               //PC=DCB6STHX  1,SP         //PC=DCB7//C code://id_var <<= 8;//to assembler code:TSX                //PC=DCBAAIX #0             //PC=DCBBLDA #0x08          //PC=DCBDJSR _LLSL          //PC=DCBFJSR _ENTER_UNARY_L //PC=C589 -> error, jump to position below BOOTLOADERSTX ,X             //PC=C1D3STX ,X             //PC=C1D4STX ,X             //PC=C1D5STX ,X             //PC=C1D6...

 I don't know, why the compiler generates such an assembler code. It looks like a code optimization problem for me. Therefor i go to the projects options (Edit->Standard settings->Compiler for HC08) and "disable optimizations" by "-O0" Command line argument. But my code still crashes at this point.

 

Can anyone help me? I am pretty shure that this is a compiler or preprozessor problem... by optimization or linking or whatever... but i don't know what to do next.

Outcomes