About Flash Program on Internal Flash (MPC5674F)

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

About Flash Program on Internal Flash (MPC5674F)

Jump to solution
1,191 Views
hyenongijeong
Contributor III

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?

FLASH_ERROR.png

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;
}

Tags (3)
1 Solution
938 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

from the reference manual:

pastedImage_1.png

You can't program two 32bit words within one double word (64bits) separately. It is necessary to write the data at once. Something like:

  FLASH_B.MCR.B.PGM = 1;     
  *(unsigned int *)0x000C0000 = 0xAABBCCDD;

  *(unsigned int *)0x000C0004 = 0x11223344;
  FLASH_B.MCR.B.EHV = 1;
  while(FLASH_B.MCR.B.DONE == 0){};
  FLASH_B.MCR.B.EHV = 0;
  FLASH_B.MCR.B.PGM = 0;

Regards,

Lukas

View solution in original post

2 Replies
939 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

from the reference manual:

pastedImage_1.png

You can't program two 32bit words within one double word (64bits) separately. It is necessary to write the data at once. Something like:

  FLASH_B.MCR.B.PGM = 1;     
  *(unsigned int *)0x000C0000 = 0xAABBCCDD;

  *(unsigned int *)0x000C0004 = 0x11223344;
  FLASH_B.MCR.B.EHV = 1;
  while(FLASH_B.MCR.B.DONE == 0){};
  FLASH_B.MCR.B.EHV = 0;
  FLASH_B.MCR.B.PGM = 0;

Regards,

Lukas

938 Views
hyenongijeong
Contributor III

Hi,

Thank you. The code has some error. my mistake.

Thank you for your response. 

Regards,

Henk

0 Kudos
Reply