做并行引导,生成了.hex文件以后,转换为.data文件,可是flash读写程序死活都不工作, 哪位高手帮忙看看哪里出错了?
这是主程序boot_5402.c
/*****************/ /*boot_5402.c */ /*主程序 */ /*flash的读写操作*/
#include "port_5402.h" #include "boot_5402.h" #include "port_func.h" #include "boot_dat.h"
u16 val;
void main() { u16 i; init_board(); //初始化5402 flash_ready(); //使FLASH进入正常工作状态 flash_erase(); //整片擦除FLASH for(i=0;i<=0x418;i++) //写入boot表,0x41a是flashdata的长度 { flash_write((0x8000+i),flash_data); //从0x8000写到0x841a } flash_write(0xffff,0x8000); //向FLASH的0xFFFF写入0x8000 val=flash_read(0xffff);//读出FLASH的0xFFFF地址的值 } 下面是flash的读写子程序port_func.h
//对FLASH操作的各种函数 u16 u_tmp; u16 u_dq7; u16 u_dq61; u16 u_dq62;
void flash_ready()//将FLASH调整为正常的读写的工作状态 { u_tmp=*(u16*)(0xfffe); *(u16*)(0xd555)=0xaa;//向0xd555写入0xaa u_tmp=*(u16*)(0xfffe);
*(u16*)(0xaaaa)=0x55;//向0xaaaa写入0x55 u_tmp=*(u16*)(0xfffe);
*(u16*)(0xd555)=0xf0;//向0xd555写入0xf0 u_tmp=*(u16*)(0xfffe); }
void flash_erase()//将FLASH整片擦除 { u_tmp=portfffe; portd555=0xaa;//向0xd555写入0xaa u_tmp=portfffe;
portaaaa=0x55;//向0xaaaa写入0x55 u_tmp=portfffe;
portd555=0x80;//向0xd555写入0x80 u_tmp=portfffe;
portd555=0xaa;//向0xd555写入0xaa u_tmp=portfffe;
portaaaa=0x55;//向0xaaaa写入0x55 u_tmp=portfffe;
portd555=0x10;//向0xd555写入0x10 u_tmp=portfffe;
do{ portfffe=0x11; u_dq7=portd555; }while((u_dq7&0x0080)==0x0000); //判断DQ7,为1时,表示完成擦除,跳出循环;为0时,继续等待 }
void flash_write(u16 u_addr,u16 u_val) //向FLASH中写入一个字 { u_tmp=*(u16*)(0xfffe); *(u16*)(0xd555)=0xaa;//向0xd555写入0xaa u_tmp=*(u16*)(0xfffe);
*(u16*)(0xaaaa)=0x55;//向0xaaaa写入0x55 u_tmp=*(u16*)(0xfffe);
*(u16*)(0xd555)=0xa0;//向0xd555写入0xa0 u_tmp=*(u16*)(0xfffe);
*(u16*)(u_addr)=u_val;//写入编程数据 u_tmp=*(u16*)(0xfffe);
do { *(u16*)(0xfffe)=0x11; u_dq61=*(u16*)(0x8000); *(u16*)(0xfffe)=0x11;
u_dq62=*(u16*)(0x8000); *(u16*)(0xfffe)=0x11; }while((u_dq61&0x0040)!=(u_dq62&0x0040)); //判断DQ6的值是否稳定,稳定了,退出;不稳定,循环等待 }
u16 flash_read(u16 u_addr) //从FLASH中读出一个字 { u16 u_val; *(u16*)(0xfffe)=0x11; u_val=*(u16*)(u_addr); *(u16*)(0xfffe)=0x11; return(u_val);
}
[此贴子已经被作者于2006-1-9 17:03:05编辑过]
[此贴子已经被作者于2006-1-9 17:10:19编辑过] |