How to read data from internal flash by using C90TFS library

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

How to read data from internal flash by using C90TFS library

跳至解决方案
2,236 次查看
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?

标签 (1)
0 项奖励
回复
1 解答
1,467 次查看
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

在原帖中查看解决方案

2 回复数
1,468 次查看
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

1,467 次查看
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 项奖励
回复