[应用相关] 关于STM32G0 flash擦除失败问题

[复制链接]
1167|12
 楼主| 根特皇宫w 发表于 2022-2-24 17:15 | 显示全部楼层 |阅读模式
STM32G0flash擦除每次都失败,无论大面积擦除还是一页页擦错都失败。且出错后打印出来的PageError=0。擦除部分程序如下
  1. <font face="Tahoma, Verdana, Arial, Microsoft Yahei, sans-serif" style="outline: none; color: rgb(0, 0, 0); font-size: 15px; background-color: rgb(232, 232, 232);"><font color="#333333" style="outline: none;"><font style="outline: none; font-size: 14px;">
  2. </font></font></font><font style="outline: none; font-size: 15px; background-color: rgb(232, 232, 232); color: rgb(51, 51, 51);"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;"></font></font><font color="#333333" style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;">HAL_FLASH_Unlock();</font></font></font>
  3. <font style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;"></font></font><font color="#333333" style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;">Page_Mum = GetPage(addr);</font></font></font>
  4. <font style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;"></font></font><font color="#333333" style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;">FlashEraseInit.TypeErase=FLASH_TYPEERASE_PAGES;    //擦除类型,页擦除</font></font></font>
  5. <font style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;"></font></font><font color="#333333" style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;">FlashEraseInit.Page=Page_Mum;   </font></font></font><font style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;"> </font></font></font><font color="#333333" style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;">  </font></font></font><font style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;"> </font></font></font><font color="#333333" style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;">//从哪页开始擦除</font></font></font>
  6. <font style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;"></font></font><font color="#333333" style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;">FlashEraseInit.NbPages=pagenum;                        </font></font></font>
  7. <font style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;"></font></font><font color="#333333" style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;">if(HAL_FLASHEx_Erase(&FlashEraseInit&PageError)!=HAL_OK)</font></font></font>
  8. <font style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;"></font></font><font color="#333333" style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;">{</font></font></font>
  9. <font style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;"></font></font><font color="#333333" style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;">printf("flash_error_addr:%x\r\n"PageError);</font></font></font>
  10. <font style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;"></font></font><font color="#333333" style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;">printf("flash_easre_error\r\n");</font></font></font>
  11. <font style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;"></font></font><font color="#333333" style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;">while(1);</font></font></font>
  12. <font style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;"></font></font><font color="#333333" style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;">}</font></font></font>
  13. <font style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;"></font></font><font color="#333333" style="outline: none;"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;">FLASH_WaitForLastOperation(FLASH_WAITETIME);            //等待上次操作完成</font></font></font>
  14. <div align="left" style="outline: none; word-break: break-all; color: rgb(0, 0, 0);"><font style="outline: none; color: rgb(51, 51, 51);"><font face="Tahoma, Verdana, Arial, &quot;" style="outline: none;"><font style="outline: none; font-size: 14px;">HAL_FLASH_Lock();</font></font></font></div></font></font></font></font></font></font></font></font></font></font></font></font>


地下縱情搖擺 发表于 2022-11-20 12:24 | 显示全部楼层
你采用什么方式实现擦除的啊?

林间有新绿 发表于 2022-11-20 12:56 | 显示全部楼层
是不是你擦除的位置不对呢?

情和欲 发表于 2022-11-20 13:28 | 显示全部楼层
一般情况,擦除之前需要解锁的,你怎么弄的呢?

偷吻月亮 发表于 2022-11-20 14:00 | 显示全部楼层
可不可以把你代码发出来看看,这方面我还有点经验

一枝香 发表于 2022-11-20 14:32 | 显示全部楼层
感觉是你没解锁,导致flash擦除失败了吧

风吻过你的不羁 发表于 2022-11-20 15:04 | 显示全部楼层
你可以参考一下官方的对flash操作的程序demo,学习一下

笨蛋无需搭理 发表于 2022-11-20 15:36 | 显示全部楼层
正常来说,擦除flash需要一页一页的擦除的

喜爱弄人 发表于 2022-11-20 16:08 | 显示全部楼层
这个建议还是楼主使用外置的flash,这样好处理一些

漫过岁月 发表于 2022-11-20 16:40 | 显示全部楼层
一般flash是按页擦除的,而且要擦除程序之外的,不然擦完,程序就不好用喽

极客晨星 发表于 2022-11-20 17:12 | 显示全部楼层
大面积擦,你是怎么擦的?

SantaBunny 发表于 2023-2-21 12:33 | 显示全部楼层
STM32G0芯片LL库没有对Flash的操作需要自己实现,可借鉴HAL库。
SantaBunny 发表于 2023-2-21 12:33 | 显示全部楼层
STM32G0芯片LL库没有对Flash的操作需要自己实现,可借鉴HAL库。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

31

主题

148

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部