⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 burn with fill.c

📁 一个在DSP上执行的flash的烧写程序
💻 C
字号:
#include "ccblkfn.h"
#include "sysreg.h"

#include <sys\exception.h>
#include <cdefBF533.h>

#define pLight (volatile unsigned char *)0x20200000

#define pData (volatile unsigned short *)0x4000
#define pData_out (volatile unsigned short *) 0x7000


#define pFlashAStartAddress 		(volatile unsigned short *)0x20000000
#define pFlashBStartAddress 		(volatile unsigned short *)0x20100000

#define pFlashAUnlock1Address 		(volatile unsigned short *)(pFlashAStartAddress + 0x555)
#define pFlashAUnlock2Address 		(volatile unsigned short *)(pFlashAStartAddress + 0x2aa)
#define pFlashAManufacturerIDAddress 	(volatile unsigned short *)(pFlashAStartAddress + 0x00)
#define pFlashADeviceIDAddress 		(volatile unsigned short *)(pFlashAStartAddress + 0x01)

#define pFlashBUnlock1Address 		(volatile unsigned short *)(pFlashBStartAddress + 0x555)
#define pFlashBUnlock2Address 		(volatile unsigned short *)(pFlashBStartAddress + 0x2aa)
#define pFlashBManufacturerIDAddress	(volatile unsigned short *)(pFlashBStartAddress + 0x00)
#define pFlashBDeviceIDAddress 		(volatile unsigned short *)(pFlashAStartAddress + 0x01)

#define pFlashSection0OffsetAddress 	0x00000
#define pFlashSection1OffsetAddress 	0x08000
#define pFlashSection2OffsetAddress 	0x10000
#define pFlashSection3OffsetAddress 	0x18000
#define pFlashSection4OffsetAddress 	0x20000
#define pFlashSection5OffsetAddress 	0x28000
#define pFlashSection6OffsetAddress 	0x30000
#define pFlashSection7OffsetAddress 	0x38000
#define pFlashSection8OffsetAddress 	0x40000
#define pFlashSection9OffsetAddress 	0x48000
#define pFlashSection10OffsetAddress 	0x50000
#define pFlashSection11OffsetAddress 	0x58000
#define pFlashSection12OffsetAddress 	0x60000
#define pFlashSection13OffsetAddress 	0x68000
#define pFlashSection14OffsetAddress 	0x70000
#define pFlashSection15OffsetAddress 	0x78000
#define pFlashSection16OffsetAddress 	0x7c000
#define pFlashSection17OffsetAddress 	0x7d000
#define pFlashSection18OffsetAddress 	0x7e000

#define FlashBankA				0
#define FlashBankB 				1
#define DelayLength 			1

#define OK 						1
#define ERROR  					0

unsigned short Length = 7032, Lily1 = 0;
unsigned short Array[8] = {0x1234,0x5678,0xabcd,0xf0ab,0x450e,0x98ca,0x6677,0x8899};
unsigned short Array_out[8] = {0};


void SDRAM_Init(void)
{

	//SDRAM Refresh Rate Control Register
	*pEBIU_SDRRC = 0x00000817;	

	//SDRAM Memory Bank Control Register
	*pEBIU_SDBCTL = 0x00000013;

	//SDRAM Memory Global Control Register	
	*pEBIU_SDGCTL = 0x0091998d;	
}//end Init_SDRAM
	
void delay(unsigned int DelayValue)
{
	int i;
	for(i=0;i<DelayValue;i++)
	{
	;
	}	
}

void Init_EBIU(void)
{
	*pEBIU_AMBCTL0	= 0x7bb07bb0;
	*pEBIU_AMBCTL1	= 0x7bb0fff0;
	*pEBIU_AMGCTL	= 0x000f;
}

void FlashReset(unsigned char FlashBank)
{
	if(FlashBank == FlashBankA)
		{
		*pFlashAStartAddress = 0xf0;
		delay(DelayLength);
		}
	else if(FlashBank == FlashBankB)
		{
		*pFlashBStartAddress = 0xf0;
		delay(DelayLength);
		}
}

unsigned short FlashGetManufacturerID(unsigned char FlashBank)
{
unsigned short FlashValue;

	if(FlashBank == FlashBankA)
		{
		*pFlashAUnlock1Address = 0xaa;
		delay(DelayLength);
		*pFlashAUnlock2Address = 0x55;
		delay(DelayLength);
		*pFlashAUnlock1Address = 0x90;
		delay(DelayLength);
		FlashValue = *pFlashAManufacturerIDAddress;
		delay(DelayLength);
		}
	else if(FlashBank == FlashBankB)
		{
		*pFlashBUnlock1Address = 0xaa;
		delay(DelayLength);
		*pFlashBUnlock2Address = 0x55;
		delay(DelayLength);
		*pFlashBUnlock1Address = 0x90;
		delay(DelayLength);
		FlashValue = *pFlashBManufacturerIDAddress;
		delay(DelayLength);
		}
	else
		{
		FlashValue = ERROR;
		}
	return(FlashValue);
}

unsigned short FlashGetDeviceID(unsigned char FlashBank)
{
unsigned short FlashValue;

	if(FlashBank == FlashBankA)
		{
		*pFlashAUnlock1Address = 0xaa;
		delay(DelayLength);
		*pFlashAUnlock2Address = 0x55;
		delay(DelayLength);
		*pFlashAUnlock1Address = 0x90;
		delay(DelayLength);
		FlashValue = *pFlashADeviceIDAddress;
		delay(DelayLength);
		}
	else if(FlashBank == FlashBankB)
		{
		*pFlashBUnlock1Address = 0xaa;
		delay(DelayLength);
		*pFlashBUnlock2Address = 0x55;
		delay(DelayLength);
		*pFlashBUnlock1Address = 0x90;
		delay(DelayLength);
		FlashValue = *pFlashBDeviceIDAddress;
		delay(DelayLength);
		}
	else
		{
		FlashValue = ERROR;
		}
	return(FlashValue);
}


void FlashEraserChip(unsigned char FlashBank)
{
	if(FlashBank == FlashBankA)
		{
		*pFlashAUnlock1Address = 0xaa;
		delay(DelayLength);
		*pFlashAUnlock2Address = 0x55;
		delay(DelayLength);
		*pFlashAUnlock1Address = 0x80;
		delay(DelayLength);
		*pFlashAUnlock1Address = 0xaa;
		delay(DelayLength);
		*pFlashAUnlock2Address = 0x55;
		delay(DelayLength);
		*pFlashAUnlock1Address = 0x10;
		delay(DelayLength);
		while((*pFlashAStartAddress) != 0xffff)
			{;
			}
		}
	else if(FlashBank == FlashBankB)
		{
		*pFlashBUnlock1Address = 0xaa;
		delay(DelayLength);
		*pFlashBUnlock2Address = 0x55;
		delay(DelayLength);
		*pFlashBUnlock1Address = 0x80;
		delay(DelayLength);
		*pFlashBUnlock1Address = 0xaa;
		delay(DelayLength);
		*pFlashBUnlock2Address = 0x55;
		delay(DelayLength);
		*pFlashBUnlock1Address = 0x10;
		delay(DelayLength);
		while((*pFlashBStartAddress) != 0xffff)
			{;
			}
		}
}

void FlashEraseSector(unsigned char FlashBank,unsigned int pFlashSectorOffsetAddress)
{
	if(FlashBank == FlashBankA)
		{
		*pFlashAUnlock1Address = 0xaa;
		delay(DelayLength);
		*pFlashAUnlock2Address = 0x55;
		delay(DelayLength);
		*pFlashAUnlock1Address = 0x80;
		delay(DelayLength);
		*pFlashAUnlock1Address = 0xaa;
		delay(DelayLength);
		*pFlashAUnlock2Address = 0x55;
		delay(DelayLength);
		*(pFlashAStartAddress + pFlashSectorOffsetAddress) = 0x30;
		delay(DelayLength);
		while((*(pFlashAStartAddress + pFlashSectorOffsetAddress)) != 0xffff)
			{;
			}
		}
	else if(FlashBank == FlashBankB)
		{
		*pFlashBUnlock1Address = 0xaa;
		delay(DelayLength);
		*pFlashBUnlock2Address = 0x55;
		delay(DelayLength);
		*pFlashBUnlock1Address = 0x80;
		delay(DelayLength);
		*pFlashBUnlock1Address = 0xaa;
		delay(DelayLength);
		*pFlashBUnlock2Address = 0x55;
		delay(DelayLength);
		*(pFlashBStartAddress + pFlashSectorOffsetAddress) = 0x30;
		delay(DelayLength);
		while((*(pFlashBStartAddress + pFlashSectorOffsetAddress)) != 0xffff)
			{;
			}
		}
}

void FlashProgarmmeWord(unsigned char FlashBank,unsigned short Value,unsigned int pFlashOffsetAddress)
{
	if(FlashBank == FlashBankA)
		{
		*pFlashAUnlock1Address = 0xaa;
		delay(DelayLength);
		*pFlashAUnlock2Address = 0x55;
		delay(DelayLength);
		*pFlashAUnlock1Address = 0xa0;
		delay(DelayLength);
		*(pFlashAStartAddress + pFlashOffsetAddress) = Value;
		delay(DelayLength);
		Lily1 = *(pFlashAStartAddress + pFlashOffsetAddress);
		while((*(pFlashAStartAddress + pFlashOffsetAddress)) != Value)
			{;
			}
		}
	else if(FlashBank == FlashBankB)
		{
		*pFlashBUnlock1Address = 0xaa;
		delay(DelayLength);
		*pFlashBUnlock2Address = 0x55;
		delay(DelayLength);
		*pFlashBUnlock1Address = 0xa0;
		delay(DelayLength);
		*(pFlashBStartAddress + pFlashOffsetAddress) = Value;
		delay(DelayLength);
		while((*(pFlashBStartAddress + pFlashOffsetAddress)) != Value)
			{;
			}
		}
}

void main(void)
{   	unsigned short readID;
	unsigned short temp, i;
	

	Init_EBIU();
	//SDRAM_Init();

	FlashReset(FlashBankA);
	FlashReset(FlashBankB);

	readID = FlashGetManufacturerID(FlashBankA);//0x0001
	readID = FlashGetDeviceID(FlashBankA);//0x22da

	FlashReset(FlashBankA);
		
	FlashEraserChip(FlashBankA);
	temp = *pFlashAStartAddress;
	
//	FlashProgarmmeWord(FlashBankB, 0x1234, 0x0000);
//	temp = *pFlashBStartAddress;

/*	for ( i=0;	i<Length; i++ )
	{
		*(pData_out + i ) = *(pData + i );
	}
*/	
/***
	for( i=0; i<8; i++ )
	{
		FlashProgarmmeWord(FlashBankA, Array[i], i );
	}
	
	for( i=0; i<8; i++ )
	{
		Array_out[i] = *(pFlashAStartAddress + i);
	}
***/	

/********** 向Flash中写代码 ***********/
	for( i=0; i<Length; i++ )
	{
		FlashProgarmmeWord(FlashBankA, *(pData + i ), i );
	}
	
/********** 从Flash中读代码 ***********/
/*	for( i=0; i<Length; i++ )
	{
		*(pData_out + i) = *(pFlashAStartAddress + i);
	}
	
	temp = *(pFlashBStartAddress + 0);
*/	
//	FlashEraseSector(FlashBankB, pFlashSection0OffsetAddress);
//	temp = *pFlashBStartAddress;
	
	*pLight = 0x2a;
	
	while(1) 
	{;
	}	
}







⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -