Hi guys,
I have a Bootloader and application files in project with part of S912G128MLL,now i cant erase and write flash with Bootloader.
this is my app .prm file:
**************************************************************************************
NAMES END
HEXFILE bootloader.s19
SEGMENTS
RAM = READ_WRITE 0x2000 TO 0x37ff;
DFLASH = READ_WRITE 0x000400 TO 0x0013FF;
ROM_1400 = READ_ONLY 0x1400 TO 0x1FFF;
ROM_4000 = READ_ONLY 0x4000 TO 0x7F7F;
ROM_C000 = READ_ONLY 0xC000 TO 0xEFDF;
PAGE_08 = READ_ONLY 0x088000 TO 0x08BFFF;
PAGE_09 = READ_ONLY 0x098000 TO 0x09BFFF;
PAGE_0A = READ_ONLY 0x0A8000 TO 0x0ABFFF;
PAGE_0B = READ_ONLY 0x0B8000 TO 0x0BBFFF;
PAGE_0C = READ_ONLY 0x0C8000 TO 0x0C93FF;
PAGE_0C_A000 = READ_ONLY 0x0CA000 TO 0x0CBFFF;
PAGE_0E = READ_ONLY 0x0E8000 TO 0x0EBFFF;
END
PLACEMENT
_PRESTART,
STARTUP,
ROM_VAR,
STRINGS,
VIRTUAL_TABLE_SEGMENT,
NON_BANKED,
COPY
INTO ROM_C000;
DEFAULT_ROM INTO PAGE_08, PAGE_09, PAGE_0A, PAGE_0B, PAGE_0C, PAGE_0C_A000, PAGE_0E ;
SSTACK,
DEFAULT_RAM INTO RAM;
END
ENTRIES
END
STACKSIZE 0x100
*****************************************************************************
this is my Bootloader .prm file:
*****************************************************************************
INIT _BootStart
NAMES END
SEGMENTS
RAM = READ_WRITE 0x3800 TO 0x3CFF;
RAM_CODE_SEG = READ_ONLY 0xFD00 TO 0xFEFF RELOCATE_TO 0x3D00;
ROM_F000 = READ_ONLY 0xF000 TO 0xFCFF;
END
PLACEMENT
ROM_VAR,
STRINGS,
DEFAULT_ROM,
NON_BANKED INTO ROM_F000;
DEFAULT_RAM INTO RAM;
RAM_CODE INTO RAM_CODE_SEG;
END
ENTRIES
flash_array
END
STACKSIZE 0x100
VECTOR 0 _BootStart
VECTOR 1 _BootStart
VECTOR 2 _BootStart
*************************************************************************************************************
and this is my erase code in bootloader :
************************************************************************************************************
UINT8 PFlash_EraseSector(UINT32 address)
{
while((FSTAT & FSTAT_CCIF_MASK) == 0);
FSTAT = 0x30;
FCCOBIX = 0x00;
FCCOB = 0x0A00 | ((address & 0x00080000)>>16);
FCCOBIX = 0x01;
FCCOB = (address & 0x0000FFF8);
FSTAT = 0x80;
while((FSTAT & FSTAT_CCIF_MASK) == 0);
if((FSTAT & (FSTAT_ACCERR_MASK | FSTAT_FPVIOL_MASK)) != 0)
return FlashEraseError;
else
return noErr;
}
/******************************************************************************/
UINT8 PFlash_EraseSectorBySector(UINT32 addr_l, UINT32 addr_h) // addr_l=0x088000 , addr_h=0x08EFDF
{
UINT32 Address;
UINT8 Error;
for(Address = addr_l; Address < addr_h; Address += FLASH_SECTOR_SIZE) // FLASH_SECTOR_SIZE=200
{
Error = PFlash_EraseSector(Address);
if(Error != noErr)
return(Error);
}
return(noErr);
}
.
.
.
Please tell me where is my wrong
TNX
Hi,
I don't see how do you make code executing from RAM while flash is being erased/programmed. The problem is flash is not readable while it is being erased/programmed (as well not readable while backdoor access key is being verified, etc), but CPU has to read instructions somehow... So you need to move code execution to RAM/EEPROM/another flash bank at least for execution of these two lines:
FSTAT = 0x80; // launch flash command
while((FSTAT & FSTAT_CCIF_MASK) == 0); // wait until done
As well you need to a) disable interrupts or b) move interrupt vectors table and all interrupt service routines to RAM or other storage which is readable while flash commands are in progress.
Edward
hi Edward
It's a little dumb for me.
If possible please explain by example or explain more.
Thank you for your post.
mojtaba.
Please be more specific what is not clear for you. How to move code to RAM? Simple:
in *.prm file add placement for code in RAM:
PLACEMENT /* here all predefined and user segments are placed into the SEGMENTS defined above. */
RAMCODE INTO RAM;
...
END
Fix you erase and program routines like this:
#pragma CODE_SEG __NEAR_SEG RAMCODE
void DoFlashCmd(void) {
//DisableInterrupts;
FSTAT = 0x80;
while((FSTAT & FSTAT_CCIF_MASK) == 0);
//EnableInterrupts;
}
#pragma CODE_SEG DEFAULT
UINT8 PFlash_EraseSector(UINT32 address)
{
while((FSTAT & FSTAT_CCIF_MASK) == 0);
FSTAT = 0x30;
FCCOBIX = 0x00;
FCCOB = 0x0A00 | ((address & 0x00080000)>>16);
FCCOBIX = 0x01;
FCCOB = (address & 0x0000FFF8);
DoFlashCmd();
if((FSTAT & (FSTAT_ACCERR_MASK | FSTAT_FPVIOL_MASK)) != 0)
return FlashEraseError;
else
return noErr;
}
Thanks for your reply .I'll check it
Best Regards,
Mojtaba