Simon Bauernfeind

Writing to Flash with LAP on S08DZ128

Discussion created by Simon Bauernfeind on Aug 2, 2010
Latest reply on Dec 23, 2011 by Anders Johansson

HI there,

 I´m writing a Flashdriver to be able to write data to the flash memory from a bootloader application. I read a lot about that and searched though the forum but unfortunately didn´t gest the desired results. So my question is, if I can read / write to the complete flash memory by using the LAP register ? The documentation says yes, but it seems to be inconsitent sometimes.

What about the PPAGE method ? Are there pro´s and con´s between both methods ? Anyway, I placed my code below, so maybe anyone can help me. Thank you very much in advance for helping !

 

void RAM_Routine( tUI16 Address, tUI8 Value, tUI8 Command )
{

    /* clear FACCERR flag */
    FSTAT |= FSTAT_FACCERR_MASK_UI8;

#ifdef MMU_USAGE == LAP_ADDRESSING

    /* set LAP ( Linear Address Pointer ) to desired location */
    LAP0 = 0xFF & Address;
    LAP1 = 0XFF & ( Address << 8 );
    LAP2 = 0xFF & ( Address << 16 );

    /*
    _asm("PSHA");
    _asm("LDA @Address:LINEAR_HIGH");
    _asm("STA LAP2");
    _asm("LDA @Address:LINEAR_MID");
    _asm("STA LAP1");
    _asm("LDA @Address:LINEAR_LOW");
    _asm("STA LAP0");
    _asm("PULA");
    */
    /* increment LAP register value / step to next byte in the flash */
    LB = Value;

#elif MMU_USAGE == PAGED
    /* TODO incrementing of data pointer */

    /* step to next byte in the flash */
#else
    
    /* write data to the block to erase */
    *(tUI8*)Address = Value;
#endif /*MMU_USAGE*/

    /* load command */
    FCMD |= Command;

    /* set FCBEF to start the command */
    FSTAT |= FSTAT_FCBEF_MASK_UI8;

    /* wait for four cycles before checking FSTAT register */
    (void)FCDIV;

    /*was the operation succesful?*/
    if( !( FSTAT & FSTAT_ERROR_MASK_UI8 ) )
    {
      /*wait for FCCF flag*/
      while( !( FSTAT & FSTAT_FCCF_MASK_UI8 ) )
      {
          /*change this to the system used function to reset the watchdog*/
          SERVICE_WATCHDOG();
      }
    }

  return;         
}

/*** end of RAM_Routine() ***/

Outcomes