在线时间0 小时
UID187727
注册时间2010-2-7
NXP金币0
该用户从未签到
新手上路

- 积分
- 13
- 最后登录
- 1970-1-1
|
我想在XS128的P_flash上写点数据。。
在认真看了技术文档之后,我写了如下代码。。
void delayflash(uint j)
{
uchar i;
for(;j>0;j--)
for(i=20;i>0;i--);
}
void Start_Command()
{
FSTAT_CCIF = 1;//To start the command.
}
void Wait_Complete_Command()
{
while(FSTAT_CCIF == 0);
}
void Pre_Start()
{
if(FCLKDIV_FDIVLD ==0)
FCLKDIV |= 0x0f; //设置时钟分频,外部晶振为16Mhz
}
void Write_P_Flash(uint value)
{
uchar count=0;
Pre_Start();
if(FSTAT_CCIF)
{
if(FSTAT_ACCERR)
{
FSTAT_ACCERR = 1;
delayflash(100);
}
if(FSTAT_FPVIOL)
{
FSTAT_FPVIOL = 1;
delayflash(100);
}
FCCOBIX=0;
FCCOB=0X067F;
FCCOBIX =1;
FCCOB = des_addr;
FCCOBIX=2;
FCCOB=0xee;
FCCOBIX=3;
FCCOB=0xcc;
FCCOBIX=4;
FCCOB=0xdd;
FCCOBIX=5;
FCCOB=0xaa;
des_addr+=8;
Start_Command();
Wait_Complete_Command();
}
}
void main()
{
..........
des_addr=0x4000;
Write_P_Flash(0xee);
Write_P_Flash(0xdd);
..........
}
参考了pdf文档中的如下描述
关于选频。。
When the FCLKDIV register is written, the FDIVLD bit is set automatically. If the FDIVLD bit is 0, the
FCLKDIV register has not been written since the last reset. If the FCLKDIV register has not been written,
any Flash program or erase command loaded during a command write sequence will not execute and the
ACCERR bit in the FSTAT register will set.
关于写命令。。
NVM command mode uses the indexed FCCOB register to provide a command code and its relevant
parameters to the Memory Controller. The user first sets up all required FCCOB fields and then initiates
the command’s execution by writing a 1 to the CCIF bit in the FSTAT register (a 1 written by the user
clears the CCIF command completion flag to 0). When the user clears the CCIF bit in the FSTAT register
all FCCOB parameter fields are locked and cannot be changed by the user until the command completes
(as evidenced by the Memory Controller returning CCIF to 1). Some commands return information to the
FCCOB register array.
关于写命令前的注意事项。。
Before launching a command, the ACCERR and FPVIOL bits in the FSTAT register must be clear (see
Section 19.3.2.7) and the CCIF flag should be tested to determine the status of the current command write
sequence. If CCIF is 0, the previous command write sequence is still active, a new command write
sequence cannot be started, and all writes to the FCCOB register are ignored.
附个操作流程大图:
https://www.nxpic.org.cn/file:///D:/software/QQ/Users/328324873/Image/8W4JL8ZQ{M9VHWXVS5A04XN.jpg
现在的问题是。。执行一次写操作没问题,(无论是单步调试还是让程序自由运行)
可是如果让他执行两次写操作。。那么。。
再第二次执行 Start_Command()后FSTAT寄存器的MGSTAT[1:0]两位全部至1,并导致写失败。
关于FSTAT的MGSTAT在写flash操作时的介绍
[img]https://www.nxpic.org.cn/file:///D:/software/QQ/Users/328324873/Image/$[F`946UW0IT0BIO@`JZOWK.jpg[/img]
还一度以为是flash地址保护的原因,选了不同的地址段,并查看了FPROT寄存器的值,发现不是。。比较郁闷了。
求高人解决。。
小弟也没什么积分。刚刚建的账户,如果你也是新手,可以和我一起交流。
如果你是达人,期待解决
|
|