本帖最后由 加油吧!宝宝! 于 2020-9-23 21:59 编辑
为什么读出来的数据全是0xFFFF,是否意味着我没写成功。编程或擦除的地址是当前页的起始地址,都在闪存基地址范围内,也没有和存储代码的地址重叠,可就是读出来的数据全是0xFFFF。我百思不得其解,求各位大佬帮帮忙,谢谢!
截取自用户使用手册
闪存页大小为1KB。主存储闪存的每页都可以单独擦除。
GD32E10x闪存基地址和构成
第0页 0x0800 0000~0x0800 03FF 1KB
第1页 0x0800 0400~0x0800 07FF 1KB
第2页 0x0800 0400~0x0800 0BFF 1KB
.
.
.
第127页 0x0801 FC00~0x0801 FFFF 1KB
附部分代码:
#define FMC_PAGE_SIZE ((uint16_t)0x400U) //1k
#define FMC_WRITE_START_ADDR ((uint32_t)0x08010400U)
#define FMC_WRITE_END_ADDR ((uint32_t)0x08010800U)
uint32_t *ptrd;
uint32_t address = 0x00;
uint32_t data0 = 0x01234567U;
uint32_t data1 = 0xd583179bU;
/* 计算有多少页要编程或擦除 */
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);
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_END | FMC_FLAG_WPERR | FMC_FLAG_PGAERR | FMC_FLAG_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_END | FMC_FLAG_WPERR | FMC_FLAG_PGAERR | FMC_FLAG_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);
address += 4;
fmc_flag_clear(FMC_FLAG_END | FMC_FLAG_WPERR | FMC_FLAG_PGAERR | FMC_FLAG_PGERR );
}
/* lock the main FMC after the program operation */
fmc_lock();
}
|