想用GD32E103读写内部FLASH,一直不成功。下面是程序。谁能看看哪有问题。
//写函数
static void fmc_program(uint32_t start_addr,uint32_t data)
{
/* unlock the flash program/erase controller */
fmc_unlock();
uint32_t address = FMC_WRITE_START_ADDR+start_addr;
/* program flash */
fmc_word_program(address, data);
fmc_flag_clear(FMC_FLAG_END | FMC_FLAG_WPERR | FMC_FLAG_PGERR);
/* lock the main FMC after the program operation */
fmc_lock();
}
//擦除函数
static void fmc_erase_pages(void)
{
/* unlock the flash program/erase controller */
fmc_unlock();
/* clear all pending flags */
fmc_flag_clear(FMC_FLAG_END | FMC_FLAG_WPERR | FMC_FLAG_PGERR);
/* erase the flash pages */
fmc_page_erase(FMC_WRITE_START_ADDR);
fmc_flag_clear(FMC_FLAG_END | FMC_FLAG_WPERR | FMC_FLAG_PGERR);
/* lock the main FMC after the erase operation */
fmc_lock();
}
//保存数据
int save_config_params(uint32_t start_addr,uint32_t data)
{
if(data == NULL)
return -1;
//擦除FLASH
fmc_erase_pages();
//保存配置数据到Flash中
fmc_program(start_addr,data);
return 0;
}
|