Flash memory read/write

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

Flash memory read/write

1,522 Views
eunseokjung
Contributor II

Hi all,

I'm using MK10 series. I have some problem when i am coding the FlexNVM memory part.

What i want to do is that partition FlexNVM and save data in data flash region.

Below code is shown my FlexMem part.

It doesn't work what i annouced..

It starts from FlexMem_Init(void) function. And flow to erase function - partition function - Program longword function - read function.

I want to write '202' in the address 6FFFC.

Could you tell me what is the wrong?

Thanks.

/

*

* FlexMem.c

*

*  Created on: Feb 10, 2015

*      Author: ESJ

*/

#include <MK10D7.h>

#include <string.h>     //memset

#include "GLB_DataTypes.h"   //type define

#include "FlexMem.h"

uint8_t flashCommandArray[10];

uint16_t error_flash_code=0;  //0bit:partition error(already partitioned)

void FlexMem_Init(void);

int16_t partition_flash(int16_t eeprom_size_code, int16_t dflash_size_code,uint8_t* flashCommandArray);

void FlashCommandSequence (uint8_t* flashCommandArray);

void FlashEraseAllBlock (uint8_t *flashCommandArray);

void FlashProgramLongword(uint32_t address,uint32_t value);

void ReadResource (uint32_t address);

uint16_t i1, i2, i3, i4;

void FlexMem_Init(void)

{

    memset((uint8_t*)flashCommandArray, 0x00, sizeof(flashCommandArray));

    error_flash_code=MSG_FLASH_NORMAL;

    FlashEraseAllBlock(flashCommandArray);

    partition_flash(EEPROM_128, DFLASH_SIZE_08K, flashCommandArray);

    FlashProgramLongword(0x86FFFC, 202);

    ReadResource(0x86FFFC);

  

     i1=FTFL_FCCOB7; //for checking the saved value

     i2=FTFL_FCCOB6;

     i3=FTFL_FCCOB5;

     i4=FTFL_FCCOB4;

    

}

int16_t partition_flash(int16_t eeprom_size_code, int16_t dflash_size_code,uint8_t* flashCommandArray)

{

    *(flashCommandArray + 0) = 0x80;

    *(flashCommandArray + 4) = 0x30|eeprom_size_code; //FlexNVM is divided

    *(flashCommandArray + 5) = dflash_size_code; // FlexNVM is divide

    FlashCommandSequence(flashCommandArray);

    return 1;

}

void FlashCommandSequence (uint8_t * flashCommandArray )

{

    while(!(FTFL_FSTAT & FTFL_FSTAT_CCIF_MASK)){  //always check to write flash register

    }

    FTFL_FSTAT = (FTFL_FSTAT_RDCOLERR_MASK|FTFL_FSTAT_ACCERR_MASK|FTFL_FSTAT_FPVIOL_MASK);

    FTFL_FCCOB0 = *(flashCommandArray + 0);

    FTFL_FCCOB1 = *(flashCommandArray + 1);

    FTFL_FCCOB2 = *(flashCommandArray + 2);

    FTFL_FCCOB3 = *(flashCommandArray + 3);

    FTFL_FCCOB4 = *(flashCommandArray + 4);

    FTFL_FCCOB5 = *(flashCommandArray + 5);

    FTFL_FCCOB6 = *(flashCommandArray + 6);

    FTFL_FCCOB7 = *(flashCommandArray + 7);

    FTFL_FCCOB8 = *(flashCommandArray + 8);

    FTFL_FCCOB9 = *(flashCommandArray + 9);

    /* clear CCIF bit , activate command*/

    FTFL_FSTAT = FTFL_FSTAT_CCIF_MASK;

    while(!(FTFL_FSTAT & FTFL_FSTAT_CCIF_MASK)) {

        /* wait till CCIF bit is set */

    }

}

void FlashEraseAllBlock (uint8_t *flashCommandArray)

{

    *(flashCommandArray + 0)=0x44;

    FlashCommandSequence(flashCommandArray);

}

void FlashProgramLongword(uint32_t destination,uint32_t value)

{

  *(flashCommandArray + 0) = 0x06;

  *(flashCommandArray + 1) = (uint8_t)(destination >> 16);

  *(flashCommandArray + 2) = (uint8_t)((destination >> 8) & 0xFF);

  *(flashCommandArray + 3) = (uint8_t)(destination & 0xFF);

  *(flashCommandArray + 4) = (uint8_t)((value >> 24) &0xff);

  *(flashCommandArray + 5) = (uint8_t)((value >> 16) &0xff);

  *(flashCommandArray + 6) = (uint8_t)((value >> 8) &0xff);

  *(flashCommandArray + 7) = (uint8_t)((value >> 0) &0xff);

  FlashCommandSequence(flashCommandArray);

}

void ReadResource (uint32_t address)  //data Flash read(IFC)

{

    *(flashCommandArray+0) = 0x03; //read resource command

    *(flashCommandArray+1) = ((uint8_t)(address >> 16)); //23bit 0:Program Flash, 1:DataFlash

    *(flashCommandArray+2) = ((uint8_t)((address >> 8) & 0xFF));

    *(flashCommandArray+3) = ((uint8_t)(address & 0xFF));

    *(flashCommandArray+8) = 0x00; //0: IFR,1:Version ID

    FlashCommandSequence(flashCommandArray);

    *(flashCommandArray+0)= FTFL_FCCOB7; //addr   data (IFR:FC[3:0] : DEPART)

    *(flashCommandArray+1)= FTFL_FCCOB6; //addr+1 data (IFR:FD[3:0] : EESIZE)

    *(flashCommandArray+2)= FTFL_FCCOB5; //addr+2 data

    *(flashCommandArray+3)= FTFL_FCCOB4; //addr+3 data

}

0 Kudos
1 Reply

722 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Eunseok:

Are you still in doubt about this?

I see you had a discussion in a different thread:

MK10 series P-Flash question about Read/Write for bootload

Instead of trying to understand AN2295 code, which is a custom code made for the bootloader, I would recommend you to download the Flash Driver C90TFS. Here is the download link:

http://cache.freescale.com/files/32bit/software/C90TFS_FLASH_DRIVER.exe

This package comes with examples and a user guide so you can integrate it to your project and use the Flash functions. This way you avoid suffering trying to understand the appnote software.

And also a couple application notes which should definitely help you about C90TFS driver and Flex Memory:

http://cache.freescale.com/files/32bit/doc/app_note/AN4695.pdf

http://cache.freescale.com/files/32bit/doc/app_note/AN4282.pdf

Let us know of any questions.


Regards!,
Jorge Gonzalez

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos