Reading Flash stored variables..

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Reading Flash stored variables..

571 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ub3r on Mon Sep 16 21:13:14 MST 2013
Hi Guys,
Ive been experimenting with storing data in flash, and ive been useing the IAP commands to prepare and store data to flash memory as below:
However.. How do i read the stored data??

#ifdef __USE_CMSIS
#include "LPC13Uxx.h"
#endif

#include <cr_section_macros.h>
#include <NXP/crp.h>
#include "IAP.h"
#include <stdio.h>
// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;



/* Flash offset where the configuration is stored */
#define CONFIG_FLASH_OFFSET            0x1000
#define CONFIG_FLASH_SECTOR            (CONFIG_FLASH_OFFSET >> 12)
#define CONFIG_FLASH_SECTOR_SIZE    1

// TODO: insert other definitions and declarations here

static uint8_t demo_messg[] = "IAP flash data";
static uint8_t demo_messg2[64];

void writeDATA(void);
void readDATA(void);



int main(void)
{
writeDATA();
readDATA();

volatile int i = 0;

while(1)
{
i++;
}
}

void readDATA(void)
{

}

void writeDATA(void)
{
__e_iap_status iap_status;


    /* Prepare the sector for erase */
    iap_status = (__e_iap_status) u32IAP_PrepareSectors(CONFIG_FLASH_SECTOR,
            (CONFIG_FLASH_SECTOR + CONFIG_FLASH_SECTOR_SIZE));
    if (iap_status != CMD_SUCCESS) while(1);

    /* Erase the sector */
    iap_status = (__e_iap_status) u32IAP_EraseSectors(CONFIG_FLASH_SECTOR,
            (CONFIG_FLASH_SECTOR + CONFIG_FLASH_SECTOR_SIZE));
    if (iap_status != CMD_SUCCESS) while(1);

    /* Prepare the sector for writing */
    iap_status = (__e_iap_status) u32IAP_PrepareSectors(CONFIG_FLASH_SECTOR,
            (CONFIG_FLASH_SECTOR + CONFIG_FLASH_SECTOR_SIZE));
    if (iap_status != CMD_SUCCESS) while(1);

    /* write data to flash */
    iap_status = (__e_iap_status) u32IAP_CopyRAMToFlash(&demo_messg,
            (void *)CONFIG_FLASH_OFFSET, 256);
    if (iap_status != CMD_SUCCESS) while(1);
}
0 项奖励
回复
1 回复

433 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by usb10185 on Tue Sep 17 07:09:14 MST 2013
Hi,

You need to setup a pointer to the memory location of interest.
Have a look at some of the IAP Application notes and associated code for the various LPC parts, in there there is code that programs Flash via IAP and then does a compare. Exactly what you are looking for! Snip below....

/** The area will be erase and program */
#define FLASH_PROG_AREA_START       0x8000
/** The origin buffer on RAM */
#define BUFF_SIZE           1024

// Compare
  for ( i = 0; i < FLASH_PROG_AREA_SIZE/BUFF_SIZE; i++ )
  {
    ptr = (uint8_t*)(FLASH_PROG_AREA_START + i*BUFF_SIZE);
status =  Compare(ptr, buffer,BUFF_SIZE);
if(status != CMD_SUCCESS)
{
   _DBG("Compare memory failed with code is ");_DBD(status);_DBG_("");
       while(1);
}
  }
0 项奖励
回复