AnsweredAssumed Answered

About Flash Program on Internal Flash (MPC5674F)

Question asked by Hyenongi Jeong on May 19, 2017
Latest reply on May 22, 2017 by Hyenongi Jeong

Hi,

 

I have a problem with the flash program.
When writing data to multiple addresses, it is shown as below.
I also attached my code. The code proceeded in the order of the datasheet.
What's wrong with my code?

 

main()

{
uint32_t ulDATA[10], i;
for(i=0;i<10;i++)
    ulDATA[i] = 0x11111111*(i+1);

ulErrCode = DRV_Flash_Write(0x10000, &ulDATA[0], 10);
}

 

uint32_t DRV_Flash_Write(uint32_t _u32Addr, uint32_t *_pData, uint32_t _u32WLen)
{
uint32_t i, errCode;

/* unlock L4~L9 in flash array A */
FLASH_A.LMLR.R = FLASH_LMLR_PASSWORD;
FLASH_A.LMLR.R = 0x0013000F;
FLASH_A.SLMLR.R = FLASH_SLMLR_PASSWORD;
FLASH_A.SLMLR.R = 0x0013000F;

// Step 1
FLASH_A.MCR.B.PGM = 1;
// Step 2 & 3
for(i=0;i<_u32WLen;i++)
{
    *(vuint32_t *)(_u32Addr+i*4) = *_pData+i; /* interlock write */
    // Step 4
    FLASH_A.MCR.B.EHV = 1; /* start programming */
    // Step 5
    while(FLASH_A.MCR.B.DONE == 0){}; /* wait for done */
    // Step 6
    if(FLASH_A.MCR.B.PGM != 1)
    {
        // Error
        errCode = 7;
    }
    // Step 7
    FLASH_A.MCR.B.EHV = 0;
    // Step 8 // to do : go to step 2
}
// Step 9
FLASH_A.MCR.B.PGM = 0;
if(FLASH_A.MCR.B.PEG == 0)
return 2; /* return error if PEG was not set */

return errCode;
}

Outcomes