KEIL MDK Debug 配置 =========================== 以下使用 **固件库** 的 **HT32F52352** KEIL5 范例工程对, Debugger 使用 **e-Link32Pro** 来进行说明。 SWD 调试接口 ------------------------- 1. holtek **e-Link32Pro** Debugger (调试器),及其接口定义: .. figure:: ../_static/image/Software/Project_Debug/image001.png :width: 80% :align: center :alt: e-Link32Pro e-Link32Pro **e-Link32Pro** 相关接口定义,可在 **固件库** 中找到说明文档 ``\Document_Tools\e-Link32_e-Link32 Pro(User'Guide)v130.pdf`` . **e-Link32Pro** 除了 SWD 调试接口,还支持 UART 接口 : **PIN7(RXD) & PIN8(TXD)** ,可连接 MCU - U(S)ART ,可在串口助手找到对应COM端口进行收发数据。 .. figure:: ../_static/image/Software/Project_Debug/image002.png :width: 80% :align: center :alt: e-Link32Pro 接口定义 e-Link32Pro 接口定义 .. tip:: - e-Link32Pro 出厂默认不对外供电,MCU-SWD 需供电运行才会使能,所以使用e-Link32 Pro需外部给MCU供电。 - e-Link32Pro 在安装KEIL/IAR时,会自带驱动,不需要额外安装驱动。 2. Cortex-M 内核MCU都支持SWD调试接口: SWD 调试接口需要用五根线, e-Link32Pro-SWD 和 MCU-SWD 一一对应连接。 **SWD** : **VDD – SWDIO – SWCLK – nRST – VSS** .. figure:: ../_static/image/Software/Project_Debug/image003.png :width: 80% :align: center :alt: SWD 连接范例 SWD 连接范例 .. warning:: 早期调试接口不引出 nRST pin , 但是当 SWDIO 、 SWCLK 在程序中复用成 GPIO ,将无法再使用 SWD 仿真&烧录,只能选择使用ISP模式进行擦除恢复,所以建议调试接口一定要加入nRST pin ,可在仿真&烧录时,复位为SWD接口。 .. _IDE Debugger: KEIL 仿真工程配置 ------------------------- 1. ``Option -> Utilities`` 选择 ``Use Debug Driver`` ,使用 ``Debugger`` 来操作MCU的FLASH。 .. figure:: ../_static/image/Software/Project_Debug/image005.png :width: 80% :align: center :alt: Debugger 配置Debugger 2. 在 **HT32F52352** 的 KEIL5 工程中, ``Option -> Debug`` 中, 使用 **e-Link32Pro** 选择 ``CMSIS-DAP`` 。 .. figure:: ../_static/image/Software/Project_Debug/image004.png :width: 80% :align: center :alt: 选择 Debugger 选择 Debugger .. tip:: 如果 **Debugger** 使用 **J-Link** ,可参考 :doc:`J-LINK使用相关 <../Tools/jlink>` 。 .. _Debugger Clock: 3. 在 ``Option -> Debug`` 选项中,打开 ``Setting`` 设置,将 ``CMSIS-DAP-JTAG/SW Adapter`` 设置如下: - **SWJ** : ``V`` - **Port** : ``SW`` - **Max Clock** : ``1MHz``, 请保证接线较短,接触良好,如有烧录问题,建议降低速度,选择 ``500kHz`` 或更低 。 .. figure:: ../_static/image/Software/Project_Debug/image006.png :width: 80% :align: center :alt: CMSIS-DAP 配置 CMSIS-DAP 配置 .. _Debugger set: 4. 如果MCU-SWD接口: SWDIO SWCLK 在程序中复用为 GPIO , 造成 **Debugger** 无法连接MCU,则需要通过 **Debugger** 通过 MCU - nRST 复位 SWD 接口。 - **Debugger** - Reset 和 MCU - nRST 连接。 - 在 ``Debug`` 窗口中, ``Connect & Reset Option`` 中设置: - **Connect** : ``under Reset`` - **Reset** : ``Autodetect`` .. figure:: ../_static/image/Software/Project_Debug/image014.png :width: 80% :align: center :alt: under Reset under Reset .. note:: 如未连接 仿真器 **Debugger** , ``SW Device`` 窗口会提示 ``No Debug Unit Device Found`` 。 这种情况,请检查你的 **Debugger** 是否有正确连接到计算机的 USB 接口。 .. figure:: ../_static/image/Software/Project_Debug/image007.png :width: 80% :align: center :alt: Debugger 未连接 Debugger 未连接 5. Debugger SWD 连接到 MCU, ``SW Device`` 窗口会提示对应的 **MCU-IDCODE** ,说明已经可以进行 仿真&烧录 。 .. figure:: ../_static/image/Software/Project_Debug/image008.png :width: 80% :align: center :alt: Debugger 连接HT32成功 Debugger 连接HT32成功 .. note:: 如未通过Debugger SWD 连接到 MCU ,会提示 ``SWD/JTAG Communication Failure`` 。 这种情况,请检查你的目标板是否已经供电,Debugger 默认不对外供电。 .. figure:: ../_static/image/Software/Project_Debug/image009.png :width: 80% :align: center :alt: Debugger 连接不到HT32 Debugger 连接不到HT32 6. ``Debug`` 窗口内容不会实时更新,需要关闭选项卡后,再重新打开才会更新。 .. figure:: ../_static/image/Software/Project_Debug/image010.png :width: 80% :align: center :alt: SW Device 更新 SW Device SWD 更新 7. 选择 ``Trace`` 窗口,注意 **Core Clock** 默认为 ``10MHz`` 。 .. figure:: ../_static/image/Software/Project_Debug/image011.png :width: 80% :align: center :alt: Trace Core Clock Trace Core Clock .. _Programming Algorithm: 8. 在 ``Flash DownLoad`` 窗口,查看以下两个配置: - **下载功能** **DownLoad Function** :设置 **FLASH 擦除方式** 和 **FLASH 烧录方式** 。 - **烧录区域** **Programming Algorithm**:检查是否有以下对应的两个项目: - ``HT32 Series Flash`` - ``HT32 Series Flash Options`` .. figure:: ../_static/image/Software/Project_Debug/image012.png :width: 80% :align: center :alt: Flash DownLoad Flash DownLoad .. note:: 若没有这两个项目,点击添加,将HT32的两个项目添加即可。 - ``HT32 Series Flash`` - ``HT32 Series Flash Options`` .. figure:: ../_static/image/Software/Project_Debug/image013.png :width: 80% :align: center :alt: Programming Algorithm Programming Algorithm .. tip:: - 如果没有特别的需要(如 **IAP_AP、OTA、FLASH存储数据** 等),建议使用 **全片擦除** ``Erase Full Chip`` 。 - 如果希望 KEIL 烧录程序后,MCU 马上进行复现运行 ,则点选 **复位&运行** ``Reset and Run`` 。 .. _HT32_fullclear : KEIL 仿真&烧录 功能 ------------------------- 1. 在 ``Flash`` 选项,可以选择以下两种操作: - **Download** : 烧录 - **Erase** :全片擦除 .. figure:: ../_static/image/Software/Project_Debug/image015.png :width: 80% :align: center :alt: Flash 选项 Flash 选项 .. tip:: 使用 ``Download`` 按钮也可以进行烧录。 .. figure:: ../_static/image/Software/Project_Debug/image016.png :width: 80% :align: center :alt: Download 按钮 Download 按钮 2. 在 ``Debug`` 选项, 使用 ``Start/Stop Debug Session`` 进入/退出 仿真 Debug。 .. figure:: ../_static/image/Software/Project_Debug/image017.png :width: 80% :align: center :alt: Start/Stop Debug Session Start/Stop Debug Session .. tip:: 使用 ``Debug`` 按钮也可以 进入/退出 仿真 Debug。 .. figure:: ../_static/image/Software/Project_Debug/image018.png :width: 80% :align: center :alt: Debug 按钮 Debug 按钮 3. 在进入仿真 Debug 时, ``View`` 选项, 使能 ``Periodic Window Update`` 后,可在仿真 **全速运行** 时,在 ``Watch`` 窗口定时更新变量数据。 .. figure:: ../_static/image/Software/Project_Debug/image019.png :width: 80% :align: center :alt: Periodic Window Update Periodic Window Update .. tip:: 在仿真 **全速运行** 时, ``Watch`` 窗口定时 **1S** 更新变量数据,中间过程量不会显示,如果需要监控变量数据的变化过程,请使用 **单步调试** 或 **断点调试** 。 **KEIL MDK Debug 配置** 常见问题,请参考 :ref:`FAQ ` 。