查看: 7199|回复: 6

[S12] 关于XS128写P_flash的问题

[复制链接]

该用户从未签到

1

主题

6

帖子

0

新手上路

Rank: 1

积分
13
最后登录
1970-1-1
发表于 2010-5-18 11:24:43 | 显示全部楼层 |阅读模式
 
我想在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寄存器的值,发现不是。。比较郁闷了。
 
求高人解决。。
小弟也没什么积分。刚刚建的账户,如果你也是新手,可以和我一起交流。
如果你是达人,期待解决
 
 
 
我知道答案 目前已有5人回答
回复

使用道具 举报

该用户从未签到

1

主题

6

帖子

0

新手上路

Rank: 1

积分
13
最后登录
1970-1-1
 楼主| 发表于 2010-5-18 11:26:02 | 显示全部楼层

RE:关于XS128写P_flash的问题

补充一下,其实Write_P_Flash(0xee)的参数没什么实际意义。。
就调试的时候曾今用到而已。。
  • TA的每日心情
    难过
    2021-12-15 16:01
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]初来乍到

    305

    主题

    4701

    帖子

    0

    中级会员

    Rank: 3Rank: 3

    积分
    377
    最后登录
    2023-8-16
    发表于 2010-5-19 15:31:15 | 显示全部楼层

    RE:关于XS128写P_flash的问题

    您好,我需要看一下技术手册,现在这个问题比较多,我抽时间为大家找写关于这方面的资料。
    该会员没有填写今日想说内容.
  • TA的每日心情
    难过
    2021-12-15 16:01
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]初来乍到

    305

    主题

    4701

    帖子

    0

    中级会员

    Rank: 3Rank: 3

    积分
    377
    最后登录
    2023-8-16
    发表于 2010-5-19 16:17:48 | 显示全部楼层

    RE:关于XS128写P_flash的问题

    请问你是对同一地址进行2次操作吗?
    flash操作注意事项:
    1、只能写入1次,如果需要重新写入,就要对flash进行擦除才能写入;
    2、flash地址要按照格式书写,一般为32位的;
    3、flash命令格式要按照手册上面的说明来操作。
    该会员没有填写今日想说内容.

    该用户从未签到

    1

    主题

    6

    帖子

    0

    新手上路

    Rank: 1

    积分
    13
    最后登录
    1970-1-1
     楼主| 发表于 2010-5-23 19:01:43 | 显示全部楼层

    RE:关于XS128写P_flash的问题

    没有对同样一个地址区域重写。。
    这个我肯定。。
    命令格式我也是一一对应着看着做的。
    不过还是没能成功,不清楚是哪里疏忽了。
  • TA的每日心情
    难过
    2021-12-15 16:01
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]初来乍到

    305

    主题

    4701

    帖子

    0

    中级会员

    Rank: 3Rank: 3

    积分
    377
    最后登录
    2023-8-16
    发表于 2010-6-1 11:35:27 | 显示全部楼层

    RE:关于XS128写P_flash的问题

    操作以前,一定要关闭写FLASH操作保护标志位。写完以后,开启保护。
    该会员没有填写今日想说内容.

    该用户从未签到

    11

    主题

    37

    帖子

    0

    新手上路

    Rank: 1

    积分
    96
    最后登录
    1970-1-1
    发表于 2013-3-1 13:55:33 | 显示全部楼层

    RE:关于XS128写P_flash的问题

    你是怎样判断你写的对与不对的?
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-7-20 00:05 , Processed in 0.100690 second(s), 27 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表