简体   繁体   English

STM32F103C8T8-擦除闪存时出错

[英]Stm32F103C8T8 - error when I erase flash

i using flash to save data, but sometime error happen when Erasing Flash, i don't understand why? 我使用Flash保存数据,但是有时在擦除Flash时发生错误,我不明白为什么?

Thank for your help! 谢谢您帮忙! sorry for my terible english 抱歉我的英语不好

my program size: 30,46 kbyte. 我的程序大小:30,46 KB。

Here is my function: 这是我的功能:

#define FLASH_PAGE_ADDR   0x08010000

uint16_t Mydata = 2345;

void WriteData(void)
{
    FLASH_Unlock(); 
    FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR\
    |FLASH_FLAG_WRPRTERR);
    FLASH_ErasePage(FLASH_PAGE_ADDR);
    FLASH_ProgramHalfWord(FLASH_PAGE_ADDR+2, Mydata);
}

You chip has 64kB of flash memory, so trying to erase a page that does not exist (starting 64kB after start of flash) is not the best idea. 您的芯片具有64kB的闪存,因此,最好删除一个不存在的页面(在闪存启动后启动64kB)。 Trying to do that may as well erase the FIRST page of flash, removing interrupt vectors and part of the running application. 尝试这样做可能会擦除Flash的FIRST页面,删除中断向量和正在运行的应用程序的一部分。

The device stm32F103C8T8 contains 64Kb of flash. 设备stm32F103C8T8包含64Kb的闪存。

订购信息方案

And the memory layout looks like this: 内存布局如下所示:

记忆图

For your device the flash memory will actually be 0x08000000-0x0800FFFF since you got the 64Kb variant. 对于您的设备,由于您使用的是64Kb版本,因此闪存实际上将为0x08000000-0x0800FFFF This memory will be our first page (aka sector ) of flash memory. 该内存将是我们的闪存的第一 (也称为扇区 )。 There are 64 pages for your device each being 1Kb in size. 设备共有64页,每页1Kb。 You can only erase full pages. 您只能删除整页。 See below picture for flash module organization: 参见下图,了解闪存模块的组织:

闪存模块组织

In your example you tell the device to start erasing from 0x08010000 . 在您的示例中,您告诉设备从0x08010000开始擦除。 With the information given above, this is of course not possible (since there is no memory at this location). 使用上面给出的信息,这当然是不可能的(因为此位置没有内存)。 I suggest you change the location so that it will target a valid page (staring at the beginning of a page): 我建议您更改位置,以便将其定位到有效页面(在页面开头凝视):

#define FLASH_PAGE_4_ADDR   0x08001000

Make sure that you are not executing from that very spot when erasing, since then, of course, your program will crash. 确保在擦除时没有从那个位置执行,否则自此以后,程序将崩溃。

Also, consider looking at the return value from your functions that you use to erase with. 另外,考虑查看用于擦除的函数的返回值。 They could tell you something important. 他们可以告诉您一些重要的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM