金牌会员
 
- 积分
- 2689
- 威望
- 1401
- 贡献
- 718
- 兑换币
- 877
- 注册时间
- 2014-7-1
- 在线时间
- 285 小时
|
7#

楼主 |
发表于 2016-1-4 12:14:06
|
只看该作者
U8 Flash_readBUF(U16 sectNo,U16 offset,U16 cnt,U16 *bBuf)
{
U32 wAddr = 0;
wAddr = sectNo * 2048 + offset;
while (cnt--)
{
*bBuf++=*(UCHAR *)wAddr++;
}
return TRUE;
}
U8 Flash_writeBUF(U16 sectNo,U16 offset,U16 cnt,U16 buf[])
{
U32 size;
U32 destaddr;
union
{
U32 word;
U8 byte2[4];
} dest;
if(offset%4 != 0)
return 1; //参数设定错误,偏移量未对齐(4字节对齐)
// 设置写入命令
FTFL_FCCOB0 = PGM4;
destaddr = (U32)(sectNo*(1<<11) + offset);//计算地址
dest.word = destaddr;
for(size=0; size<cnt; size+=4, dest.word+=4, buf+=4)
{
// 设置目标地址
FTFL_FCCOB1 = dest.byte2[2];
FTFL_FCCOB2 = dest.byte2[1];
FTFL_FCCOB3 = dest.byte2[0];
// 拷贝数据
FTFL_FCCOB4 = buf[3];
FTFL_FCCOB5 = buf[2];
FTFL_FCCOB6 = buf[1];
FTFL_FCCOB7 = buf[0];
if(1 == Flash_cmd_launch())
return 2; //写入命令错误
}
return 0; //成功执行
}
|
|