AnsweredAssumed Answered

Problems with writing to internal flash memory

Question asked by Michael Weston on Jun 26, 2013
Latest reply on Jul 2, 2013 by Michael Weston

Hello,

 

I added a bootloader to my project and it does work but I am having some trouble with it.  I will explain and maybe there is something commonly known that I am just missing.  The microcontroller core used is the MC9S08GB60A in the MC13213 chip.

 

First, my bootloader is entirely custom except for using the file doonstack.asm provided by Freescale in one of their application packages.  It is 4KB in size, protected, and uses hardware vector relocation (I use no ISR in my bootloader for simplicity).  I have an onboard EEPROM that stores the new firmware to be flashed into the chip and a configuration area that the bootloader uses to decide if it should update or not.  This all works fine.  My bootloader and main app are two separate projects so no code sharing occurs.

 

The problem is that when I create one .S19 file with my main app and bootloader together, the flash routine in the bootloader will fail to successfully alter the flash at the same point every time.  If I build the bootloader and just send it alone over JTAG, it succeeds.  On some boards, it ALL just works fine and on others it won't flash unless freshly loaded over JTAG.

 

My CPU clock is the internal 8MHz one and FCDIV is set to (4000000L/200000L)-1 which equals 19.  I also tried 20 to slow it down a bit more.

 

My firmware starts at 0x1080 and packets of 64 bytes (generally two lines in the S-record file) are passed to the FlashProgBurst function.  I have tried erasing all areas of the chip below the bootloader first before flashing anything and I also tried a dynamic eraser that clears each block as it is needed.  For example, data starting at 0x1080 would erase the area designated as 0x1000 to 0x11FF and then flash those values. Data starting at 0x10C0 would erase nothing and then get flashed in.  0x1100 would erase nothing, etc. etc.  Data starting at 0x1200 would erase the area from 0x1200 to 0x13FF and then load the data in.  Most of the time, flashing fails when I write to 0x1200.  Trying to step through the bootloader using the JTAG debugger generally makes the flashing fail right at 0x1080 so I now use messages out through the UART to determine where things are failing.  Maybe the flash controller doesn't like the background interface running.

 

Am I understanding the memory map correctly?  According to the RM: "a high block of 59348 bytes (115 pages of 512 bytes each plus 1 page of 468 bytes) and a low block of 1920 bytes."  The low block is 1920 bytes but do I still erase it in 512 byte chunks or just send the erase command anywhere in this 1920 byte area?  I seem to get the best results sticking to 512 byte chunks with the boundaries assumed to begin at 0, then 512, 1024, etc.

 

Thanks for any help you can give,

 

 

Michael

Outcomes