Jim Donelson

Flashing Made Simple Min Ram Redux HCS08 Family

Discussion created by Jim Donelson on Feb 28, 2008
Latest reply on Apr 26, 2013 by Carl Norman
Well, thanks to the help of several people, and the realization that the app. notes sort of misrepresented certain aspects of flashing, we now have it down to 10 bytes of ram.

It turns out that in non-burst mode, the only code that must be in ram is writing the start command bit and the wait loop, which cut another 8 bytes out of ram.

If you notice in the asm code, that does not go in ram, I seeming loaded X with 'page' when I did not need to. This is not an oversight, as it is bad design to "know" where the compiler puts things, as other compilers may or may not pass things in this way, or this compiler may change.

According to the app. note that this was taken from (HCS08RUG) this is for the HCS08 family.
It started out at 59 bytes in ram.

Code:
volatile unsigned char PGM[10]  = {  0xc7,0x18,0x25,     // sta       FSTAT  0x44,               // lsra -  delay and convert to FCCF bit0xc5,0x18,0x25,     // Bit fstat0x27,0xfb,          // BEQ *-30x81                // RTS}; byte FlashErasePage(word page) {      asm {      TPA         ; Get status to A      PSHA        ; Save current status        SEI         ; Disable interrupts      LDA  #0x30      STA  FSTAT  ; Clear FACCERR & FPVIOL flags      LDX  page      STA ,X      ; Save the data      LDA  #$40   ; Erase command      STA  FCMD      LDA  #FSTAT_FCBEF_MASK      JSR  PGM      PULA        ; Restore previous status      TAP   }     if (FSTAT&0x30){                     //check to see if FACCERR or FVIOL are set    return 0xFF;                       //if so, error.   }      return 0;    }byte FlashProgramByte(word address, byte data) {      asm{      TPA        PSHA        ; Save current status        SEI         ; Disable interrupts      LDA  #0x30      STA  FSTAT  ; Clear FACCERR & FPVIOL flags      LDX  address      LDA  data      STA ,X      ; Save the data      LDA  #$20   ; Burn command      STA  FCMD      LDA  #FSTAT_FCBEF_MASK      JSR   PGM      PULA        ; Restore previous status      TAP   }       if (FSTAT&0x30){                     //check to see if FACCERR or FVIOL are set    return 0xFF;                         //if so, error.   }      return 0;    }

 


Outcomes