硬汉嵌入式论坛

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

[脱机烧录] PY32F002B芯片本身不支持RDP Flash读保护,H7-TOOL通过SDK代码保护间接实现方法,操作比较简单(2025-09-27)

[复制链接]

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
119429
QQ
发表于 2025-9-27 16:52:52 | 显示全部楼层 |阅读模式
1、PY32F002B不同于F002A,F002A支持RDP读保护

123.png

而F002B不支持

456.png

2、通过SDK代码保护间接实现方法

(1)没代码保护的时候,是可以正常读取内容的

13.png

(2)根据手册说明,F002B有个代码保护设置选项字节配置,STM32上这个叫PCROP,是一样的功能。

F002B的SDK代码保护设置说明如下:

省事些,我们这里直接全部配置了,起始地址设置为0x00,  结束地址设置为0x0F,每个STEP增加2KB,那么我们配置为0x0F的话,就是32KB(芯片手册实际计算时要+1, 也就是32KB), 完全可以覆盖这个芯片的24KB容量

12.png

(3)脱机烧录配置

选择烧录完毕后断电复位,保证TOOL独立供电,如果外置供电,需要手动全端电一次。因为修改选项字节需要断电复位才会生效。同使能写选项字节

12345.png

0x00对应地址0x1FFF0084,0x0F对应地址0x1FFF0085

23456.png

这里记得使能解除保护断电

234.png

然后执行下载,我们下载一个24KB的随机代码

123.png

此时读取,会返回error

23455.png

(4)由于这个不是RDP读保护,没有做自动解除。

点击这里解除保护即可

下载.png



回复

使用道具 举报

9

主题

176

回帖

203

积分

高级会员

积分
203
发表于 2025-9-30 11:34:16 | 显示全部楼层
全片 PCROP 保护后代码还能正常运行不?
ST 的 PCROP, 启用后是阻止 '数据总线' 访问指定区域, 只允许 '指令总线' 访问, 所以例如常量数据那些不能放到 PCROP 区域里
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
119429
QQ
 楼主| 发表于 2025-9-30 11:43:52 | 显示全部楼层
avita 发表于 2025-9-30 11:34
全片 PCROP 保护后代码还能正常运行不?
ST 的 PCROP, 启用后是阻止 '数据总线' 访问指定区域, 只允许 '指 ...

对,ST那个一般配合MDK的Excute - only一起使用。

002B的这个我还没测,过两天我试试。
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
119429
QQ
 楼主| 发表于 2025-10-2 16:14:24 | 显示全部楼层
avita 发表于 2025-9-30 11:34
全片 PCROP 保护后代码还能正常运行不?
ST 的 PCROP, 启用后是阻止 '数据总线' 访问指定区域, 只允许 '指 ...

已经实际测试,整个芯片开启PCROP后,这个区域内程序的数据访问没问题,测试了个const常量访问,正常

回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
119429
QQ
 楼主| 发表于 2025-10-2 16:16:36 | 显示全部楼层
实测了一个例子,官方例子软件包


PY32F002B_Firmware_V1.2.1\Projects\PY32F002B-STK\Example\GPIO\GPIO_Toggle

开启整个芯片SDK保护后,可以正常使用。

[C] 纯文本查看 复制代码
/**
  ******************************************************************************
  * @file    main.c
  * @author  MCU Application Team
  * @brief   Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&#169; Copyright (c) 2023 Puya Semiconductor Co.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by Puya under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  * @attention
  *
  * <h2><center>&#169; Copyright (c) 2016 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private define ------------------------------------------------------------*/
#define LED_GPIO_PIN                 LED3_PIN
#define LED_GPIO_PORT                LED3_GPIO_PORT
#define LED_GPIO_CLK_ENABLE()        LED3_GPIO_CLK_ENABLE()

/* Private variables ---------------------------------------------------------*/
/* Private user code ---------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
static void APP_GpioConfig(void);

const char sdktest = 100;

/**
  * @brief  Main program.
  * @retval int
  */
int main(void)
{
  /* Reset of all peripherals, Initializes the Systick. */
  HAL_Init();
  
  /* Initialize GPIO */
  APP_GpioConfig();

  while (1)
  {
    /* Delay 250ms */
    HAL_Delay(250);
          
         if(sdktest == 100)
         {
                /* LED flipping */
                HAL_GPIO_TogglePin(LED_GPIO_PORT, LED_GPIO_PIN);
         }
  }
}

/**
  * @brief  GPIO configuration.
  * @param  None
  * @retval None
  */
static void APP_GpioConfig(void)
{
  GPIO_InitTypeDef  GPIO_InitStruct = {0};

  LED_GPIO_CLK_ENABLE();                                 /* Enable GPIOA clock */

  GPIO_InitStruct.Pin = LED_GPIO_PIN;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;            /* Push-pull output */
  GPIO_InitStruct.Pull = GPIO_PULLUP;                    /* Enable pull-up */
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;          /* GPIO speed */  
  /* GPIO initialization */
  HAL_GPIO_Init(LED_GPIO_PORT, &GPIO_InitStruct);
}

/**
  * @brief  Error executing function.
  * @param  None
  * @retval None
  */
void APP_ErrorHandler(void)
{
  while (1)
  {
  }
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* Users can add their own printing information as needed,
     for example: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* Infinite loop */
  while (1)
  {
  }
}
#endif /* USE_FULL_ASSERT */

/************************ (C) COPYRIGHT Puya *****END OF FILE******************/



正常保护,无法读取

123.png

2345.png



回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-11-21 23:46 , Processed in 0.045390 second(s), 27 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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