硬汉嵌入式论坛

 找回密码
 立即注册
查看: 515|回复: 3
收起左侧

[技术讨论] stm32 g0 flash擦除的FLASH_SR_PGSERR bug真的离谱

[复制链接]

22

主题

67

回帖

133

积分

初级会员

积分
133
发表于 2023-10-10 14:26:19 | 显示全部楼层 |阅读模式
    {  uint32_t error;
        LL_FLASH_SetTypeErase(FLASH,FLASH_TYPEERASE_PAGES);
        LL_FLASH_SetErasePageNumber(FLASH,pagenumber);
        LL_FLASH_StartErase(FLASH);
        while (LL_FLASH_IsActiveFlag_BSY(FLASH))
        {
        }
        //printf(" FLASH->PG %d\r\n",/*READ_BIT(FLASH->CR,PSIZE),*/error);    不加这个printf error就会报擦除出错,错误的寄存器是FLASH_SR_PGSERR
       //本来以为是这个printf造成的延迟,但是我在这里加个while(cnt--)delay也没用啊

        CLEAR_BIT(FLASH->CR, FLASH_CR_PER);      
        error = (FLASH->SR & FLASH_SR_ERRORS);
        if(error !=0)
        {
            printf("error %d\r\n",error);
        }
    }


求大佬 硬汉哥围观一下

回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106757
QQ
发表于 2023-10-10 15:07:41 | 显示全部楼层
1、加个HAL_Delay(100)试试
2、不行的话,调用HAL库的API测试下正常不。
回复

使用道具 举报

3

主题

122

回帖

131

积分

初级会员

积分
131
发表于 2023-10-19 08:58:35 | 显示全部楼层
https://www.armbbs.cn/forum.php?mod=viewthread&tid=120335
站里也有人碰到类似的问题,要清除错误标志才行,单独擦除SR_PGERR可能还不行,需要擦很多,擦哪些我没试过,我是全擦了
#define FLASH_SR_CLEAR                  (FLASH_SR_ERRORS | FLASH_SR_EOP)

#define FLASH_SR_ERRORS                 (FLASH_SR_OPERR  | FLASH_SR_PROGERR | FLASH_SR_WRPERR | \
                                         FLASH_SR_PGAERR | FLASH_SR_SIZERR  | FLASH_SR_PGSERR |  \
                                         FLASH_SR_MISERR | FLASH_SR_FASTERR |                    \
                                         FLASH_SR_OPTVERR) /*!< All SR error flags */

回复

使用道具 举报

3

主题

122

回帖

131

积分

初级会员

积分
131
发表于 2023-10-19 09:16:39 | 显示全部楼层
找到了,必须是清除所有错误标志,否则擦除页会失败,第2条这里可以看到。在rm0454 stm32g0x0参考手册3.3.7FLASH Main memory erase sequences能找到这段

To erase a page (2 Kbytes), follow the procedure below:
1.Check that no Flash memory operation is ongoing by checking the BSY1 bit of the
FLASH status register (FLASH_SR).
2.Check and clear all error programming flags due to a previous programming. If not,
PGSERR is set.
3.Set the PER bit and select the page to erase (PNB) in the FLASH control register
(FLASH_CR).
4.Set the STRT bit of the FLASH control register (FLASH_CR).
5.Wait until the BSY1 bit of the FLASH status register (FLASH_SR) is cleared.


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-4 20:08 , Processed in 0.244998 second(s), 26 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表