硬汉嵌入式论坛

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

[其它] 请教下stm32f030对option byte编程时,需要先擦除吗?

[复制链接]

92

主题

596

回帖

872

积分

金牌会员

积分
872
发表于 前天 22:37 | 显示全部楼层 |阅读模式
看了手册上,写的很含糊,
回复

使用道具 举报

7

主题

364

回帖

385

积分

高级会员

积分
385
发表于 昨天 08:41 | 显示全部楼层
这些东西我觉得实测一下最靠谱,不要听任何人讲,先直接写,再读,看正常不?再重复多次,每次不同的数据,如果正常则不需要擦,否则需要擦除。
回复

使用道具 举报

92

主题

596

回帖

872

积分

金牌会员

积分
872
 楼主| 发表于 昨天 10:00 | 显示全部楼层
fxyc87 发表于 2026-1-8 08:41
这些东西我觉得实测一下最靠谱,不要听任何人讲,先直接写,再读,看正常不?再重复多次,每次不同的数据, ...

我刚试了下,应该是要擦除的,
回复

使用道具 举报

1万

主题

7万

回帖

12万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
120427
QQ
发表于 昨天 11:05 | 显示全部楼层
F0系列需要的,后来的F4等系列,可以写选项字节寄存器时自动擦除。

[C] 纯文本查看 复制代码
/**
  * @brief  Erases the FLASH option bytes.
  * @note   This functions erases all option bytes except the Read protection (RDP).
  *         The function @ref HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
  *         The function @ref HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes
  *         The function @ref HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes
  *         (system reset will occur)
  * @retval HAL status
  */

HAL_StatusTypeDef HAL_FLASHEx_OBErase(void)
{
  uint8_t rdptmp = OB_RDP_LEVEL_0;
  HAL_StatusTypeDef status = HAL_ERROR;

  /* Get the actual read protection Option Byte value */
  rdptmp = FLASH_OB_GetRDP();

  /* Wait for last operation to be completed */
  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);

  if(status == HAL_OK)
  {
    /* Clean the error context */
    pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;

    /* If the previous operation is completed, proceed to erase the option bytes */
    SET_BIT(FLASH->CR, FLASH_CR_OPTER);
    SET_BIT(FLASH->CR, FLASH_CR_STRT);

    /* Wait for last operation to be completed */
    status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);

    /* If the erase operation is completed, disable the OPTER Bit */
    CLEAR_BIT(FLASH->CR, FLASH_CR_OPTER);

    if(status == HAL_OK)
    {
      /* Restore the last read protection Option Byte value */
      status = FLASH_OB_RDP_LevelConfig(rdptmp);
    }
  }

  /* Return the erase status */
  return status;
}
回复

使用道具 举报

92

主题

596

回帖

872

积分

金牌会员

积分
872
 楼主| 发表于 昨天 11:11 | 显示全部楼层
eric2013 发表于 2026-1-8 11:05
F0系列需要的,后来的F4等系列,可以写选项字节寄存器时自动擦除。

[mw_shl_code=c,true]/**

是的,F4系列的会自动擦除
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-1-9 16:50 , Processed in 0.077875 second(s), 24 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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