GD32F103RCT6 FMC写入flash 读出来全是ffff 是什么问题?
#define FMC_PAGE_SIZE ((uint16_t)0x800)
#define FMC_WRITE_START_ADDR ((uint32_t)0x0807F800) //最后一页2KB
#define FMC_WRITE_END_ADDR ((uint32_t)0x0807FFFF)
uint32_t *ptrd;
uint32_t address = 0x00;
uint32_t data0 = 0x01234567U;
/* 计算有多少页要编程或擦除 */
uint32_t PageNum = (FMC_WRITE_END_ADDR - FMC_WRITE_START_ADDR) / FMC_PAGE_SIZE;
/* 计算有多少字要编程或擦除 */
uint32_t WordNum = ((FMC_WRITE_END_ADDR - FMC_WRITE_START_ADDR) >> 2);
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
void fmc_erase_pages(void)
{
uint32_t EraseCounter;
/* unlock the flash program/erase controller */
fmc_unlock();
/* clear all pending flags */
fmc_flag_clear(FMC_FLAG_BANK0_END);
fmc_flag_clear(FMC_FLAG_BANK0_WPERR);
fmc_flag_clear(FMC_FLAG_BANK0_PGERR);
/* erase the flash pages */
for(EraseCounter = 0; EraseCounter < PageNum; EraseCounter++){
fmc_page_erase(FMC_WRITE_START_ADDR + (FMC_PAGE_SIZE * EraseCounter));
fmc_flag_clear(FMC_FLAG_BANK0_END);
fmc_flag_clear(FMC_FLAG_BANK0_WPERR);
fmc_flag_clear(FMC_FLAG_BANK0_PGERR);
}
/* lock the main FMC after the erase operation */
fmc_lock();
}
void fmc_program(void)
{
/* unlock the flash program/erase controller */
fmc_unlock();
address = FMC_WRITE_START_ADDR;
/* program flash */
while(address < FMC_WRITE_END_ADDR){
fmc_word_program(address, data0);
fmc_halfword_program(address,data0);
address += 2;
fmc_flag_clear(FMC_FLAG_BANK0_END);
fmc_flag_clear(FMC_FLAG_BANK0_WPERR);
fmc_flag_clear(FMC_FLAG_BANK0_PGERR);
}
/* lock the main FMC after the program operation */
fmc_lock();
}
uint16_t gd32fmc_ReadWord(uint32_t addr)
{
return *(volatile uint32_t*)addr;
}
主函数
fmc_erase_pages();
fmc_program();
printf("%x \r\n",gd32fmc_ReadWord(0x0807f800));
//printf("%d \r\n",FMC_READ(FMC_WRITE_END_ADDR));
|