AnsweredAssumed Answered

HCS12XA - Flash Mass Erase (Bootloader)

Question asked by sebasira on Mar 22, 2012
Latest reply on Mar 23, 2012 by kef

Hello, I'm porting the bootloader from AN3275 to the HCS12XA.

For now, the only problem that I've encountered is that I don't understand what does or should the bootloader erase. And that's why I cannot modify the mass erase routine in order to work with the S12XA. I know it should erase everything but the bootloader memory area.

 

I don't want it to be portable for any other devices, and will only be need for the S12XA256, so every control regarding block size, pages per block, etc won't be needed.

Block size is 1024 (0x400) can anyone guide/help me on how to modify this routine in order to do that?

 

Here's the code that set the addresses to be erased, that's what I want to modify.

void near vfnFlashMassEraseCmd(void){    /*     * Total Flash Pages     * MEMSIZ1 (1:0) = 0:0  128K = 8 Pages (0<<3)     * MEMSIZ1 (1:0) = 0:1  256K = 16Pages (1<<3)     * MEMSIZ1 (1:0) = 1:0  512K = 32Pages (2<<3)     * MEMSIZ1 (1:0) = 1:1 1024K = 64Pages (3<<3)     *     * As the HCS12XA does not have the MEMSIZ1 then its defined as "1" becasuse     * it has 256KB of Flash Memory     */    uint16 li16BlockZeroStart,li16BootAddressPointer,li16PageAddressPointer;    uint8 li8FlashPagesPerBlock = ui8fnFindFlashPagesPerBlock();    uint8 li8Page = 0x3f - li8FlashPagesPerBlock;    uint8 li8BlockSearch = 8<<(MEMSIZ1 & 3);        li8BlockSearch = (uint8) (li8BlockSearch/li8FlashPagesPerBlock);  //Number of Blocks        /***** PART 1 *****/
    li16BlockZeroStart = 0x3f -  li8FlashPagesPerBlock;    /*Mass Erase Blocks from Block 1 To Block N, Block 0 must be erased page by page*/    while (--li8BlockSearch){      gi32FlashAddressH = ((uint16) (0x3f - (li8FlashPagesPerBlock * li8BlockSearch)));      gi32FlashAddressL = 0x8000;      gi8FlashBlock = li8BlockSearch;      gi16FlashDataCounter = 1;      if (vfnFlash_Cmd(FMassErase)){        // SEND ERROR MESSAGE        return;      }    }            /***** PART 2 *****/    gi8FlashBlock = 0;    for(gi32FlashAddress=0xEF00;gi32FlashAddressL>=0xC000;gi32FlashAddressL-=0x200){      gi16FlashDataCounter = 1;      if (vfnFlash_Cmd(FErase)){        // SEND ERROR MESSAGE        return;      }    }            /***** PART 3 *****/    PPAGE=0x3E;    li16PageAddressPointer=0xBFFF;    li16BootAddressPointer = 0xFFFF;    while(PPAGE>li8Page){      if(*(uint8 *)(li16BootAddressPointer) != *(uint8 *)(li16PageAddressPointer)){       /* Erase Paged Memory */        gi32FlashAddressH = PPAGE;        for(gi32FlashAddressL=0xBF00;gi32FlashAddressL>=0x8000;gi32FlashAddressL-=0x200){          gi16FlashDataCounter = 1;          if (vfnFlash_Cmd(FErase)){            // SEND ERROR MESSAGE            return;          }        }        PPAGE--;        li16PageAddressPointer = 0xC000;        li16BootAddressPointer = 0x0000;      }      li16BootAddressPointer--;      li16PageAddressPointer--;      /***** PART 4 *****/      if(li16BootAddressPointer<0xF000){        PPAGE = 0x36;      }      }    FlashSectorBackup();    FlashSectorRestore();  }

 

I point out four parts, wich I think are the "skeleton" of the routine, I'd like to know what does/should do each part so I can understand it better.

 

Thanks for taking the time to read!!

In case anyone want/need the entire project, I'll attach it here.

Outcomes