使用GD32F103VET6芯片进行flash读写,经过测试发现flash写操作只能在前256KB,在后256KB则无法进行写操作,查看手册针对这两块内存的区别在指令零等待或延时,但是对读写操作上会存在什么区分呢?擦除使用fmc_page_erase接口如下是操作demo:
/**
* @description: EEPROM read data
* @param : uint16_t write_addr: EEPROM addr(first addr: ) [input]
* uint8_t *buffer: Temporary storage cache [output]
* uint16_t length: len (unit: BYTE) [input]
* @return: success: 0 | fail: 1
*/
static int flash_write_word(uint32_t write_addr, const uint32_t *buffer, uint16_t length)
{
uint16_t i = 0;
uint32_t *tempBuff = NULL;
fmc_state_enum state = FMC_PGERR;
if (buffer == NULL || ((write_addr % 4) != 0))
{
return -1;
}
if ((write_addr) < FLASH_STORE_BASE_ADDR || ((write_addr + length * 4) >= (FLASH_BASE_ADDR + FLASH_SECTOR_SIGLE_SIZE * FLASH_SECTOR_TOTAL_SIZE)))
{
return -1;
}
tempBuff = (uint32_t *)buffer;
fmc_unlock();
__disable_irq();
for (i = 0; i < length; i++)
{
fmc_flag_clear(FMC_FLAG_BANK0_END);
fmc_flag_clear(FMC_FLAG_BANK0_WPERR);
fmc_flag_clear(FMC_FLAG_BANK0_PGERR);
state = fmc_word_program(write_addr + 4 * i, *(tempBuff + i));
if(state != FMC_READY)
{
__enable_irq();
fmc_lock();
return -1;
}
}
__enable_irq();
fmc_lock();
return 0;
}
|