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

📄 example_dps2812m_flash.c

📁 TMS320F2812驱动flash程序
💻 C
字号:
/* =================================================================================
File name:       	Example_DPS2812M_FLASH.c                   
                    
Originator:				SEED R&D Group
		
Description: 
                  Example Program That Executes From XINTF (assumes MPNMC = 1)
                  As supplied, this project is configured for "boot from XINTF Zone 7" 
                  operation. 
  
                  XMP/MCn pin = 1
  
                  Map the region for XINTF Zone 7 as RAM in Code Composer
                 (Refer to the F2812.gel file supplied with CCS Studio) 
                 
                 This example configures CPU Timer0 and increments
                 a counter each time the timer asserts an interrupt.
 
                 Watch Variables:
                  CpuTimer0.InterruptCount
                  BackGroundCounter
=====================================================================================
 History:
-------------------------------------------------------------------------------------
 10-20-2005		Release	Rev 1.0         Jijunhui                                          
------------------------------------------------------------------------------*/

// Step 0: Include required header files:
//         DSP281x_Device.h: device specific definitions #include statements for
//         all of the peripheral .h definition files.

#include "Examples_DPS2812M_FLASH.h"


Uint16 data[0x10000];
Uint16 good_flag = 1;
Uint32 k;
void InitPeripherals(void);

void main(void)
{
	//初始化系统控制
	InitSysCtrl();
	//关总中断
	DINT;
	IER = 0x0000;
	IFR = 0x0000;
	//初始化外设
//	InitPeripherals();
	//使能总中断
//	EINT;
	//使能全局实时中断DBGM
	ERTM;
	
	//整片擦除
    	flash_erase(0,0x10);
    	for(k = 0; k < 0x10000; k++)
    	{
    		data[k] = 0x1234+k;
    	}
    	//从0x80000地址开始,写入长度为0x1000的数据DATA
    	flash_writem(0x80000,&data[0],0x10000);
    	//从0x80000地址开始,读出长度为0x1000的数据到DATA
	//flash_readm(0x80000,&data[0],0x10000);
	//
	for(k = 0; k < 0x10000; k++)
    	{
    		if(data[k] != flash_reads(0x80000+k))
    		{
    			good_flag = 0;
    			while(1);
    		}
    	}
	for(;;);		
}

/*********************************************************************
	函数名:	void InitPeripherals(void)
	目的:		初始化外设
	输入:		无
	输出:		无
*********************************************************************/
void InitPeripherals(void)
{
	//初始化XINTF
	InitXintf();
}

/*********************************************************************
	函数名:	unsigned int flash_erase(unsigned long addr,unsigned int type)
	目的:		FLASH擦除
	输入:		addr:	需要擦除FLASH的首地址
			type:	擦除类型
			0x50	块擦除
			0x30	段擦除
			0x10	芯片擦除
	输出:		判断擦除是否成功
			1	成功
			0	失败
*********************************************************************/

unsigned int flash_erase(unsigned long addr,unsigned int type)
{
	unsigned long i,j;
	*FLASH_5555 = FLASH_UL1;	//first
	*FLASH_2AAA = FLASH_UL2;	//second
	*FLASH_5555 = FLASH_UL3;	//third
	*FLASH_5555 = FLASH_UL4;
	*FLASH_2AAA = FLASH_UL5;
	switch(type)
	{
		case 0x50:		//block erase
			*(unsigned int *)addr = type;
			while((*(unsigned int *)addr & 0x80) != 0x80);
			for(i = 0; i < BLOCK_SIZE; i++)
			{
				if(*(unsigned int *)(addr + i) != 0xffff)
				{
					j = 0;
					break;
				}
			}
			j = 1;
			break;
		
		case 0x30:		//sector erase
			*(unsigned int *)addr = type;
			while((*(unsigned int *)addr & 0x80) != 0x80);
			for(i = 0; i < SECTOR_SIZE; i++)
			{
				if(*(unsigned int *)(addr + i) != 0xffff)
				{
					j = 0;
					break;
				}
			}
			j = 1;
			break;
			
		case 0x10:		//chip erase
			*FLASH_5555 = type;
			while((*FLASH_5555 & 0x80) != 0x80);
			for(i = 0; i < CHIP_SIZE; i++)
			{
				if(*(unsigned int *)(addr + i) != 0xffff)
				{
					j = 0;
					break;
				}
			}
			j = 1;
			break;
		
		default:
			break;
	}
	return (j);
}

/*********************************************************************
	函数名:	void flash_writes(unsigned long addr,unsigned int data)
	目的:		FLASH写
	输入:		addr:	需要写FLASH的地址
			data:	写入FLASH的数据
	输出:		无
*********************************************************************/

void flash_writes(unsigned long addr,unsigned int data)
{
	*FLASH_5555 = FLASH_UL1;
	*FLASH_2AAA = FLASH_UL2;
	*FLASH_5555 = FLASH_PROGRAM;
	*(unsigned int *)addr = data;
	while(*(unsigned int *)addr != data);
}

/*********************************************************************
	函数名:	void flash_writem(unsigned long addr,unsigned int *ptr,unsigned long length)
	目的:		FLASH连续写
	输入:		addr:	需要写FLASH的首地址
			ptr:	写入FLASH的数据指针
			length:	写入FLASH的数据长度
	输出:		无
*********************************************************************/

void flash_writem(unsigned long addr,unsigned int *ptr,unsigned long length)
{
	unsigned long i;
	for(i  = 0; i < length; i++)
	{
		flash_writes(addr+i,*(ptr+i));
	}
}

/*********************************************************************
	函数名:	unsigned int flash_reads(unsigned long addr)
	目的:		FLASH读
	输入:		addr:	需要读FLASH的首地址
	输出:		从FLASH读出的数据
*********************************************************************/

unsigned int flash_reads(unsigned long addr)
{
	return (*(unsigned int *)addr);
}

/*********************************************************************
	函数名:	void flash_readm(unsigned long addr,unsigned int *ptr,unsigned long length)
	目的:		FLASH连续读
	输入:		addr:	需要读FLASH的首地址
			ptr:	读FLASH的数据指针
			length:	读FLASH的数据长度
	输出:		无
*********************************************************************/

void flash_readm(unsigned long addr,unsigned int *ptr,unsigned long length)
{
	unsigned long i;
	for(i = 0; i < length; i++)
	{
		*(ptr + i) = flash_reads(addr+i);
	}
}

⌨️ 快捷键说明

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