AnsweredAssumed Answered

HCS12XEQ384 - Internal Flash - Programming (S12XFTM384K2V1)

Question asked by Sascha Pfengler on Aug 8, 2016
Latest reply on Aug 11, 2016 by Sascha Pfengler

Hi there!

 

I'm having trouble programming words into the global address space.

Programming / Triggering of write operations shall be done "in the background" by utilising the "Command Status ISR".

First of all I used Processor Expert to generate FLASH1_Init() and added to it from there on.

 

As soon as FLASH1_Init() completes, the Command Status ISR is called non-stop.

Why is that? Do I need to disable Command Status Complete Interrupts within the ISR?

 

Now when I skip these ISRs by stepping during Debug, I call enHalFlashInternalWriteWord(), which sadly doesn't work either: When I reach "Schreiben einleiten" to initiate the programming (FSTAT |= FSTAT_CCIF_MASK;), ACCERR is still active, so setting CCIF (which should clear the flag) does nothing. (see attached file or code example)

 

Input Parameters: 0x7C0000 (Address), 0 (Data).

 

By the way: How does the Flash-Controller know, how many Words I want to program, starting with the Address?

For example: If I leave FCCOB3-5 empty, would the controller still attempt to write Zeros into the addresses related to FCCOB3-5?

 

Do I need to consider switching to program execution in RAM?

Is there a far easier way to program internal Flash that I am overlooking?

I tried to understand the "current" AN2720, however it appears to be outdated for S12XE / couldn't get it to work.

 

This is an excerpt from my code:

 

    /* Moegliche Fehler rücksetzen */

    FSTAT |= FSTAT_ACCERR_MASK + FSTAT_FPVIOL_MASK;

 

    /* FCCOB - Register vorbereiten */

    /** FCCOB0 */

    FCCOBIX  = 0u;

    FCCOB    = ((uint16)(((uint16)EN_P_FLASH_CMD_PROGRAM_P_FLASH) << 8)); /* Schreib-Kommando in FCCOB-MSB schreiben */

    FCCOB   |= (uint16)(u32ParAddrGlob >> 16);                            /* Oberste 7 Bit der glob. 23 Bit-Adresse  */

    /** FCCOB1 */

    FCCOBIX  = 1u;

    FCCOB    = (uint16)u32ParAddrGlob; /* Unterste 16 Bit der 23 Bit-Adresse */

    /** FCCOB2 */

    FCCOBIX  = 2u;

    FCCOB    = u16ParData;

 

    /* Schreiben einleiten */

    FSTAT |= FSTAT_CCIF_MASK;

 

    // Warten bis Schreiben abgeschlossen

    while(!M_BO_FLASH_CONTROLLER_IDLE);

 

    // Ergebnis stimmt nicht

    if((*far_pu16Dest) != u16ParData)

    {

      enRet = EN_HAL_RET_ERR_FLASH_DATA_INVALID;

    }

 

Thanks for Your time!

Original Attachment has been moved to: Flash_Internal.c.zip

Outcomes