help for  the sample code of  MPC5606B DFLASH erase ,write and read function

cancel
Showing results for 
Search instead for 
Did you mean: 

help for  the sample code of  MPC5606B DFLASH erase ,write and read function

680 Views
明伟张
Contributor III

I need to erase,write and read a specific address in DLASH;

thanks for supplying the sample code of MPC5606B DFLASH erase,write and read function;

Labels (1)
0 Kudos
4 Replies

66 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport

I have similar simple example for MPC5675K. Although different device, principle is the same. Pay attention to C function Program_Data_FLASH. Code is stored here:

Example MPC5675K Data_flash_program_simple CW210

Hope it helps

0 Kudos

66 Views
远灿谌
Contributor I

hello,David.

I'm going to control the DFLASH by using MPC5606B. 

The erase  and write  function of  DFLASH is ok with your code,but I get some problems in the read function.

For example:

I have written 0x12345678 to the 0x00800000(i get this address from the datasheet,the LLK0),and the value has been checked . However,when i read the value to a variation from the 0x0080000, it will cause a Data Storage interrupt handler,i have no idea to solve it.

the code of read function as below:

                u32 dflash_temp;
                u32 *dflash_addr=(u32 *)0x00800000;
                dflash_temp = *dflash_addr;       //only use a point to read the value from 0x00800000

aleilei00@foxmail.com      this is my e-mail,

I'm looking forward to your reply.

0 Kudos

66 Views
明伟张
Contributor III

Hi David

please check the sample code, function is called,the address of Dflash as follows:

pastedImage_0.png

thanks!

0 Kudos

66 Views
明伟张
Contributor III

thanks;DFLASH read and write function is OK;but erase funtion is not OK;

the code as below:

uint8_t DFls_Erase(uint16_t SectorNm)

{

  uint32_t *AnyAddress;

  AnyAddress = (uint32_t *)0x0;

    /* password to unlock space array */

    #define FLASH_LMLR_PASSWORD   0xA1A11111  // Low/Mid

    #define FLASH_HLR_PASSWORD    0xB2B22222  // High

    #define FLASH_SLMLR_PASSWORD  0xC3C33333  // Secondary Low/Mid

   

    /* enable low address space */

    DFLASH.LML.R = FLASH_LMLR_PASSWORD;

    DFLASH.LML.R = 0x00000000;              // unlock all LLK3-LLK0

    DFLASH.SLL.R = FLASH_SLMLR_PASSWORD;

    DFLASH.SLL.R = 0x00000000;              // unlock all SLLK3-SLLK0

    /* step1. erase B0F0 (0x00800000-0x00803FFF) */

    DFLASH.MCR.B.ERS = 1;                   // select operation (erase)

    DFLASH.LMS.R = SectorNm;                // select B0F0 block

    //*((unsigned int*) p_test) = 0xFFFFFFFF; // interlock write

    *AnyAddress = 0xFFFFFFFF;               /* write to any address in flash*/

    DFLASH.MCR.B.EHV = 1;                   // operation start (erase)

    while(DFLASH.MCR.B.DONE == 0){};        // wait for DONE

    DFLASH.MCR.B.EHV = 0;                   // operation end

    DFLASH.MCR.B.ERS = 0;                   // deselect operation

   

  if(DFLASH.MCR.B.PEG == 1U)  /* check erase flash successfully*/

  return E_OK;

  else

     return E_NOT_OK;

}

0 Kudos