#include "DataType.h"
#include "stm32f4xx_flash.h"
BOOL MCU_FlashErase(INT16U iSector)
{
BOOL bSta;
FLASH_Status Status;
bSta = FALSE;
Status = FLASH_EraseSector(iSector<<3, VoltageRange_3);
while(Status == FLASH_BUSY)
{
Status = FLASH_WaitForLastOperation();
}
if(Status == FLASH_COMPLETE)
{
bSta = TRUE;
}
return bSta;
}
BOOL MCU_FlashLock(void)
{
FLASH_Lock();
return TRUE;
}
BOOL MCU_FlashUnLock(void)
{
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
return TRUE;
}
BOOL MCU_FlashProgram(INT32U Addr,INT8U *pBuff,INT16U iCnt)
{
FLASH_Status status;
INT16U iLoop;
BOOL bSta;
iCnt >>= 2;
bSta = TRUE;
for(iLoop=0; iLoop<iCnt; iLoop++)
{
status = FLASH_ProgramWord(Addr, *(INT32U*)(pBuff));
pBuff += 4;
Addr += 4;
if(status!=FLASH_COMPLETE)
{
bSta = FALSE;
break;
}
}
return bSta;
}
void test_flash(void)
{
INT8U ctempBuff[]= "1234567890";
MCU_FlashUnLock();
MCU_FlashErase(1);
MCU_FlashProgram(0x08004010,ctempBuff,10);
MCU_FlashLock();
}
STM32M4 内部flash编程
于 2015-06-09 19:28:09 首次发布