日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]/////////////**************************.h文件*********************************///////////////////////////////////#ifndef_FLASH_CTRL_H_#define_FLASH_CTRL_H_#ifdefSTM32F10X_HD#defineFLASHADDRSTART0x0807

////

/////////**************************.h文件*********************************///////////////////////////////////

#ifndef_FLASH_CTRL_H_

#define_FLASH_CTRL_H_

#ifdefSTM32F10X_HD

#defineFLASHADDRSTART0x0807F800//

#defineFLASHADDREND0x08080000//

#elifSTM32F10X_MD

#defineFLASHADDRSTART0x0801FC00//

#defineFLASHADDREND0x0801FFFF//

#elifSTM32F10X_LD

#defineFLASHADDRSTART0x08001000//

#defineFLASHADDREND0x080013FF//

#endif

#ifdefSTM32F10X_HD//大容量產(chǎn)品,flash>=256K

#defineFLASH_PAGE_SIZE((u16)0x800)//2K

#elifSTM32F10X_MD//小容量產(chǎn)品,flash<256K

#defineFLASH_PAGE_SIZE((u16)0x400)//1K

#else

#defineFLASH_PAGE_SIZE((u16)0x400)//1K

#endif

#defineUCHARunsignedchar

#defineCHARchar

#defineULONGunsignedlong

#defineUINTunsignedint

#defineboolenUCHAR

#ifndeftrue

#definetrue1

#endif

#ifndeffalse

#definefalse0

#endif

#defineBLOCK_SIZE64

typedefstruct_tagFLASHWORDBUFF

{

ULONGulItems[BLOCK_SIZE/4];

}

FLASHWORDBUFF;

typedefstruct_tagFLASHHALFWORDBUFF

{

UINTulItems[BLOCK_SIZE/2];

}FLASHHALFWORDBUFF;

typedefstruct_tagFLASHBYTEBUFF

{

UCHARulitems[BLOCK_SIZE];

}

FLASHBYTEBUFF;

boolenwriteFlash(UCHAR*str,UINTlen);

UINTreadByteFlash(UINTlen);

UINTreadHalfWordFlash(UINTlen);

UINTreadWordFlash(UINTlen);

#endif

/////////////////////////********************.c文件***************************///////////////////////////////////////////////

/*Includes------------------------------------------------------------------*/

#include"flashctrl.h"

#include"stm32f10x_flash.h"

/*Privatevariables---------------------------------------------------------*/

vu32NbrOfPage=0x00;

u32EraseCounter=0x00,Address=0x00;

volatileFLASH_StatusFLASHStatus;

FLASHBYTEBUFFflashBytebuff;

FLASHHALFWORDBUFFflashHalfWrodbuff;

FLASHWORDBUFFflashWordbuff;

/*Publicfunction------------------------------------------------------------*/

/******************************************************************************

*FunctionName:writeFlash

*Description:Ereasetherange(FLASHADDREND-FLASHADDRSTART)offlash,and

*Writethestringtoit.

*input:thewritedofstring-str,thelenofstr

*output:writeorereasesuccessreturn1,otherwisereturn0.

*******************************************************************************/

boolenwriteFlash(UCHAR*str,UINTlen)

{

FLASH_Unlock();

NbrOfPage=(FLASHADDREND-FLASHADDRSTART)/FLASH_PAGE_SIZE;

FLASH_ClearFlag(FLASH_FLAG_BSY|FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPRTERR);

FLASHStatus=FLASH_COMPLETE;

for(EraseCounter=0;(EraseCounter

{

FLASHStatus=FLASH_ErasePage(FLASHADDRSTART+(FLASH_PAGE_SIZE*EraseCounter));

}

if(FLASHStatus!=FLASH_COMPLETE)//擦除不成功

{

returnfalse;

}

Address=FLASHADDRSTART;

while((Address

{

//instr=(*str)|((*(str+1))<<8);

if(len==0)break;

FLASHStatus=FLASH_ProgramWord(Address,*(u32*)str);//一次性寫入四個字節(jié)=1個字

Address=Address+4;

len-=4;

str+=4;

//str+=2;

if(len<4)

{

//由于是按字的寫入方式,即一次性寫入4個字節(jié)的數(shù)據(jù),

//所有后面剩余的(4-len%4)%4個字節(jié)的補(bǔ)零處理

FLASHStatus=FLASH_ProgramWord(Address,*(u32*)str);

break;

}

}

FLASH_Lock();

if(FLASHStatus!=FLASH_COMPLETE)

{

returnfalse;

}

elsereturntrue;

}

/******************************************************************************

*FunctionName:readByteFlash

*Description:readspecifiedlengthstringfromflash,thebeginflashis:FLASHADDRSTART

*Abytebybytetoread.

*input:thereadedofstring-str,thelenofstr

*output:returnthelengthofstringtakeaway1

*******************************************************************************/

UINTreadByteFlash(UINTlen)//

{

UINTi=0;

Address=FLASHADDRSTART;

for(i=0;i

{

flashBytebuff.ulitems[i]=(*(__IOint8_t*)Address);

Address+=1;

}

returni;

}

/******************************************************************************

*FunctionName:readHalfWordFlash

*Description:readspecifiedlengthstringfromflash,thebeginflashis:FLASHADDRSTART

*AHalfwordbyhalfwordtoread.

*input:thereadedofstring-str,thelenofstr

*output:returnthelengthofstringtakeaway1

*******************************************************************************/

UINTreadHalfWordFlash(UINTlen)//

{

UINTi=0;

Address=FLASHADDRSTART;

for(i=0;i

{

flashHalfWrodbuff.ulItems[i]=(*(__IOuint16_t*)Address);

Address+=2;

}

if(len/2)

{

flashHalfWrodbuff.ulItems[i]=(*(__IOuint16_t*)Address);

}

returni;

}

/******************************************************************************

*FunctionName:readWordFlash

*Description:readspecifiedlengthstringfromflash,thebeginflashis:FLASHADDRSTART

*Awordbywordtoread.

*input:thereadedofstring-str,thelenofstr

*output:returnthelengthofstringtakeaway1

*******************************************************************************/

UINTreadWordFlash(UINTlen)

{

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉