开始2812 Flash编程首先得准备3个文件:Flash2812_API_V210.lib,Flash281x_API_Config.h和Flash281x_API_Library.h。一个库文件和两个头文件,Flash2812_API_V210.lib和Flash281x_API_Library.h这两个文件不需要修改,但是配置文件Flash281x_API_Config.h需要修改如下:
//#define CPU_RATE 6.667L // for a 150MHz CPU clock speed (SYSCLKOUT)
//#define CPU_RATE 7.143L // for a 140MHz CPU clock speed (SYSCLKOUT)
//#define CPU_RATE 8.333L // for a 120MHz CPU clock speed (SYSCLKOUT)
//#define CPU_RATE 10.000L // for a 100MHz CPU clock speed (SYSCLKOUT)
//#define CPU_RATE 13.330L // for a 75MHz CPU clock speed (SYSCLKOUT)
//#define CPU_RATE 20.000L // for a 50MHz CPU clock speed (SYSCLKOUT)
#define CPU_RATE 33.333L // for a 30MHz CPU clock speed (SYSCLKOUT)
//#define CPU_RATE 41.667L // for a 24MHz CPU clock speed (SYSCLKOUT)
//#define CPU_RATE 50.000L // for a 20MHz CPU clock speed (SYSCLKOUT)
//#define CPU_RATE 66.667L // for a 15MHz CPU clock speed (SYSCLKOUT)
//#define CPU_RATE 100.000L // for a 10MHz CPU clock speed (SYSCLKOUT)
看你板子的SYSCLKOUT,我的为30M
修改完成后,我三个文件导入到工程中,开始时遇到了
warning:typedef name has already been decleared (with same type)
最后发现是Flash281x_API_Library.h中的
typedef int int16;
typedef long int32;
typedef unsigned int Uint16;
typedef unsigned long Uint32;
typedef float float32;
typedef long double float64;
这些定义重复定义了,屏蔽掉就可以
然后设置自己所需要的PLLCR寄存器的值,我的输入晶振30M,SYSCLKOUT 30M,PLL=2;
在直接编程前先做Flash编程频率测试,用Flash_ToggleTest实现;
用示波器测试频率大概在10K左右;
现在你可以使用Flash API函数编程了;
我没有把程序放到Flash里面,只是用仿真器在RAM里面运行,下面是我的测试程序:
#include "DSP28_Device.h"
#include "stdio.h"
#define GPAMUX (volatile Uint16*)0x000070C0 // GPIO A mux
#define GPATOGGLE (volatile Uint16*)0x000070E3 // GPIO A toggle
#define GPIOA0 (Uint16)0x0001 // Pin 1mask
/*--- Global variables used to interface to the flash routines */
FLASH_ST EraseStatus;
FLASH_ST ProgStatus;
FLASH_ST VerifyStatus;
float32 VersionFloat;
Uint16 VersionHex;
unsigned int Send_Flag;
unsigned int i;
char *strg="abcd";
unsigned int buff[8];
unsigned int Buffer[8];
unsigned int *Flash_ptr=(unsigned int *)0x3E0000;
Uint16 Status;
unsigned int Length=8;
void DelayNmSec(int N)
{
unsigned int j;
while(N--)
for(j=0;j<65535;j++);
}
void flash_reads(unsigned int *addr,unsigned int *ptr,unsigned long length)
{
unsigned long i;
for(i = 0; i < length; i++)
{
*(ptr + i) =*(addr+i);
}
}
void main(void)
{
/*初始化系统*/
InitSysCtrl();
/*关中断*/
DINT;
IER = 0x0000;
IFR = 0x0000;
/*初始化PIE中断*/
InitPieCtrl();
/*初始化PIE中断矢量表*/
InitPieVectTable();
/*初始化SCIA寄存器*/
InitSci();
for(i = 0; i < 8; i++)
{
Sci_VarRx[i] = 0;
Sci_VarTx[i] = 0;
}
Rx=Sci_VarRx;
Tx=Sci_VarTx;
Send_Flag = 0;
rx_length=0;
add=0;
length=9;
/*设置中断服务程序入口地址*/
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TXAINT = &SCITXINTA_ISR;
PieVectTable.RXAINT = &SCIRXINTA_ISR;
EDIS; // This is needed to disable write to EALLOW protected registers
/*开中断*/
IER |= M_INT9;
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
Flash_CPUScaleFactor=SCALE_FACTOR;
Flash_CallbackPtr=NULL;
VersionFloat = Flash_APIVersion();
VersionHex = Flash_APIVersionHex();
//Flash_ToggleTest(GPAMUX,GPATOGGLE,GPIOA0);
for(i=0;i<8;i++)
{
Buffer[i] = 0x8000+i;
}
Status = Flash_Erase(SECTORG,&EraseStatus);
if(Status == STATUS_SUCCESS)
{
Status = Flash_Program(Flash_ptr,Buffer,Length,&ProgStatus);
if(Status == STATUS_SUCCESS)
{
Status = Flash_Verify(Flash_ptr,Buffer,Length,&VerifyStatus);
if(Status == STATUS_SUCCESS)
flash_reads(Flash_ptr,buff,8);
}
}
while(1)
{
}
}
//===========================================================================
// No more.
//===========================================================================
阅读(4443) | 评论(1) | 转发(0) |