STM32CubeMX生成工程 SWD无法下载

 

问题现象:

使用STM32CubeMX生成工程后,使用SWD下载,第二次无法下载。

错误提示:

* JLink Info: STM32 (connect): Can not attach to CPU. Trying connect under reset.
* JLink Info: STM32 (connect): Can not attach to CPU. Trying connect under reset.
***JLink Error: STM32: Connecting to CPU via connect under reset failed.
Error: Flash Download failed  -  Target DLL has been cancelled

原因分析:

使用STM32CubeMX生成的工程,使用SWD下载,需要配置。

解决办法:

STM32CubeMX生成工程 SWD无法下载_第1张图片

 

STM32CubeMX生成工程 SWD无法下载_第2张图片

步骤:

更改STM32CubeMX配置

SYS>Debug>SerialWire


 使用 Compare Beyond 比较两个工程代码:

STM32CubeMX生成工程 SWD无法下载_第3张图片

 

HAL_Init();
    > HAL_MspInit();
        >>    
             /**NOJTAG: JTAG-DP Disabled and SW-DP Enabled */
              __HAL_AFIO_REMAP_SWJ_NOJTAG();

异常工程:
        >>    
              /**DISABLE: JTAG-DP Disabled and SW-DP Disabled */
              __HAL_AFIO_REMAP_SWJ_DISABLE();

固件下载操作:

按住复位键 > 点击 Download > 提示框更新 如下内容 > 松开复位键 > 正常下载

(期间复位键一定要按住,否则会有警告提示框,再次重复上述操作即可)

* JLink Info: Found SW-DP with ID 0x1BA01477
* JLink Info: Active write protected STM32 device detected.
This could cause problems during flash download.
Note: Unsecuring will trigger a mass erase of the internal flash.
* JLink Info: Executing default behavior previously saved in the registry.
* JLink Info: Device was not unsecured. No action performed.
* JLink Info: Found SW-DP with ID 0x1BA01477
* JLink Info: Scanning AP map to find all available APs
* JLink Info: AP[1]: Stopped AP scan as end of AP map has been reached
* JLink Info: AP[0]: AHB-AP (IDR: 0x14770011)
* JLink Info: Iterating through AP map to find AHB-AP to use
* JLink Info: AP[0]: Core found
* JLink Info: AP[0]: AHB-AP ROM base: 0xE00FF000
* JLink Info: CPUID register: 0x411FC231. Implementer code: 0x41 (ARM)
* JLink Info: Found Cortex-M3 r1p1, Little endian.
* JLink Info: FPUnit: 6 code (BP) slots and 2 literal slots
* JLink Info: CoreSight components:
* JLink Info: ROMTbl[0] @ E00FF000
* JLink Info: ROMTbl[0][0]: E000E000, CID: B105E00D, PID: 001BB000 SCS
* JLink Info: ROMTbl[0][1]: E0001000, CID: B105E00D, PID: 001BB002 DWT
* JLink Info: ROMTbl[0][2]: E0002000, CID: B105E00D, PID: 000BB003 FPB
* JLink Info: ROMTbl[0][3]: E0000000, CID: B105E00D, PID: 001BB001 ITM
* JLink Info: ROMTbl[0][4]: E0040000, CID: B105900D, PID: 001BB923 TPIU-Lite
ROMTableAddr = 0xE00FF000
* JLink Info: Reset: Halt core after reset via DEMCR.VC_CORERESET.
* JLink Info: Reset: Reset device via AIRCR.SYSRESETREQ.
* JLink Info: Reset: S_RESET_ST never gets cleared. CPU seems to be kept in reset forever.
* JLink Info: Reset: Using fallback: Reset pin.
* JLink Info: Reset: Halt core after reset via DEMCR.VC_CORERESET.
* JLink Info: Reset: Reset device via reset pin
* JLink Info: Reset: VC_CORERESET did not halt CPU. (Debug logic also reset by reset pin?).
* JLink Info: Reset: Reconnecting and manually halting CPU.
* JLink Info: Found SW-DP with ID 0x1BA01477
* JLink Info: AP map detection skipped. Manually configured AP map found.
* JLink Info: AP[0]: AHB-AP (IDR: Not set)
* JLink Info: AP[0]: Core found
* JLink Info: AP[0]: AHB-AP ROM base: 0xE00FF000
* JLink Info: CPUID register: 0x411FC231. Implementer code: 0x41 (ARM)
* JLink Info: Found Cortex-M3 r1p1, Little endian.
**JLink Warning: CPU could not be halted
* JLink Info: Reset: Core did not halt after reset, trying to disable WDT.
* JLink Info: Reset: Halt core after reset via DEMCR.VC_CORERESET.
* JLink Info: Reset: Reset device via reset pin
* JLink Info: Reset: VC_CORERESET did not halt CPU. (Debug logic also reset by reset pin?).
* JLink Info: Reset: Reconnecting and manually halting CPU.
* JLink Info: Found SW-DP with ID 0x1BA01477
* JLink Info: AP map detection skipped. Manually configured AP map found.
* JLink Info: AP[0]: AHB-AP (IDR: Not set)
* JLink Info: AP[0]: Core found
* JLink Info: AP[0]: AHB-AP ROM base: 0xE00FF000
* JLink Info: CPUID register: 0x411FC231. Implementer code: 0x41 (ARM)
* JLink Info: Found Cortex-M3 r1p1, Little endian.
**JLink Warning: CPU could not be halted
* JLink Info: Reset: Failed. Toggling reset pin and trying reset strategy again.
* JLink Info: Found SW-DP with ID 0x1BA01477
* JLink Info: AP map detection skipped. Manually configured AP map found.
* JLink Info: AP[0]: AHB-AP (IDR: Not set)
* JLink Info: AP[0]: Core found
* JLink Info: AP[0]: AHB-AP ROM base: 0xE00FF000
* JLink Info: CPUID register: 0x411FC231. Implementer code: 0x41 (ARM)
* JLink Info: Found Cortex-M3 r1p1, Little endian.
* JLink Info: Reset: Halt core after reset via DEMCR.VC_CORERESET.
* JLink Info: Reset: Reset device via AIRCR.SYSRESETREQ.
* JLink Info: Reset: S_RESET_ST never gets cleared. CPU seems to be kept in reset forever.
* JLink Info: Reset: Using fallback: Reset pin.
* JLink Info: Reset: Halt core after reset via DEMCR.VC_CORERESET.
* JLink Info: Reset: Reset device via reset pin
* JLink Info: Reset: VC_CORERESET did not halt CPU. (Debug logic also reset by reset pin?).
* JLink Info: Reset: Reconnecting and manually halting CPU.
* JLink Info: Found SW-DP with ID 0x1BA01477
* JLink Info: AP map detection skipped. Manually configured AP map found.
* JLink Info: AP[0]: AHB-AP (IDR: Not set)
* JLink Info: AP[0]: Core found
* JLink Info: AP[0]: AHB-AP ROM base: 0xE00FF000
* JLink Info: CPUID register: 0x411FC231. Implementer code: 0x41 (ARM)
* JLink Info: Found Cortex-M3 r1p1, Little endian.

 

你可能感兴趣的:(嵌入式,SWD,STM32CubeMX)