打印

STM32如何检测FLASH写保护

[复制链接]
7165|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
Miltonliu2010|  楼主 | 2012-8-31 08:34 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
以前做过STM32IAP,没有能发现一些问题。可今天再读IAP的软件包。不明白下面这段代码的原理
  •   /* Get the number of block (4 or 2 pages) from where the user program will be loaded */
  •   BlockNbr = (FlashDestination - 0x08000000) >> 12;
  •   /* Compute the mask to test if the Flash memory, where the user program will be
  •      loaded, is write protected */
  • #if defined (STM32F10X_MD) || defined (STM32F10X_MD_VL)
  •   UserMemoryMask = ((uint32_t)~((1 << BlockNbr) - 1));
  • #else /* USE_STM3210E_EVAL */
  •   if (BlockNbr < 62)
  •   {
  •     UserMemoryMask = ((uint32_t)~((1 << BlockNbr) - 1));
  •   }
  •   else
  •   {
  •     UserMemoryMask = ((uint32_t)0x80000000);
  •   }
  • #endif /* (STM32F10X_MD) || (STM32F10X_MD_VL) */
  •   /* Test if any page of Flash memory where program user will be loaded is write protected */
  •   if ((FLASH_GetWriteProtectionOptionByte() & UserMemoryMask) != UserMemoryMask)
  •   {
  •     FlashProtection = 1;
  •   }
  •   else
  •   {
  •     FlashProtection = 0;
  •   }

复制代码
沙发
IJK| | 2012-8-31 10:27 | 只看该作者
这段代码注释得挺清楚。要完全弄清楚,需要看STM32的 programming manual,里面有细节。

使用特权

评论回复
板凳
Miltonliu2010|  楼主 | 2012-8-31 11:48 | 只看该作者
2# IJK 谢谢,已经弄清楚了。它检查的是从某个块以后的所有块的写保护,而不是只是检查某一个块的写保护。

使用特权

评论回复
地板
it_yrj| | 2014-5-21 14:27 | 只看该作者
楼主方便解释下开始的移位是什么意思吗?谢谢了

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

20

主题

87

帖子

3

粉丝