Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GD32350G-START setup #9

Open
ch1nq opened this issue Feb 17, 2023 · 9 comments
Open

GD32350G-START setup #9

ch1nq opened this issue Feb 17, 2023 · 9 comments

Comments

@ch1nq
Copy link

ch1nq commented Feb 17, 2023

Hi,

I don't know if this is the right place to ask, but any help will be appriciated.

I have a GD32350G-START development board that PlatformIO does not seem to recognize as a device. I can still compile the examples from this repo (which are great!) and flash them using the gdlinkcli upload protocol on my Windows machine. However, I need to flash the board using a linux machine and obviously can't call the GD_Link_CLI.exe, so I was wondering if there is any way to flash the board using without it?

My current hardware setup is:

PC -> USB Barrel connector -> GD32350G-START <- USB (on GDLink side) <- PC
@maxgerhardt
Copy link
Member

GDLinkCLI is indeed Windows only. The default upload protocol for the GD32F350G-START is cmsis-dap, aka the "GD-Link" on-board, which is accessed using openocd, which we special-adapted and made available for all operating systems. So you should have 0 problems uploading + debugging on Linux.

https://github.com/CommunityGD32Cores/platform-gd32/blob/f1578376c30087790bf67e9ee5e46662f057b95d/boards/gd32350g_start.json#L34

What exact platformio.ini are you using so that it attempts to upload with GD_Link_CLI? Very curious.

@ch1nq
Copy link
Author

ch1nq commented Feb 17, 2023

I have been manually overriding the platform.ini with upload_protocol = gdlinkcli on all the examples to get them to work.

An example: When I use the default upload protocol on gd32-spl-blinky example, it outputs the following error on both linux and windows:

CURRENT: upload_protocol = cmsis-dap
Uploading .pio\build\gd32350g_start\firmware.elf
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-12-07-17:33)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

swd
0x2ba01477
0x10000
*** [upload] Error 3221225477

@maxgerhardt
Copy link
Member

Well that's not supposed to happen.

3221225477 is 0xC0000005 in hexadecimal, which is NTSTATUS code STATUS_ACCESS_VIOLATION. Your

So.. openocd is crashing, or a library call it does. I've seen some problems regarding crashes in OpenOCD related to old libusb version, and coincidentally I've packaged OpenOCD with libusb-1.0.dll version 1.0.24. Can you go to C:\Users\<user>\.platformio\packages\tool-openocd-gd32\bin and replace libusb-1.0.dll with the version found in https://github.com/libusb/libusb/releases/download/v1.0.26/libusb-1.0.26-binaries.7z VS2015-x64\dll\?

If that doesn't get you further you can go to the Linux system, view the invoked command line with the project task Advanced->Verbose Upload, then use gdb to launch the same binary with the same argument and see where it crashes.

I'm also cross-checking this on my Windows + Linux system, since I do have exactly a GD32350G-START board here.

@ch1nq
Copy link
Author

ch1nq commented Feb 17, 2023

I tried replacing the libusb-1.0.dll, but i get the same error.

I only use the pio cli on the linux system, but on the windows system running the "verbose upload", e.g.,

pio run -v -t upload -e gd32350g_start

gives the following:

Processing gd32350g_start (board: gd32350g_start; framework: spl; platform: https://github.com/CommunityGD32Cores/platform-gd32.git; platform_packages: framework-spl-gd32@https://github.com/CommunityGD32Cores/gd32-pio-spl-package.git)
--------------------------------------------------------------------------CONFIGURATION: https://docs.platformio.org/page/boards/gd32/gd32350g_start.html
PLATFORM: GD GD32 (1.0.0+sha.f157837) (git+https://github.com/CommunityGD32Cores/platform-gd32.git) > GD32350G-START
HARDWARE: GD32F350G8U6 108MHz, 8KB RAM, 64KB Flash
DEBUG: Current (cmsis-dap) On-board (cmsis-dap) External (blackmagic, jlink, stlink)
PACKAGES:
 - framework-spl-gd32 @ 2.10000.0+sha.43a133d (git+https://github.com/CommunityGD32Cores/gd32-pio-spl-package.git)
 - tool-dfuutil @ 1.9.200310
 - tool-gdlinkcli @ 2.40611.220807+sha.74386ec (git+https://github.com/CommunityGD32Cores/pio-gd32-gdlinkcli.git)
 - tool-openocd-gd32 @ 2.1100.211207 (11.0)
 - tool-stm32duino @ 1.0.2
 - toolchain-gccarmnoneeabi @ 1.90201.191206 (9.2.1)
==== STARTUP FILE: startup_gd32f3x0.S ======
SPL libraries are included: True  
CMSIS libraries are included: True
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
USBFS source filter excludes: ['-<*>', '+<driver\\Source*>']      
Added CMSIS-DSP library for arm_cortexM4l_math
Found 12 compatible libraries
Scanning dependencies...     
No dependencies
Building in release mode
MethodWrapper(["checkprogsize"], [".pio\build\gd32350g_start\firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"RAM:   [          ]   0.4% (used 36 bytes from 8192 bytes)
Flash: [          ]   2.0% (used 1284 bytes from 65536 bytes)
.pio\build\gd32350g_start\firmware.elf  :

section             size        addr

.isr_vector          336   134217728

.text               1272   134218064

.rodata                0   134219336

.init_array            4   134219336

.fini_array            4   134219340

.data                  4   536870912

.bss                  32   536870916

._user_heap_stack   1536   536870948

.ccram_bss             0   268435456

.ccram_data            0   268435456

.ARM.attributes       46           0

.comment             102           0

.debug_frame          44           0

Total               3380
<lambda>(["upload"], [".pio\build\gd32350g_start\firmware.elf"])
AVAILABLE: blackmagic, cmsis-dap, jlink, mbed, stlink
CURRENT: upload_protocol = cmsis-dap
openocd -d2 -s C:\Users\Aske\.platformio\packages\tool-openocd-gd32/scripts -f interface/cmsis-dap.cfg -c "transport select swd" -c "set CPUTAPID 0x2ba01477" -c "set FLASH_SIZE 0x10000" -f target/stm32f1x.cfg -c "program {.pio\build\gd32350g_start\firmware.elf}  verify reset; shutdown;"
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-12-07-17:33)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 2

swd
0x2ba01477
0x10000
Info : DEPRECATED target event trace-config; use TPIU events {pre,post}-{enable,disable}

and running it on linux gives

Processing gd32350g_start (board: gd32350g_start; framework: spl; upload_protocol: cmsis-dap; platform: https://github.com/CommunityGD32Cores/
platform-gd32.git; platform_packages: framework-spl-gd32@https://github.com/CommunityGD32Cores/gd32-pio-spl-package.git)
----------------------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/gd32/gd32350g_start.html
PLATFORM: GD GD32 (1.0.0+sha.f157837) (git+https://github.com/CommunityGD32Cores/platform-gd32.git) > GD32350G-START
HARDWARE: GD32F350G8U6 108MHz, 8KB RAM, 64KB Flash
DEBUG: Current (cmsis-dap) On-board (cmsis-dap) External (blackmagic, jlink, stlink)
PACKAGES:
 - framework-spl-gd32 @ 2.10000.0+sha.67e2ef5 (git+https://github.com/CommunityGD32Cores/gd32-pio-spl-package.git)
 - tool-dfuutil @ 1.9.200310
 - tool-gdlinkcli @ 2.40611.220807+sha.74386ec (git+https://github.com/CommunityGD32Cores/pio-gd32-gdlinkcli.git)
 - tool-openocd-gd32 @ 2.1100.211207 (11.0)
 - tool-stm32duino @ 1.0.1
 - toolchain-gccarmnoneeabi @ 1.90201.191206 (9.2.1)
==== STARTUP FILE: startup_gd32f3x0.S ======
SPL libraries are included: True
CMSIS libraries are included: True
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
USBFS source filter excludes: ['-<*>', '+<driver/Source*>']
Added CMSIS-DSP library for arm_cortexM4l_math
Found 12 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
MethodWrapper(["checkprogsize"], [".pio/build/gd32350g_start/firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.4% (used 36 bytes from 8192 bytes)
Flash: [          ]   2.0% (used 1280 bytes from 65536 bytes)
.pio/build/gd32350g_start/firmware.elf  :
section             size        addr
.isr_vector          336   134217728
.text               1268   134218064
.rodata                0   134219332
.init_array            4   134219332
.fini_array            4   134219336
.data                  4   536870912
.bss                  32   536870916
._user_heap_stack   1536   536870948
.ccram_bss             0   268435456
.ccram_data            0   268435456
.ARM.attributes       46           0
.comment             102           0
.debug_frame          44           0
Total               3376
<lambda>(["upload"], [".pio/build/gd32350g_start/firmware.elf"])
AVAILABLE: blackmagic, cmsis-dap, jlink, mbed, stlink
CURRENT: upload_protocol = cmsis-dap
openocd -d2 -s /home/jeff/.platformio/packages/tool-openocd-gd32/scripts -f interface/cmsis-dap.cfg -c "transport select swd" -c "set CPUTAPID
 0x2ba01477" -c "set FLASH_SIZE 0x10000" -f target/stm32f1x.cfg -c "program {.pio/build/gd32350g_start/firmware.elf}  verify reset; shutdown;"
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-12-07-17:30)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 2

swd
0x2ba01477
0x10000
Info : DEPRECATED target event trace-config; use TPIU events {pre,post}-{enable,disable}
Error: unable to open CMSIS-DAP device 0x28e9:0x58f
Error: unable to find a matching CMSIS-DAP device
Error: No Valid JTAG Interface Configured.
*** [upload] Error 255

It seems i get an error 255 on the linux system.

Great that you also have the board and can help debug the problem - I really appreciate the help!

@maxgerhardt
Copy link
Member

maxgerhardt commented Feb 17, 2023

First try plugging the board in and it just works.

CURRENT: upload_protocol = cmsis-dap
openocd -d2 -s C:\Users\Max\.platformio\packages\tool-openocd-gd32/scripts -f interface/cmsis-dap.cfg -c "transport select swd" -c "set CPUTAPID 0x2ba01477" -c "set FLASH_SIZE 0x10000" -f target/stm32f1x.cfg -c "program {.pio\build\gd32350g_start\firmware.elf}  verify reset; shutdown;"
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-12-07-17:33)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 2

swd
0x2ba01477
0x10000
Info : DEPRECATED target event trace-config; use TPIU events {pre,post}-{enable,disable}
Info : CMSIS-DAP: SWD  supported
Info : CMSIS-DAP: JTAG supported
Info : CMSIS-DAP: Atomic commands supported
Info : CMSIS-DAP: Test domain timer supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : stm32f1x.cpu: Cortex-M4 r0p1 processor detected
Info : stm32f1x.cpu: target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f1x.cpu on 3333
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000190 msp: 0x20002000
** Programming Started **
Info : device id = 0x17040410
Warn : STM32 flash size failed, probe inaccurate - assuming 128k flash
Info : ignoring flash probed value, using configured bank size
Info : flash size = 64kbytes
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked
===================================================================================== [SUCCESS] Took 3.19 seconds =====================================================================================

I'm powering the board with 2xUSB though, so the above USB port with the switch to the right position and the lower USB port for the actual GDLink are both connected.

Can you verify on Windows using Zadig that the "CMSIS-DAP" device has HidUSB drivers loaded?

grafik

@maxgerhardt
Copy link
Member

On Linux I get the same

Error: unable to open CMSIS-DAP device 0x28e9:0x58f
Error: unable to find a matching CMSIS-DAP device

Error with the USB device forwarded, but I think that's just a very simple udev rules error / would work with sudo. Let me just add a line in the PlatformIO udev rules..

@maxgerhardt
Copy link
Member

Ah, actually I didn't even have the PlatformIO udev rules installed, silly me. Following

https://docs.platformio.org/en/latest/core/installation/udev-rules.html#platformio-udev-rules

and logging out & back in again on my Ubuntu 22.04 system made my normal user be able to access to the CMSIS-DAP device and upload it, no problems.

<lambda>(["upload"], [".pio/build/gd32350g_start/firmware.elf"])
AVAILABLE: blackmagic, cmsis-dap, jlink, mbed, stlink
CURRENT: upload_protocol = cmsis-dap
openocd -d2 -s /home/max/.platformio/packages/tool-openocd-gd32/scripts -f interface/cmsis-dap.cfg -c "transport select swd" -c "set CPUTAPID 0x2ba01477" -c "set FLASH_SIZE 0x10000" -f target/stm32f1x.cfg -c "program {.pio/build/gd32350g_start/firmware.elf}  verify reset; shutdown;"
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-12-07-17:30)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 2

swd
0x2ba01477
0x10000
Info : DEPRECATED target event trace-config; use TPIU events {pre,post}-{enable,disable}
Info : CMSIS-DAP: SWD  supported
Info : CMSIS-DAP: JTAG supported
Info : CMSIS-DAP: Atomic commands supported
Info : CMSIS-DAP: Test domain timer supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : stm32f1x.cpu: Cortex-M4 r0p1 processor detected
Info : stm32f1x.cpu: target has 6 breakpoints, 4 watchpoints
Info : stm32f1x.cpu: external reset detected
Info : starting gdb server for stm32f1x.cpu on 3333
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000190 msp: 0x20002000
** Programming Started **
Info : device id = 0x17040410
Warn : STM32 flash size failed, probe inaccurate - assuming 128k flash
Info : ignoring flash probed value, using configured bank size
Info : flash size = 64kbytes
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked
========================================================================= [SUCCESS] Took 1.91 seconds =========================================================================

So both Windows+Linux uploads are working for me, hm.

@ch1nq
Copy link
Author

ch1nq commented Feb 18, 2023

I got the linux working by installing the udev rules!

I verified that I have the exact same HidUSB drivers on the CMSIS-DAP device, but Windows is still giving the Error 3221225477. However, since I can flash it on linux I do not strictly need Windows to work now, so I might leave it at that.

If you want to dig deeper into the issue, let me know if there is anything I can help with. If not, then thank you for your help!

@maxgerhardt
Copy link
Member

Non-working OpenOCD upload on Windows for some users is indeed absolutely critical. Can you please get GDB downloading https://github.com/brechtsanders/winlibs_mingw/releases/download/12.2.0-15.0.7-10.0.0-ucrt-r4/winlibs-x86_64-posix-seh-gcc-12.2.0-llvm-15.0.7-mingw-w64ucrt-10.0.0-r4.7z, extracting and adding the extracted to the PATH enviornment variable.

Then check that in a new terminal (Windows+R -> cmd.exe) the command gdb --version is returning GNU gdb 12.1 and execute

gdb -ex=r --args "C:\Users\Max\.platformio\packages\tool-openocd-gd32\bin\openocd.exe" -s "C:\Users\Max\.platformio\packages\tool-openocd-gd32/scripts" -f interface/cmsis-dap.cfg -c "transport select swd" -c "set CPUTAPID 0x2ba01477" -c "set FLASH_SIZE 0x10000" -f target/stm32f1x.cfg -c "init; reset; shutdown"

Adapt paths as needed.

For me it says

swd
0x2ba01477
0x10000
Info : DEPRECATED target event trace-config; use TPIU events {pre,post}-{enable,disable}
warning:
warning: AllK required contiguous memory = 675016 (64bit)
warning:   8 HotK Handles: HandleSize 2112 PoolSize 16912 (bytes)
warning:   64 LstK Handles: HandleSize 64 PoolSize 4112 (bytes)
warning:   2048 LstInfoK Handles: HandleSize 64 PoolSize 131088 (bytes)
warning:   128 UsbK Handles: HandleSize 96 PoolSize 12304 (bytes)
warning:   64 DevK Handles: HandleSize 112 PoolSize 7184 (bytes)
warning:   2048 OvlK Handles: HandleSize 104 PoolSize 213008 (bytes)
warning:   64 OvlPoolK Handles: HandleSize 96 PoolSize 6160 (bytes)
warning:   32 StmK Handles: HandleSize 176 PoolSize 5648 (bytes)
warning:   2048 IsochK Handles: HandleSize 136 PoolSize 278544 (bytes)
warning:
warning: Dynamically allocated as needed:
warning:        KLST_DEVINFO = 2596 bytes each
[New Thread 7960.0x2684]
[Thread 7960.0x2684 exited with code 0]
Info : CMSIS-DAP: SWD  supported
Info : CMSIS-DAP: JTAG supported
Info : CMSIS-DAP: Atomic commands supported
Info : CMSIS-DAP: Test domain timer supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : stm32f1x.cpu: Cortex-M4 r0p1 processor detected
Info : stm32f1x.cpu: target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f1x.cpu on 3333
Info : Listening on port 3333 for gdb connections
shutdown command invoked
[Thread 7960.0x31f4 exited with code 0]
[Thread 7960.0x24fc exited with code 0]
[Thread 7960.0x1738 exited with code 0]
[Inferior 1 (process 7960) exited normally]
(gdb)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants