GD32的flash写操作
往flash的某个地址写入数据前,一般要先擦除该地址。
16位半字编程:
void IAP_WriteFlag(uint16_t flag)
{
fmc_unlock();
fmc_page_erase(IAP_FLAG_ADDR);
fmc_halfword_program(IAP_FLAG_ADDR,flag);
fmc_lock();
}
32位整字编程:
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);
address += 4;
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();
}
|