打印
[开发工具]

在 KEIL 下这样实现了“读保护”,请大家来评论是否可靠

[复制链接]
4505|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
luyuc|  楼主 | 2009-6-2 11:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
keil, TE, TI, se, ST
   首先打开WINDOWS任务管理器  
1.上 KEIL 进入 DEBUG 状态 
2.读取地址  0X1FFF F800 , 显示出内容 0X00FF 5AA5  
3.修改最低8位为 FF , 这时数据为  0X00FF 5AFF  
4.KEIL 死掉  
5.在任务管理器中结束 KEIL 


    Reading/programming the STM32F10xxx embedded Flash memory PM0042  17 页这样写 
This protection is activated by setting the RDP option byte. Once the protection byte has been programmed to a value: 
● Main Flash memory read access is not allowed except for the user code (when booting from main Flash memory itself with the debug mode not active). 
● Pages 0-3 (for low- and medium-density devices), or pages 0-1 (for high-density devices) are automatically write-protected. The rest of the memory can be programmed by the code executed from the main Flash memory (for IAP, constant storage, etc.), but it is protected against write/erase (but not against mass erase) in debug mode or when booting from the embedded SRAM. 
● All features linked to loading code into and executing code from the embedded SRAM are still active (JTAG/SWD and boot from embedded SRAM) and this can be used to Reading/programming the STM32F10xxx embedded Flash memory PM0042 disable the read protection. When the read protection option byte is altered to a memory-unprotect value, a mass erase is performed. 
沙发
computer00| | 2009-6-2 11:28 | 只看该作者

FLASH不能直接这样修改吧……你再读回来看看?

应该在程序中用at关键字指定地址的值

使用特权

评论回复
板凳
grant_jx| | 2009-6-2 19:59 | 只看该作者

这样在MDK下改,肯定不可靠。

STM32的外设固件库中Flash API下面不是有这个函数吗?难道不能实现要求?


/*******************************************************************************
* Function Name  : FLASH_ReadOutProtection
* Description    : Enables or disables the read out protection.
*                  If the user has already programmed the other option bytes before 
*                  calling this function, he must re-program them since this 
*                  function erases all option bytes.
* Input          : - Newstate: new state of the ReadOut Protection.
*                    This parameter can be: ENABLE or DISABLE.
* Output         : None
* Return         : FLASH Status: The returned value can be: FLASH_BUSY, 
*                  FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_COMPLETE or 
*                  FLASH_TIMEOUT.
*******************************************************************************/
FLASH_Status FLASH_ReadOutProtection(FunctionalState NewState)
{
  FLASH_Status status = FLASH_COMPLETE;

  /* Check the parameters */
  assert_param(IS_FUNCTIONAL_STATE(NewState));

  status = FLASH_WaitForLastOperation(EraseTimeout);

  if(status == FLASH_COMPLETE)
  {
    /* Authorizes the small information block programming */
    FLASH->OPTKEYR = FLASH_KEY1;
    FLASH->OPTKEYR = FLASH_KEY2;

    FLASH->CR |= CR_OPTER_Set;
    FLASH->CR |= CR_STRT_Set;

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

    if(status == FLASH_COMPLETE)
    {
      /* if the erase operation is completed, disable the OPTER Bit */
      FLASH->CR &= CR_OPTER_Reset;

      /* Enable the Option Bytes Programming operation */
      FLASH->CR |= CR_OPTPG_Set; 

      if(NewState != DISABLE)
      {
        OB->RDP = 0x00;
      }
      else
      {
        OB->RDP = RDP_Key;  
      }

      /* Wait for last operation to be completed */
      status = FLASH_WaitForLastOperation(EraseTimeout); 
    
      if(status != FLASH_BUSY)
      {
        /* if the program operation is completed, disable the OPTPG Bit */
        FLASH->CR &= CR_OPTPG_Reset;
      }
    }
    else 
    {
      if(status != FLASH_BUSY)
      {
        /* Disable the OPTER Bit */
        FLASH->CR &= CR_OPTER_Reset;
      }
    }
  }
  /* Return the protection operation Status */
  return status;      
}
  

非要在Keil里面改?不知意图是什么,是否是希望keil的编程能支持读保护操作,还是在调试的时候可以实现读保护功能的调试,我自己给自己的话快绕晕了。

使用特权

评论回复
地板
luyuc|  楼主 | 2009-6-3 20:38 | 只看该作者

是这样


1. 我完全用汇编在 keil 写东西
2. 我调完后就想直接锁住(量小的生产)
3. 板上只留 4 根针 gnd  swdio swclj vdd ,方便

使用特权

评论回复
5
luyuc|  楼主 | 2009-6-3 20:48 | 只看该作者

在 keil 用间接寻址操作0X1FFF F800无效

1.我也曾想过,在复位后,让程序操作地址 0x1FFF F800 ,但是试了一下,不行;可能还有别的时序要求,如什么 KEY 之类,文档也没有仔细看;
2.我在数据窗口读出 0X1FFF F8000 后,修改低2位,回车就导致 KEIL 死掉;
3.我用KEIL挂 STLINK2 学习板学软件,这搭配本身就不理想;
4.后来我尝试了别的地址,只要不是 FLASH 内的地址,一动数据回车就死 KEIL,真实有趣;
5.如果动 FLASH 的某些地址的数据,发现 KEIL 的程序指针自己走几下,有趣;

使用特权

评论回复
6
luyuc|  楼主 | 2009-6-3 21:02 | 只看该作者

我写很多小汇编测试外设

发现这样 HEX 文件比较小,编译后一般在 2.5K 以下,挂上 C 头文件马上就有近 10K 不见了,这的确是让人担心用 C 写东西,32K 也不太够折腾的;还是下点功夫,把汇编的外设测试例程都完善了吧,这样比较让人放心,我也基本上看不懂 C ; 如果我把 3 楼给的那段 C 译成汇编,让芯片复位后自己走一次,相信马上可以实现读保护,这里谢谢 3 楼的朋友了;

使用特权

评论回复
7
luyuc|  楼主 | 2009-6-3 22:40 | 只看该作者

大概是这样的,不知道对否


   看了看文档,首先确定一点,通过 IDE 界面无法实现读保护操作,让程序自己跑起来可以实现这一操作;如下几步:

1. 使能 HSI
2. FPEC 解锁
3. 写入 KEY1 到 FLASH_OPTKEYR
4. 写入 KEY2 到 FLASH_OPTKEYR
5. 设置 FLASH_CR 的OPTWRE 位为 1
6. 对选择字节进行编程

   有几个问题不明白
1. 写入 KEY1  KEY2 就是解锁 FPEC 吧?
2. 置位 OPTWRE 位是进行半字的普通写入操作吧?
3. 进行选择字节的编程也应该是进行半字的普通写入操作吧?
4. 一旦学习板读保护成功了,我也就不能再用了,必须进入 RAM 启动,清除读保护后,才能 DEBUG 吧? 至今试了几次,还没有成功从 RAM 启动过;所以万万不可自己把自己搞定了;
5. 如果把这一段代码写入芯片复位后的位置,每次启动都执行一遍,感觉也不是太理想,是否存在寿命之类的问题呢,万一操作失败,是否整个程序就完了?
  
  想来想去,都无法放心用 SWDIO SWCLK 这两条线完成调试、读保护的操作;

使用特权

评论回复
8
FAQ| | 2017-11-7 23:21 | 只看该作者

使用特权

评论回复
9
nyszx| | 2017-11-8 13:10 | 只看该作者
挖坟了

使用特权

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

本版积分规则

3

主题

12

帖子

0

粉丝