21ic问答首页 - GD32F103VET6 FMC 512KB flash,后256KB无法写入数据
GD32F103VET6 FMC 512KB flash,后256KB无法写入数据
sumwms2021-06-15
使用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;
}
/**
* @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;
}
赞0
GD手册这边针对片上flash有个定义:闪存控制器(FMC)。**作的实际是片内的flash。使用工具直接读写片内flash,发现也是同样的问题(后256KB无法写入,全0xFFFFFFF)
评论
2021-06-16
赞0
评论
2021-06-16
您需要登录后才可以回复 登录 | 注册