Custom board build error (GD32F470_EVAL)

The following build error occurs. What should I do?

PS C:\Users\JJS\projects\gd32eval\gd32-pio-projects\gd32-arduino-blinky> pio run -e genericGD32F470ZK   
Processing genericGD32F470ZK (board: genericGD32F470ZK; framework: arduino; platform: https://github.com/CommunityGD32Cores/platform-gd32.git)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/gd32/genericGD32F470ZK.html
PLATFORM: GD GD32 (1.0.0+sha.417eefe) > GD32F470ZK (256k RAM, 3072k Flash)
HARDWARE: GD32F470ZKT6 240MHz, 256KB RAM, 3MB Flash
DEBUG: Current (stlink) External (blackmagic, cmsis-dap, jlink, sipeed-rv-debugger, stlink)
PACKAGES:
 - framework-arduinogd32 @ 4.20000.210603+sha.977fef9
 - toolchain-gccarmnoneeabi @ 1.90201.191206 (9.2.1)
TypeError: Directory C:\Users\JJS\.platformio\packages\framework-arduinogd32\variants\GD32F470ZK_EVAL found where file expected.:
  File "C:\Users\JJS\.platformio\penv\lib\site-packages\platformio\builder\main.py", line 188:
    env.SConscript("$BUILD_SCRIPT")
  File "C:\Users\JJS\.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Script\SConscript.py", line 597:
    return _SConscript(self.fs, *files, **subst_kw)
  File "C:\Users\JJS\.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Script\SConscript.py", line 285:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "C:\Users\JJS\.platformio\platforms\gd32\builder\main.py", line 128:
    target_elf = env.BuildProgram()
  File "C:\Users\JJS\.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Util.py", line 737:
    return self.method(*nargs, **kwargs)
  File "C:\Users\JJS\.platformio\penv\lib\site-packages\platformio\builder\tools\piobuild.py", line 60:
    env.ProcessProgramDeps()

platformio.ini configuration

[env]
platform = https://github.com/CommunityGD32Cores/platform-gd32.git
platform_packages = 
    framework-arduinogd32@https://github.com/CommunityGD32Cores/ArduinoCore-GD32.git
monitor_speed = 115200

[env:genericGD32F470ZK]
board = genericGD32F470ZK
framework = arduino
build_flags =
    ;include path
    -I C:/Users/JJS/.platformio/packages/framework-arduinogd32/variants/GD32F470ZK_EVAL
    -I C:/Users/JJS/.platformio/packages/framework-arduinogd32/cores/arduino/gd32
    -I C:/Users/JJS/.platformio/packages/framework-arduinogd32/system/GD32F4xx_firmware/GD32F4xx_standard_peripheral/Include
    -I C:/Users/JJS/.platformio/packages/framework-arduinogd32/system/GD32F4xx_firmware/GD32F4xx_standard_peripheral/Source
    -I C:/Users/JJS/.platformio/packages/framework-arduinogd32/system/GD32F4xx_firmware/CMSIS/GD/GD32F4xx/Include
    -I C:/Users/JJS/.platformio/packages/framework-arduinogd32/system/GD32F4xx_firmware/CMSIS/GD/GD32F4xx/Source
    -I C:/Users/JJS/.platformio/packages/framework-spl-gd32/gd32/spl/variants/gd32f4xx/inc
    
    ;define 
    -D GD32F470
    -D GD32F4xx

    ;custom linker script
    board_build.ldscript = C:/Users/JJS/.platformio/packages/framework-arduinogd32/variants/GD32F470ZK_EVAL

This should never ever be necessary.

We don’t have a GD32F470ZK_EVAL board in ArduinoCore-GD32/variants at main · CommunityGD32Cores/ArduinoCore-GD32 · GitHub. What files are you using for it? What changes to the core have you made to add GD32F4x0 support, since we don’t have that in the core at all? If you give us your changes, we can add it then in our arduino core properly.

Especially this is invalid because you have to point to an .ld file, not a folder. It’s also indented wrongly, there must be no spaces to the left.

There are related files in the link below, so please review them.
https://drive.google.com/drive/folders/1T7YsIXeO_T2P-h26XMt3QY40ZczFCx2d?usp=sharing

  • project folder: gd32-arduino-blinky (C:\Users\JJS\projects\gd32eval\gd32-pio-projects\gd32-arduino-blinky)
  • variants: GD32F470ZK_EVAL (C:\Users\JJS.platformio\packages\framework-arduinogd32\variants)
  • f/w lib: GD32F4xx_Firmware_Library (GD32F4xx_Demo_Suites_V2.6.1)

If you need any other data other than the above file, please let me know.

I modified it as below and rebuilt it.

    ;custom linker script
board_build.ldscript = C:/Users/JJS/.platformio/packages/framework-arduinogd32/variants/GD32F470ZK_EVAL/ldscript.ld

The build result shows a lot of errors as follows.

Building in release mode
Compiling .pio\build\genericGD32F470ZK\src\main.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\CDCACM.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\HardwareRTC.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\HardwareSerial.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\HardwareTimer.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\Tone.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\USBCore.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\WInterrupts.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\WMath.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\abi.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\analog.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\api\Common.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\api\IPAddress.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\api\PluggableUSB.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\api\Print.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\api\Stream.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\api\String.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\fatal.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\gd32\Source\gd32xxyy_src.c.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\gd32\gd32_def.c.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\gd32\gpio_interrupt.c.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\gd32\pinmap.c.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\gd32\pins_arduino.c.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\gd32\rtc.c.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\gd32\startup_gd32f450_470.S.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\gd32\startup_gd32xxyy.S.o
In file included from C:\Users\JJS\.platformio\packages\framework-arduinogd32\cores\arduino\gd32\Source\gd32xxyy_src.c:55:
C:\Users\JJS\.platformio\packages\framework-arduinogd32\system\GD32F4xx_firmware\GD32F4xx_standard_peripheral\Source/gd32f4xx_wwdgt.c: In function 'wwdgt_counter_update':
C:\Users\JJS\.platformio\packages\framework-arduinogd32\system\GD32F4xx_firmware\GD32F4xx_standard_peripheral\Source/gd32f4xx_wwdgt.c:71:28: warning: implicit declaration of function 'CTL_CNT'; did you mean 'CTL_CPT'? [-Wimplicit-function-declaration]
   71 |     WWDGT_CTL = (uint32_t)(CTL_CNT(counter_value));
      |                            ^~~~~~~
      |                            CTL_CPT
C:\Users\JJS\.platformio\packages\framework-arduinogd32\system\GD32F4xx_firmware\GD32F4xx_standard_peripheral\Source/gd32f4xx_wwdgt.c: In function 'wwdgt_config':
C:\Users\JJS\.platformio\packages\framework-arduinogd32\system\GD32F4xx_firmware\GD32F4xx_standard_peripheral\Source/gd32f4xx_wwdgt.c:91:28: warning: implicit declaration of function 'CFG_WIN' [-Wimplicit-function-declaration]
   91 |     WWDGT_CFG = (uint32_t)(CFG_WIN(window) | prescaler);
      |                            ^~~~~~~
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\gd32\system_gd32xxyy.c.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\gd32\systick.c.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\gd32\timer.c.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\gd32\uart.c.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\gd32\usb.c.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\hooks.c.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\itoa.c.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\main.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\new.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\pwm.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\wiring_analog.c.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\wiring_digital.c.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\wiring_pulse.cpp.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\wiring_shift.c.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\wiring_time.c.o
Archiving .pio\build\genericGD32F470ZK\libFrameworkArduino.a
Indexing .pio\build\genericGD32F470ZK\libFrameworkArduino.a
Linking .pio\build\genericGD32F470ZK\firmware.elf
c:/users/jjs/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio\build\genericGD32F470ZK\libFrameworkArduino.a(HardwareSerial.cpp.o): in function `HardwareSerial::HardwareSerial(unsigned char, unsigned char, int)':
HardwareSerial.cpp:(.text._ZN14HardwareSerialC2Ehhi+0x54): undefined reference to `digital_pins'
c:/users/jjs/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio\build\genericGD32F470ZK\libFrameworkArduino.a(uart.c.o): in function `serial_init':
uart.c:(.text.serial_init+0xc8): undefined reference to `PinMap_UART_TX'
c:/users/jjs/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: uart.c:(.text.serial_init+0xcc): undefined reference to `PinMap_UART_RX'
c:/users/jjs/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio\build\genericGD32F470ZK\libFrameworkArduino.a(wiring_digital.c.o): in function `pinMode':
wiring_digital.c:(.text.pinMode+0x4c): undefined reference to `digital_pins'
c:/users/jjs/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio\build\genericGD32F470ZK\libFrameworkArduino.a(wiring_digital.c.o): in function `digitalWrite':
wiring_digital.c:(.text.digitalWrite+0x28): undefined reference to `digital_pins'
c:/users/jjs/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio\build\genericGD32F470ZK\libFrameworkArduino.a(pinmap.c.o): in function `pin_function':
pinmap.c:(.text.pin_function+0x80): undefined reference to `GD_GPIO_AF'
c:/users/jjs/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: pinmap.c:(.text.pin_function+0x84): undefined reference to `GD_GPIO_MODE'
c:/users/jjs/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: pinmap.c:(.text.pin_function+0x88): undefined reference to `GD_GPIO_PULL_UP_DOWN'
c:/users/jjs/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: pinmap.c:(.text.pin_function+0x8c): undefined reference to `GD_GPIO_SPEED'
c:/users/jjs/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: pinmap.c:(.text.pin_function+0x90): undefined reference to `GD_GPIO_OUTPUT_MODE'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\genericGD32F470ZK\firmware.elf] Error 1

Did you set the variant attribute? Please add

board_build.variant = GD32F470ZK_EVAL

in the platformio.ini, since it doesn’t look like the files for the variant are compiled.

Otherwise add them in the json file like the reference does.

Thanks for the files, I will have a look at integrating proper support later in the day.

If if you get it to compile now, without significant core modifications, likely none of the functionality like GPIO or UART will work – and if yes, that is highly accidental.

Also, don’t forget to add startup_gd32f450_470.S to system/startup.

This also needs modifications in cores/arduino/gd32/startup_gd32xxyy.S and cores/arduino/gd32/system_gd32xxyy.c.

  1. added startup_gd32f450_470.S to C:\Users\JJS\.platformio\packages\framework-arduinogd32\system\startup\
  2. added gd32f4xx_libopt.h to C:\Users\JJS\.platformio\packages\framework-arduinogd32\cores\arduino\gd32
  3. modified gd32xxyy.S
#elif defined(GD32F450) || defined(GD32F470)
#include "startup_gd32f450_470.S"
  1. modified system_gd32xxyy.S
#elif defined(GD32F4xx)
#include "system_gd32f4xx.c"
  1. modified platformio.ini
[env]
platform = https://github.com/CommunityGD32Cores/platform-gd32.git
platform_packages = 
    framework-arduinogd32@https://github.com/CommunityGD32Cores/ArduinoCore-GD32.git
monitor_speed = 115200

[env:genericGD32F470ZK]
board = genericGD32F470ZK
framework = arduino
build_flags =
    -D GD32F470
    -D GD32F4xx

board_build.ldscript = C:/Users/JJS/.platformio/packages/framework-arduinogd32/variants/GD32F470ZK_EVAL/ldscript.ld
board_build.variant = GD32F470ZK_EVAL 

debug_tool = jlink

=> build & debug result is successful as shown below;

 *  Executing task in folder gd32-arduino-blinky: C:\Users\JJS\.platformio\penv\Scripts\platformio.exe debug 

Processing genericGD32F470ZK (board: genericGD32F470ZK; framework: arduino; platform: https://github.com/CommunityGD32Cores/platform-gd32.git)
--------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/gd32/genericGD32F470ZK.html
PLATFORM: GD GD32 (1.0.0+sha.417eefe) > GD32F470ZK (256k RAM, 3072k Flash)
HARDWARE: GD32F470ZKT6 240MHz, 256KB RAM, 3MB Flash
DEBUG: Current (jlink) External (blackmagic, cmsis-dap, jlink, sipeed-rv-debugger, stlink)
PACKAGES:
 - framework-arduinogd32 @ 4.20000.210603+sha.977fef9
 - toolchain-gccarmnoneeabi @ 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 11 compatible libraries
Scanning dependencies...
No dependencies
Building in debug mode
Compiling .pio\build\genericGD32F470ZK\FrameworkArduinoVariant\PeripheralPins.c.o
Compiling .pio\build\genericGD32F470ZK\FrameworkArduinoVariant\variant.cpp.o
Compiling .pio\build\genericGD32F470ZK\src\main.cpp.o
                       ..........
Compiling .pio\build\genericGD32F470ZK\FrameworkArduino\wiring_time.c.o
Archiving .pio\build\genericGD32F470ZK\libFrameworkArduino.a
Indexing .pio\build\genericGD32F470ZK\libFrameworkArduino.a
Linking .pio\build\genericGD32F470ZK\firmware.elf
Checking size .pio\build\genericGD32F470ZK\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.2% (used 420 bytes from 262144 bytes)
Flash: [          ]   0.2% (used 6572 bytes from 3145728 bytes)
Building .pio\build\genericGD32F470ZK\firmware.bin
=========================== [SUCCESS] Took 20.34 seconds ================================================
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task in folder gd32-arduino-blinky: C:\Users\JJS\.platformio\penv\Scripts\platformio.exe debug 

Processing genericGD32F470ZK (board: genericGD32F470ZK; framework: arduino; platform: https://github.com/CommunityGD32Cores/platform-gd32.git)
  1. jlink device selection → Cortex M4,
JLinkARM.dll V7.50a (DLL compiled Jul  8 2021 18:16:52)

Comm and line: -singlerun -if SWD -select USB -device GD32F470ZK -port 2331
-----GDB Server start settings-----
GDBInit file:                  none
GDB Server Listening port:     2331
SWO raw output listening port: 2332
Terminal I/O port:             2333
Accept remote connection:      localhost only
Generate logfile:              off
Verify download:               off
Init regs on start:            off
Silent mode:                   off
Single run mode:               on
Target connection timeout:     0 ms
------J-Link related settings------
J-Link Host interface:         USB
J-Link script:                 none
J-Link settings file:          none
------Target related settings------
Target device:                 GD32F470ZK
Target interface:              SWD
Target interface speed:        4000kHz
Target endian:                 little
Connecting to J-Link...
J-Link is connected.
Firmware: J-Link V10 compiled Jun 29 2021 16:11:46
Hardware: V10.10
S/N: 50118507
Feature(s): GDB
Checking target voltage...
Target voltage: 3.32 V
Listening on TCP/IP port 2331
Connecting to target...
undefinedC:\Users\JJS\.platformio\packages\toolchain-gccarmnoneeabi\bin\arm-none-eabi-gdb.exe: warning: Couldn't determine a path for the index cache directory.

Connected to target
Waiting for GDB connection...
Reading symbols from c:\Users\JJS\projects\gd32eval\gd32-pio-projects\gd32-arduino-blinky\.pio\build\genericGD32F470ZK\firmware.elf...
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = jlink
PlatformIO: Initializing remote target...

Connected to 127.0.0.1 Reading all registers
Read 4 bytes @ address 0x080001CA (Data = 0xE7FEE7FE)
Reading 64 bytes @ address 0x20015A40
Read 4 bytes @ address 0x0001F11C (Data = 0xFFFFFFFF)
Read 2 bytes @ address 0x0001F11C (Data = 0xFFFF)

0x080001ca in HardwareSerial::write (this=<optimized out>, c=<optimized out>) at C:\Users\JJS\.platformio\packages\framework-arduinogd32\cores\arduino\HardwareSerial.cpp:250
250 serial_transmit(&_serial, &_tx_buffer.buffer[_tx_buffer.tail], 1);
Received monitor command: clrbp
Received monitor command: speed auto
Select auto target interface speed
Select auto target interface speed (2000 kHz)
(2000 kHz)
Received monitor command: reset
Resetting target
Resetting target
Received monitor command: halt
Halting target CPU...

.
..Target halted (PC = 0x080001C0)
Loading section .text, size 0x1574 lma 0x8000000
Downloading 5492 bytes @ address 0x08000000
Loading section .rodata, size 0x3d0 lma 0x8001574
Downloading 976 bytes @ address 0x08001574
D
Loading section .init_array, size 0xc lma 0x8001944
ownloading 12 bytes @ address 0x08001944
D
Loading section .fini_array, size 0x4 lma 0x8001950
ownloading 4 bytes @ address 0x08001950

Writing register (PC = 0x 800056c)
Transfer rate: 134 KB/sec, 1317 bytes/write.
Read 4 bytes @ address 0x0800056C (Data = 0x2304EA43)
Read 2 bytes @ address 0x0800056C (Data = 0xEA43)
Read 2 bytes @ address 0x0800056E (Data = 0x2304)
Reading 64 bytes @ address 0x08000B80
Read 2 bytes @ address 0x08000B98 (Data = 0xF000)

Temporary breakpoint 1 at 0x8000b98: file C:\Users\JJS\.platformio\packages\framework-arduinogd32\cores\arduino\main.cpp, line 59.
PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = tbreak main`
PlatformIO: More configuration options -> https://bit.ly/pio-debug
Setting breakpoint @ address 0x08000B9
8, Size = 2, BPHandle = 0x0001
Starting target CPU...

however it doesn’t work
gd32f470z_eval debug error

Can you use a more simple

#include <Arduino.h>

#ifdef LED_BUILTIN
#define LED LED_BUILTIN
#else 
#define LED PC13
#endif 

void setup(){
    pinMode(LED, OUTPUT);
}

void loop(){
    digitalWrite(LED, LOW);
    delay(500);
    digitalWrite(LED, HIGH);
    delay(500);
}

code as src/main.cpp and also add

debug_init_break = break Reset_Handler

in the platformio.ini so that the debugger stops at the very first instruction of the startup script? When you then use “Step Into” to step over the assembly code, does it get stuck anywhere or does it reach the main() function and setup() etc?

Thanks for your reply.

I used src/main.cpp (LED blinks).
Added debug_init_break in platformio.ini,

debug_tool = jlink
debug_init_break = break Reset_Handler

When debugging starts it enters the Reset_Handler.

continue with “Step Into”

stuck in the system_clock_200ms_25m_hxtal()

fail to debug

Woah, it is never supposed to go beyond the main() function… that’s very weird.

What crystal oscillator do you have on your board? The clock source selection is static in the system_gd32f4xx.c with the macros on top. If the HSE (HXTAL at 25MHz) doesn’t work, try the internal RC oscillator, that is, comment __SYSTEM_CLOCK_200M_PLL_25M_HXTAL and uncomment __SYSTEM_CLOCK_200M_PLL_IRC16M.

The external crystal is 25MHz.
25MHz
But I tried setting it up as an internal RC oscillator and running it.
After repeatedly executing CopyDataInit: and LoopCopyDataInit: it goes to SystemInit, but if step over here, it fails.

You can just add a breakpoint at the bl SystemInit line and press play to skip the boring copy part.

How does it fail? Does it get stuck inside a function in there even if you set the RC oscillator up? In which function does it hang?

  1. set BOOT from User to System as shown below,

  2. jlink selection device → gigadevice/GD32F450ZK (there is not GD32F470ZK)

  3. finally entering the main loop
    gd32_arduino_blink_debug_main_loop

  4. however the LED doesn’t turn ON, and

  5. stuck in delay()
    the return value of getCurrentMillis() is zero
    gd32_arduino_blink_debug_delay

Seems like the GPIO code is missing some #if defined(GD32F4xx) code (or the variant doesn’t declare the pins correctly) and the SysTick timer isn’t set up properly. As said, we don’t yet have tested F4xx support in the code.

Can you upload the current state of the Arduino framework and your modified board files?

shared link
https://drive.google.com/drive/folders/1T7YsIXeO_T2P-h26XMt3QY40ZczFCx2d?usp=sharing

Great, I’ll have time in the evening to look at this.

The GPIO pin number specified in variant.h and the GPIO index in digital_pins[] of variant.cpp are incorrect. When I made the pin number and GPIO index match, the LED turned on. (Updated variant.h, variant.cpp)
I’m still not sure how to modify the SysTick settings.

Yeah my bad, looks like I won’t be free until the weekend to look at this in person.

If millis() are still stuck at 0, take a look at ArduinoCore-GD32/wiring_time.c at main · CommunityGD32Cores/ArduinoCore-GD32 · GitHub. It accesses the SysTick->VAL etc. values to get the timing information. Either the logic in that code is wrong, or the systick isn’t ticking at all. The Systick is supposed to be initialized in ArduinoCore-GD32/systick.c at main · CommunityGD32Cores/ArduinoCore-GD32 · GitHub by calling systick_config(), which is supposed to be called by

which is supposed to be called by

and this constructor call is one of the calls that the __libc_init_array() function will then execute, from the startup script.

Can you set

debug_init_break = break premain

to see if it reaches that “constructor” call at all and subsequently systick_config()?