IC解密环境说明
本文使用的软硬件环境已经在前面介绍
硬件
基于 HC32L110 系列MCU的开发板
JLink OB
软件
Ubuntu20.04
VSCode
IC解密配置步骤
安装配置 Cortex-Debug
在VSCode的插件中, 搜索安装Cortex-Debug
IC解密在VSCode中, 切换到Run And Debug, 点击上方的 Add Configuration, 会在 .vscode 目录下的 launch.json (如果没有会自动创建)中添加配置, 需要增加对应的配置信息
- "configurations": [
 
-         {
 
-             "name": "Cortex Debug",
 
-             "cwd": "${workspaceFolder}",
 
-             "executable": "${workspaceFolder}/Build/app.elf",
 
-             "request": "launch",        // 可以是launch或attach, 后者表示运行中接入, 前者会执行前置任务并重启
 
-             "type": "cortex-debug",
 
-             "runToEntryPoint": "main",
 
-             "servertype": "jlink",
 
-             "device": "HC32L110X4",     // 如果是32K的版本, 需要修改为 HC32L110X6
 
-             "interface": "swd",
 
-             "runToMain": true,          // false则从 reset handler 开始停留
 
-             "preLaunchTask": "build",   // 根据 tasks.json 中配置的任务填写,
 
-             // "preLaunchCommands": ["Build all"], // 如果不使用 preLaunchTask, 可以用这个参数指定命令行命令
 
-             "svdFile": "",              // svd 用于观察外设
 
-             "showDevDebugOutput": "vscode", // 输出的日志级别, parsed:解析后的内容, raw:直接输出, vscode:包含scode调用和raw
 
-             "swoConfig":
 
-             {
 
-                 "enabled": true,
 
-                 "cpuFrequency": 24000000,
 
-                 "swoFrequency":  4000000,
 
-                 "source": "probe",
 
-                 "decoders":
 
-                 [
 
-                     {
 
-                         "label": "ITM port 0 output",
 
-                         "type": "console",
 
-                         "port": 0,
 
-                         "showOnStartup": true,
 
-                         "encoding": "ascii"
 
-                     }
 
-                 ]
 
-             }
 
-         }
 
-     ]
具体的配置项含义, 可以参考 Debug Attributes
同时在 .vscode/settings.json 中增加以下配置, 如果文件不存在则创建. 路径根据自己的环境修改
- {
 
-     "cortex-debug.gdbPath": "/opt/gcc-arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb",
 
-     "cortex-debug.JLinkGDBServerPath": "/opt/SEGGER/JLink/JLinkGDBServerCLExe",
 
- }
修改 rules.mk
在rules.mk中开启debug, 涉及到两处, OPT要使用-O0, 表示不执行任何优化. 使用优化后代码中的部分变量在编译后会被丢弃无法跟踪
OPT         ?= -O0
在CFLAGS中增加gdb输出
CFLAGS      += -g -gdwarf-2 # original: -g
这样编译后, 尺寸会比原先大不少