Hello, I am working on a Bootloader project using CAN communication with MC9S12XS64.
We are currently using interrupts for CAN and are working on a project using Process expert.
For my next flash programming task, I tested the XS series' P flash example code and my code that applied it.
Code:
------------------------------------------------------------------------
UINT8 PFlash_EraseSector(UINT32 address)
{
while((FSTAT & FSTAT_CCIF_MASK) == 0); //wait if command in progress
FSTAT = 0x30; //clear ACCERR and PVIOL
FCCOBIX = 0x00;
FCCOB = 0x0A00 | ((address & 0x007F0000)>>16);
FCCOBIX = 0x01;
FCCOB = (address & 0x0000FFF8);
FSTAT = 0x80; //launch command
while((FSTAT & FSTAT_CCIF_MASK) == 0); //wait for done
if((FSTAT & (FSTAT_ACCERR_MASK | FSTAT_FPVIOL_MASK)) != 0)
return FlashEraseError;
else
return noErr;
}
UINT8 PFlash_EraseSectorBySector(UINT32 addr_l, UINT32 addr_h)
{
UINT32 Address;
UINT8 Error;
for(Address = addr_l; Address < addr_h; Address += FLASH_SECTOR_SIZE)
{
Error = PFlash_EraseSector(Address);
if(Error != noErr)
return(Error);
}
return(noErr);
}
void Memory_Write(void)
{
if(u8BootPhraseRcvd == 1) // If a complete booth phrase was received
{
u8BootPhraseRcvd = 0;
if(Verify_Phrase_Checksum()) // Check that phrase checksum matches
{
if(!u8flashErased) // the flash hasn't been erased, erase it
{
PFlash_EraseSectorBySector(0x7F0000, 0x7FEFDF); // Jump to RAM and Erase Flash, return to Flash when done.
u8flashErased = 1; //Indicate that flash has been erased
} ..... ellipsis .....
---------------------------------------------------------------------
The code compiles fine.
Debug and run in hiwave.
When the specified CAN msg is sent and the requirements are met,
PFlash_EraseSectorBySector (0x7F0000, 0x7FEFDFUL) is executed.
Afterwards, the results were confirmed through real-time debugging in hiwave.
FlashEraseError occurs in the error checking code of the example code.
During PFlash_EraseSector(UINT32 address)
FSTAT = 0x80; //launch command
while((FSTAT & FSTAT_CCIF_MASK) == 0); //wait for done
If I run the code without it, it runs without an error, but I don't know if this is correct.
I'd like to know what the problem is and how to make it work properly.