How to read data from internal flash by using C90TFS library

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

How to read data from internal flash by using C90TFS library

Jump to solution
1,296 Views
alexshephard
Contributor I

I am trying to read data from Pflash and Dflash from MK20DX256 by using C90TFS library in KSDK 1.3.

But I cannot find read function in the library. Then how do you guys read data from the flash?

Labels (1)
0 Kudos
1 Solution
527 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Alex,

Regarding your question, as you know that the ARM architecture uses the normalized address space for the program/data flash, SRAM and peripheral, special commands are required to erase/program flash, but you can read a flash address as you read a RAM address.

you can read flash or RAM using the following macro based on the data width you access.

#define READ8(address)              ((uint8_t)(*(vuint8_t*)(address)))
#define READ16(address)             ((uint16_t)(*(vuint16_t*)(address)))
#define READ32(address)             ((uint32_t)(*(vuint32_t*)(address)))

for example, you can use the following code to access flash no matter whether the flash save data or code.

uint16_t value, i, *pSrc, *pDest;

pSrc=0xxxxxxxx;

value=READ16(pSrc);

pSrc++;

BR

XiangJun Rong

View solution in original post

2 Replies
528 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Alex,

Regarding your question, as you know that the ARM architecture uses the normalized address space for the program/data flash, SRAM and peripheral, special commands are required to erase/program flash, but you can read a flash address as you read a RAM address.

you can read flash or RAM using the following macro based on the data width you access.

#define READ8(address)              ((uint8_t)(*(vuint8_t*)(address)))
#define READ16(address)             ((uint16_t)(*(vuint16_t*)(address)))
#define READ32(address)             ((uint32_t)(*(vuint32_t*)(address)))

for example, you can use the following code to access flash no matter whether the flash save data or code.

uint16_t value, i, *pSrc, *pDest;

pSrc=0xxxxxxxx;

value=READ16(pSrc);

pSrc++;

BR

XiangJun Rong

527 Views
calebrust
Contributor III

I was trying for several hours to read program flash using the FlashReadResource() function.  After reading this post I tried the READ32() macro, and it just worked.  Yay!

Sidenote:

It's strange to me that the C90TFS library has 2 functions to read the P-Flash IFR(FlashReadResource, and ReadOnce), but neither can read the basic program flash.  If you try to pass in an absolute address, e.g. 0x7E000 for a 512KB MKW2x chip, the FlashReadResource function will return an access error (ACCERR).  After lots of reading I realized that the access error is because these functions are only supposed to access IFR memory (see Table 35-44 of the MKW2x reference manual for valid local address ranges). 

Thanks for the info XiangJun Rong!

0 Kudos