shadow578 / framework-hc32f46x-ddl

HUADA DDL for PlatformIO
GNU General Public License v3.0
4 stars 4 forks source link

how to upload and debug use cmsis-dap on platformio? #13

Closed mintisan closed 6 months ago

mintisan commented 6 months ago

I have already compiled the elf binary file using your library and blink example in PlatformIO, but I cannot download and debug it. The error message is as follows:

Processing my_env (platform: https://github.com/shadow578/platform-hc32f46x/archive/1.0.0.zip; framework: ddl; board: generic_hc32f460)
------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/hc32f46x/generic_hc32f460.html
PLATFORM: HC32F46X (1.0.0) > Generic HC32F460 Series
HARDWARE: 8MHz, 188KB RAM, 256KB Flash
PACKAGES:
 - framework-arduino-hc32f46x @ 1.1.0+sha.d89fb4b
 - framework-hc32f46x-ddl @ 2.2.1
 - toolchain-gccarmnoneeabi @ 1.120301.0 (12.3.1)
linker parameters: FLASH_START=0, FLASH_SIZE=262144; BOOT_MODE=1; usable flash size: 262144
Driver Library 'DDL_GPIO_ENABLE' enabled
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Checking size .pio\build\my_env\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.0% (used 36 bytes from 192512 bytes)
Flash: [          ]   1.1% (used 2984 bytes from 262144 bytes)
*** Do not know how to make File target `upload' (C:\Users\mintisan\workplace\HC32F460_PlatformIO\upload).  Stop.
===================================== [FAILED] Took 0.64 seconds =====================================

Processing default ()
------------------------------------------------------------------------------------------------------
UndefinedEnvPlatformError: Please specify platform for 'default' environment

 *  The terminal process "C:\Users\mintisan\.platformio\penv\Scripts\platformio.exe 'run', '--target', 'upload', '--upload-port', 'COM9'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

Here is my .platformio.ini

[env:my_env]
platform = https://github.com/shadow578/platform-hc32f46x/archive/1.0.0.zip
platform_packages =
  framework-hc32f46x-ddl @ https://github.com/shadow578/framework-hc32f46x-ddl/archive/2.2.1.zip

framework = ddl
board = generic_hc32f460
debug_tool = cmsis-dap
upload_protocol = cmsis-dap
debug_port = COM9
upload_port = COM9

# enable the GPIO device driver library
board_build.ddl.gpio = true

[env:default]

# required only for CI
[env:ci]
# override the framework-hc32f46x-ddl package with the local one
board_build.ddl_package_dir = ../../
extra_scripts = 
    pre:../../tools/ci/patch_get_package_dir.py

I can download and debug in Keil, so the driver is ok. image

shadow578 commented 6 months ago

hi, debugging is currently experimentally only supported on the add/debugging_pyocd branch of shadow578/platform-hc32f46x repo.

to use debugging, you have to update the platform entry to use the correct branch like so:

[env:my_env]
platform = https://github.com/shadow578/platform-hc32f46x/archive/refs/heads/add/debugging_pyocd.zip
# ...

please note that the debugging support is still experimental, so support is limited.


as a side note: when using cmsis-dap as debug tool, you don't need to set debug_port = COM9 and upload_port = COM9.

mintisan commented 6 months ago

@shadow578 Thanks for your reply.

I can upload successfully when used you debugging_pyocd branch.

It seems from the logs that the upload was successful, but it did not take effect in reality [possibly due to incorrect flash address?]. This is because I changed the blinking interval of the LED, but there was no change after downloading and restarting.

 *  The terminal process "C:\Users\mintisan\.platformio\penv\Scripts\platformio.exe 'run', '--target', 'upload', '--upload-port', 'COM9'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: C:\Users\mintisan\.platformio\penv\Scripts\platformio.exe run --target upload --upload-port COM9 

Processing myenv (platform: https://github.com/shadow578/platform-hc32f46x/archive/refs/heads/add/debugging_pyocd.zip; framework: ddl; board: generic_hc32f460)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/hc32f46x/generic_hc32f460.html
PLATFORM: HC32F46X (1.0.0) > Generic HC32F460 Series
HARDWARE: 8MHz, 188KB RAM, 256KB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, stlink)
PACKAGES:
 - framework-arduino-hc32f46x @ 1.1.0+sha.d89fb4b
 - framework-hc32f46x-ddl @ 2.2.1
 - toolchain-gccarmnoneeabi @ 1.120301.0 (12.3.1)
linker parameters: FLASH_START=0, FLASH_SIZE=262144; BOOT_MODE=1; usable flash size: 262144
Driver Library 'DDL_GPIO_ENABLE' enabled
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
pyocd_load_cmd $PYTHONEXE -m pyocd load --no-wait --target hc32f460xc --base-address 0x0 $SOURCE
Checking size .pio\build\myenv\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.0% (used 36 bytes from 192512 bytes)
Flash: [          ]   1.1% (used 2984 bytes from 262144 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap
CURRENT: upload_protocol = cmsis-dap
Uploading .pio\build\myenv\firmware.bin
0001571 I Loading C:\Users\mintisan\workplace\HC32F460_PlatformIO\.pio\build\myenv\firmware.bin at 0x00000000 [load_cmd]
[---|---|---|---|---|---|---|---|---|----]
[========================================]
0001914 I Erased 0 bytes (0 sectors), programmed 0 bytes (0 pages), skipped 3072 bytes (6 pages) at 8.76 kB/s [loader]
=========================================================================== [SUCCESS] Took 3.22 seconds ===========================================================================

Processing ci ()
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
UndefinedEnvPlatformError: Please specify platform for 'ci' environment

 *  The terminal process "C:\Users\mintisan\.platformio\penv\Scripts\platformio.exe 'run', '--target', 'upload', '--upload-port', 'COM9'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

This is what I used in Keil flash download setting: image image

mintisan commented 6 months ago

Another upload log, not work either.

pyocd_load_cmd $PYTHONEXE -m pyocd load --no-wait --target hc32f460xc --base-address 0x0 $SOURCE
Checking size .pio\build\myenv\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.0% (used 36 bytes from 192512 bytes)
Flash: [          ]   1.1% (used 2984 bytes from 262144 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap
CURRENT: upload_protocol = cmsis-dap
Uploading .pio\build\myenv\firmware.bin
0001580 I Loading C:\Users\mintisan\workplace\HC32F460_PlatformIO\.pio\build\myenv\firmware.bin at 0x00000000 [load_cmd]
[---|---|---|---|---|---|---|---|---|----]
[========================================]
0002015 I Erased 8192 bytes (1 sector), programmed 3072 bytes (6 pages), skipped 0 bytes (0 pages) at 6.90 kB/s [loader]
=========================================================================== [SUCCESS] Took 3.33 seconds ===========================================================================
shadow578 commented 6 months ago

please make sure that you've actually modified the source, as in the log you've posted nothing got compiled... if you're unsure, clean the project before uploading