#include "fmc.h"
#define GD32_FLASH_BASE 0x08000000
typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
#define FMC_PAGE_SIZE ((u16)0x800)
vu32 zNbrOfPage = 0x00;
u32 Address = 0x00 ,wrp = 0,wrp2 = 0;
volatile fmc_state_enum zFMCStatus = FMC_READY;
volatile TestStatus zMemoryProgramStatus = PASSED;
u32*ptrd;
__IO TestStatus zTransferStatus = FAILED;
u32 GDFLASH_ReadWord(u32 faddr)
{
return *(vu32*)faddr;
}
u8 GDFLASH_Write(u32 WriteAddr,u32 *pBuffer,u32 NumToWrite)
{
// uint32_t addrx=0;
uint32_t endaddr=0;
// uint32_t i;
fmc_unlock();
// addrx=WriteAddr;
endaddr=WriteAddr+NumToWrite*4;
fmc_flag_clear(FMC_FLAG_BANK0_END);
fmc_flag_clear(FMC_FLAG_BANK0_WPERR);
fmc_flag_clear(FMC_FLAG_BANK0_PGERR);
while(WriteAddr<endaddr)
{
zFMCStatus = fmc_word_program(WriteAddr,*pBuffer);
fmc_flag_clear(FMC_FLAG_BANK0_END);
fmc_flag_clear(FMC_FLAG_BANK0_WPERR);
fmc_flag_clear(FMC_FLAG_BANK0_PGERR);
WriteAddr+=4;
pBuffer++;
}
fmc_lock();
return zFMCStatus;
}
u8 GDFMC_ErasePage(u32 PageAddr)
{
// uint8_t i;
zTransferStatus = PASSED;
fmc_unlock();
fmc_flag_clear(FMC_FLAG_BANK0_END);
fmc_flag_clear(FMC_FLAG_BANK0_WPERR);
fmc_flag_clear(FMC_FLAG_BANK0_PGERR);
zFMCStatus=fmc_page_erase(PageAddr);//GD32_FLASH_BASE + (FMC_PAGE_SIZE * PageAddr));
fmc_flag_clear(FMC_FLAG_BANK0_END);
fmc_flag_clear(FMC_FLAG_BANK0_WPERR);
fmc_flag_clear(FMC_FLAG_BANK0_PGERR);
fmc_lock();
return zFMCStatus;
}
void GDFLASH_Read(u32 ReadAddr,u32 *pBuffer,u32 NumToRead)
{
u32 i;
for(i=0;i<NumToRead;i++)
{
pBuffer[i]=GDFLASH_ReadWord(ReadAddr);
ReadAddr+=4;
}
}
仅供参考
|