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() ***/
/* clear FACCERR flag */
FSTAT |= FSTAT_FACCERR_MASK_UI8;
Above is wrong. Oring FSTAT with anything will write '1' to FCBEF bit if FCBEF is already set. Effectively it is attempt to launch flash command. Since flash erase/write sequence is most likely violated, error flag will be reset back to '1'...
For DZ128 Address should be wider than 16 bits integer.
DZ128.
What is the best and correct way to set up a 24 bit
pointer to a flash array in adress 0x48000,
and then write a byte to the adress to start a sector erase.
Thanks,
Anders
Hi,
thank you for helping. Ok so I was wrong with shifting, that shouldn´t happen. Do you agree with my code fundamentally ?
I mean should the code work regarding your suggested changes ?
I feel it´s pretty hard to get into this stuff when you never did flash programming routines before
Thank you guys,
Best regards,
Simon
Yes, it's possible to use LAP, although I have been doing it with pages until now.
I didn't have a thorough look at your code, just one obvious mistake that caught my eye. Shouldn't you be right shifting?
/* set LAP ( Linear Address Pointer ) to desired location */LAP0 = 0xFF & Address;
LAP1 = 0XFF & ( Address << 8 );
LAP2 = 0xFF & ( Address << 16 );