S12XDT flash erase/write issue

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S12XDT flash erase/write issue

716 Views
almqvist
Contributor I

Hi, I have been working on a flash loader for S12XDT. The code I've been using as a base was originally written for, and runs fine on a S12C. While porting the code I've ran into a problem, let me try to explain.

 

I erase a flash sector using the following function:

 

sbyte FlashEraseSector(word *__pptr pAddress){ static word* address; address = (word *)pAddress; FSTAT = FSTAT_ACCERR | FSTAT_PVIOL; // clear errors (*address) = 0xFFFF;     // Dummy store to page to be erased FCMD = SECTOR_ERASE; (void)DoOnStack(pAddress); if (FSTAT_ACCERR) {  return ACCESS_ERROR; } else if (FSTAT_PVIOL) {  return PROTECTION_ERROR; } else {  return PASS; }}

 

 This "seems" to work just well and a passed result is returned. But when I want to confirm that the memory is in fact erased I found out that it's not. This is the function used to write a word to flash, and it returns flash not erased.

 

 

#define FLASH_ERASED_WORD  0xFFFFu
sbyte FlashWriteWord(word *__pptr pAddress, word data){ FSTAT = FSTAT_PVIOL | FSTAT_ACCERR;  if(*pAddress != FLASH_ERASED_WORD)  {  return FLASH_NOT_ERASED;// It returns here when I run... } else if(*pAddress == data) {   return PASS; } else {  *pAddress = data;        // Store desired data to address being programmed  FCMD = WORD_PROGRAM;     // Store programming command in FCMD  (void)DoOnStack(pAddress);    // just passed for PPAGE  if (FSTAT_ACCERR)  {   return ACCESS_ERROR;  }  else if (FSTAT_PVIOL)  {   return PROTECTION_ERROR;  }  else  {   if (*pAddress == data)   {    return PASS;   }   else   {    return FAIL;   }  } }}

 

I also checked while debugging and find that the memory is not been erased. The memory I try to erase and write to is within paged flash (page F8 to FE).

 

Any clue as to why the memory is no erased? I don't have alot of experience with S12C/S12XDT so I can't quite figure out how to tackle this problem.

Labels (1)
0 Kudos
Reply
2 Replies

519 Views
kef
Specialist I

Don't know if this will help, but please fix this bug:

 

    FSTAT = FSTAT_ACCERR_MASK | FSTAT_PVIOL_MASK; // clear errors

 

0 Kudos
Reply

519 Views
almqvist
Contributor I

Ah right, thanks for pointing it out.

 

I still have the same behaviour when trying to erase/write however. Is there something in particular I need to consider when working with the S12X?

0 Kudos
Reply