DSP.rar

  • PUDN用户
    了解作者
  • C/C++
    开发工具
  • 1KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 2
    下载次数
  • 2016-10-04 14:49
    上传日期
把写好的二进制文件写入DSP板子上的FLASH中实现FLASH的烧写
DSP.rar
  • DSP.c
    5.3KB
内容介绍
#include<stdio.h> void EraseChip(); void WriteByte(unsigned int Addr,unsigned char Val); void WriteIsOver(); unsigned char WriteIsOver2( volatile unsigned char *addr ); char ReadByte(unsigned int Addr); void Reset_FLash( void ); void WriteByte2(unsigned int Addr,unsigned char Val); #define FlashMap1BaseAddr 0x400000 /*polling bit*/ #define Data_Polling_Bit 0x80 /* d7 = 1 */ #define Toggle_Bit 0x40 /* d6 = 1 */ #define Hangup_Bit 0x20 /* d5 = 1 TimeOut*/ #define Pass_Flag 0 #define Fail_Flag 1 unsigned char ret; main() { FILE *fp; char *ptr=(char *)0x809800; unsigned int i; int codelengthstart,codelengthend,codelength; char filename[128]; i = Read_ID(); printf("FLASH ID is 0x%x\n",i); printf("Clearing FLASH...\n"); EraseChip(); printf("Erased.\n"); printf("Please enter the BIN filename:\n"); scanf("%s",filename); fp = fopen(filename,"rb"); if(fp == NULL)exit(0); fseek(fp,0,SEEK_END); codelengthend = (int)ftell(fp); fseek(fp,0x0,SEEK_SET); codelengthstart = (int)ftell(fp); codelength=codelengthend-codelengthstart; for(i=0;i<codelength;i++) { fread(ptr,1,1,fp); WriteByte(i,*ptr); } printf("OK.\n"); printf("read0 %x \n", ReadByte(0)); printf("read1 %x \n", ReadByte(1)); printf("read2 %x \n", ReadByte(2)); printf("read3 %x \n", ReadByte(3)); printf("read4 %x \n", ReadByte(4)); printf("read5 %x \n", ReadByte(5)); printf("read6 %x \n", ReadByte(6)); printf("read7 %x \n", ReadByte(7)); for(;;); } void EraseSector(unsigned int SectorAddr) { *(volatile unsigned char*)(FlashMap1BaseAddr + 0xaaa) = 0xaa; *(volatile unsigned char*)(FlashMap1BaseAddr + 0x555) = 0x55; *(volatile unsigned char*)(FlashMap1BaseAddr + 0xaaa) = 0x80; *(volatile unsigned char*)(FlashMap1BaseAddr + 0xaaa) = 0xaa; *(volatile unsigned char*)(FlashMap1BaseAddr + 0x555) = 0x55; *(volatile unsigned char*)(FlashMap1BaseAddr + SectorAddr) = 0x30; WriteIsOver(); } int Read_ID(void) { int CurrentToggleBit,i; for(i=0;i<0x10;i++); *(volatile unsigned char*)(FlashMap1BaseAddr + 0xaaa) = 0xaa; for(i=0;i<0x10;i++); *(volatile unsigned char*)(FlashMap1BaseAddr + 0x555) = 0x55; for(i=0;i<0x10;i++); *(volatile unsigned char*)(FlashMap1BaseAddr + 0xaaa) = 0x90; for(i=0;i<0x10;i++); CurrentToggleBit = (*(volatile unsigned char*)FlashMap1BaseAddr); for(i=0;i<0x10;i++); return (CurrentToggleBit); } void EraseChip() { volatile unsigned char* FlashAddr; *(volatile unsigned char*)(FlashMap1BaseAddr + 0xaaa) = 0xaa; *(volatile unsigned char*)(FlashMap1BaseAddr + 0x555) = 0x55; *(volatile unsigned char*)(FlashMap1BaseAddr + 0xaaa) = 0x80; *(volatile unsigned char*)(FlashMap1BaseAddr + 0xaaa) = 0xaa; *(volatile unsigned char*)(FlashMap1BaseAddr + 0x555) = 0x55; *(volatile unsigned char*)(FlashMap1BaseAddr + 0xaaa) = 0x10; FlashAddr = (volatile unsigned char*)FlashMap1BaseAddr; WriteIsOver2(FlashAddr); } void WriteByte(unsigned int Addr,unsigned char Val) { volatile unsigned char* FlashAddr; *(volatile unsigned char*)(FlashMap1BaseAddr + 0xaaa) = 0xaa; *(volatile unsigned char*)(FlashMap1BaseAddr + 0x555) = 0x55; *(volatile unsigned char*)(FlashMap1BaseAddr + 0xaaa) = 0xa0; *(volatile unsigned char*)(FlashMap1BaseAddr + Addr) = Val; FlashAddr = (volatile unsigned char*)(FlashMap1BaseAddr + Addr); WriteIsOver2(FlashAddr); } void WriteByte2(unsigned int Addr,unsigned char Val) { volatile unsigned char* FlashAddr; *(volatile unsigned char*)(FlashMap1BaseAddr + 0xaaa) = 0xaa; *(volatile unsigned char*)(FlashMap1BaseAddr + 0x555) = 0x55; *(volatile unsigned char*)(FlashMap1BaseAddr + 0xaaa) = 0x20; *(volatile unsigned char*)(FlashMap1BaseAddr) = 0xa0; *(volatile unsigned char*)(FlashMap1BaseAddr + Addr) = Val; FlashAddr = (volatile unsigned char*)(FlashMap1BaseAddr + Addr); WriteIsOver2(FlashAddr); } void WriteIsOver() { unsigned int i; unsigned char LastToggleBit,CurrentToggleBit; LastToggleBit = (*(volatile unsigned char*)FlashMap1BaseAddr) & 0x40; CurrentToggleBit = (*(volatile unsigned char*)FlashMap1BaseAddr) & 0x40; for(i = 0; ; i++) { LastToggleBit = CurrentToggleBit; CurrentToggleBit = (*(volatile unsigned char*)FlashMap1BaseAddr) & 0x40; if(LastToggleBit == CurrentToggleBit) break; } } unsigned char WriteIsOver2( volatile unsigned char *addr ) { unsigned char Toggle_data,Read_data; Toggle_data = *addr & Toggle_Bit; do { if(((Read_data = *addr) & Toggle_Bit) == Toggle_data) break; Toggle_data = Read_data & Toggle_Bit; }while((Read_data & Hangup_Bit) != Hangup_Bit); Toggle_data = *addr & Toggle_Bit; if(((Read_data = *addr) & Toggle_Bit) != Toggle_data) { ret = Fail_Flag; return (Fail_Flag); } else { ret = Pass_Flag; return (Pass_Flag); } } char ReadByte(unsigned int Addr) { unsigned char Val; Val = *(volatile unsigned char*)(FlashMap1BaseAddr + Addr); return Val; } void Reset_FLash( void ) { *(volatile unsigned char*)(FlashMap1BaseAddr) = 0xF0; }
评论
    相关推荐
    • dsp flash烧写工具
      主要用于dsp 固化程序,读flash。主要针对6416,其他型号可以参考修改。
    • DSP 5509A 的 FLASH 烧写工具
      自认为 比 DSP 自带 FlashBurn 还好的 FLASH 烧写工具。 1. 程序版权 马福禄 西安交通大学机械学院 QQ:50647258 maxrun@sohu.com 2. 免责声明 本程序是作者本人做项目时开发的,他人可免费使用, 但要...
    • dsp6000烧写FLASH
      让你不再为不能把DSP程序烧写进FLASH发愁
    • DSP FLASH烧写解决方案
      解决了常见的FLASH烧写问题,让你更好的理解FLASH.
    • DSP C6455 flash烧写工程
      C6455的flash烧写程序,里面有步骤详解,先生成数组文件,然后将数组文件烧写到Flash中,傻瓜式教程,步骤已经优化了,3.3上完美运行。用了很多次,屡次不爽~
    • DSP5416烧写FLASH程序
      自己编写的FLASH烧写程序,对初学者有很大的帮助
    • DSP 28335 Flash烧写例程
      绝对的,本人板子上跑的,初学者可以看看,有意义的
    • DSP串口烧写所需软件.rar
      DSP串口烧写所需软件,包括hex2000.exe\jre-1_5_0-windows-i586.exe\C2Prog
    • 如何烧写DSP6713的BootLoader
      烧写DSP6713的BootLoader例程与讲解,简单易懂直接运行
    • DSP C6455 flash烧写工程
      C6455的flash烧写程序,里面有步骤详解,先生成数组文件,然后将数组文件烧写到Flash中,傻瓜式教程,步骤已经优化了,3.3上完美运行。用了很多次,屡次不爽~