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

📄 flash.cpp.bak

📁 基于ARM 44b0的启动应到程序
💻 BAK
字号:

#include "includes.h"

int CheckBlank(UINT32 addr,UINT32 WordSize) 
{
	UINT32 i,temp;
	for (i=addr;i<(addr+WordSize);i++)
	{
		temp=*((volatile UINT16 *)(0x2000000+i<<1));
		if(temp!=0xffff)
			return 0;
	}
	return 1;	
}

int WaitForEnd( ) 
{
	volatile UINT16 flashStatus,old;
	old=*((volatile UINT16 *)0x0);

	while(1)
	{
		flashStatus=*((volatile UINT16 *)0x0);
		if( (old&0x40) == (flashStatus&0x40) )
			break;
		else
		old=flashStatus;
	}
	return 1;
}

int WriteWord(UINT32 addr,UINT16 dat)
{
	WriteFlash(0x555,0xAA);
	WriteFlash(0x2AA,0x55);
	WriteFlash(0x555,0xA0);
	WriteFlash(addr,dat);
	WaitForEnd();
	*((volatile ushort *)0x2000000) = 0xF0;
	return WaitForEnd();	
}

void  EraseSector(UINT32 addr)
{
	WriteFlash(0x555,0xAA);
	WriteFlash(0x2AA,0x55);
	WriteFlash(0x555,0x80);
	WriteFlash(0x555,0xAA);
	WriteFlash(0x2AA,0x55);
	WriteFlash(addr,0x30);
	WaitForEnd();
	//写入复位命令
	*((volatile ushort *)0x2000000) = 0xF0;
	WaitForEnd();
}

void TestFlash()
{
	UINT16 temp;
	
	EraseSector(0x0);
	vUartPrintf("\nSector erase successfully!");
    	if(CheckBlank(0,256))//是否为空
    	{
    		vUartPrintf("\nBlank check OK! Begin to Write the sector...");
		for(i=0;i<256;i++)
		{
			if(WriteWord(i,0xAA55))
		      	{
		      		vDelay(2);
		      	}
		      	else
		      	  	vUartPrintf("adr=%d,Write Error",i);
		 }
		 vUartPrintf("\nWrite OK! Begin to Verify... ");   
           	for(i=0;i<256;i++)
           	{
              		temp = Readflash(i);
              		if(temp!= 0xaa55)
              		{
              	 		Uart_Printf("\nadr=%4d,temp = %4x Verify Error!",i,temp);	      
		         	//break;
		      	}
		 }
		 vUartPrintf("\nVerify OK! Begin to erase the sector...");
	  	SectorErase(0xff800);
		vUartPrintf("\nSector erase successfully!");
	}
	else
		vUartPrintf("\nThe Sector is not empty! Abort the test!"); 
}

⌨️ 快捷键说明

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