STM32如何检测FLASH写保护

[复制链接]
3044|2
 楼主| Miltonliu2010 发表于 2012-8-30 17:19 | 显示全部楼层 |阅读模式
以前做过STM32的IAP,没有能发现一些问题。可是今天再读IAP的软件包。不明白下面这段代码的原理。
  1.   /* Get the number of block (4 or 2 pages) from where the user program will be loaded */
  2.   BlockNbr = (FlashDestination - 0x08000000) >> 12;

  3.   /* Compute the mask to test if the Flash memory, where the user program will be
  4.      loaded, is write protected */
  5. #if defined (STM32F10X_MD) || defined (STM32F10X_MD_VL)
  6.   UserMemoryMask = ((uint32_t)~((1 << BlockNbr) - 1));
  7. #else /* USE_STM3210E_EVAL */
  8.   if (BlockNbr < 62)
  9.   {
  10.     UserMemoryMask = ((uint32_t)~((1 << BlockNbr) - 1));
  11.   }
  12.   else
  13.   {
  14.     UserMemoryMask = ((uint32_t)0x80000000);
  15.   }
  16. #endif /* (STM32F10X_MD) || (STM32F10X_MD_VL) */


  17.   /* Test if any page of Flash memory where program user will be loaded is write protected */
  18.   if ((FLASH_GetWriteProtectionOptionByte() & UserMemoryMask) != UserMemoryMask)
  19.   {
  20.     FlashProtection = 1;
  21.   }
  22.   else
  23.   {
  24.     FlashProtection = 0;
  25.   }
 楼主| Miltonliu2010 发表于 2012-8-31 11:46 | 显示全部楼层
为什么每次我提出来的问题最后都是自己解决的?:Q
airwill 发表于 2012-9-1 09:19 | 显示全部楼层
两种可能性
1. 说明你的问题太专业, 层次太高了. 无人能参加.
2. 说明你太钻研了, 人家还没有弄明白, 你就搞定了.
总之, 这里有个潜力不小的高人, 即将或者已经诞生.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

20

主题

87

帖子

3

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