Custom board build error (GD32F470_EVAL)

It has been confirmed that the Systick_Config() is being called and the value is also being entered in the systick-related register.

  1. __libc_init_array
    debug_break_bl_libc_init_array

  2. call init()

  3. call systick_config()
    debug_break_systick_config

  4. systick_config()
    debug_systick_systick_config

  • values of systick registers
    debug_systick_reg_value
  • SysTick->CTRL = 7;
    – clock source = 1: Processor Clock (AHB)
    – TICKINT = 1: Counting down to zero to asserts the SysTick exception request
    – ENABLE = 1: Counter enabled
  1. the tick value is still zero.

I tried to run the gd32-pio-projects\gd32-spl-blinky by setting the framework to spl.
platformio.ini settings are as follows.

[env:gd32f470z_eval]
board = genericGD32F470ZK
framework = spl
debug_tool = jlink

Like when set to arduino, LED turns on but delay dose not work.
debug_spl_gd32_blinky_delay

This it extremely strange. Is the interrupt called for the SysTick that actually increases the tick variable?

We have

and since this function should be at the correct position in the interrupt vector…

(which was auto-converted from this).

This function should be called if SysTick interrupts are activated in the peripheral. Of course the linker script also has to place the interrupt vector at the start of flash, but this should be correct.

Can you set debug_init_break = break SysTick_Handler in the platformio.ini and let it run? Does it ever hit the SysTick handler?

I solved it. The damn SysTick_Handler is called!
image

The cause of problem is that the VTOR(Vector Table Offset Register) is not initialized in the SystemInit().
I added definition and the code in the system_gd324xx.c

/* Vector Table base offset */
#define VECT_TAB_OFFSET  0x00                      /* This value must be a multiple of 0x200. */

void SystemInit(void) 
{
  ...
    system_clock_config();

#ifdef VECT_TAB_SRAM
    nvic_vector_table_set(NVIC_VECTTAB_RAM, VECT_TAB_OFFSET);
#else
    nvic_vector_table_set(NVIC_VECTTAB_FLASH, VECT_TAB_OFFSET);
#endif
  ...
}
1 Like

Oh my god, that is a very crucial thing. How could Gigadevice overlook this. Thanks, for the integration in the Arduino core we will have to fix this too.

I tried to build and run it with arduino-core, but SysTick_Handler still does not work.

When you start the debugger and pause execution, you should get a “perpiherals” view based on the SVD file referenced in the board file. Can you confirm that the NVIC VECTTAB register has the right value there? What’s the value of the SysTick registers?

You did the same modification in C:\Users\<user>\.platformio\packages\framework-arduinogd32\system\system/GD32F4xx_firmware/CMSIS/GD/GD32F4xx/Source/system_gd32f4xx.c? Since the framework-spl-gd32 package is not used when compiling the Arduino core.

I did the same modification in system_gd32f4xx.c of arduino package.

the related register value is as follows;
image

  • STK_CTRL: 7 (CLKSOURCE = TICKINT = ENABLE = 1)
  • STK_VAL: it does work (decreasing)
  • STK_LOAD, CALIB: set properly
  • SHPR1 = SHPR2 = SHPR3 = 0 (System Handler Priority Register)
  • VTOR register(@0xE000ED08): 134217728 (=0x08000000)

Can you read out the registers again but with your now-working SPL example? Are there any changes in the registers between them?

register with SPL

the difference is the value of STK_CTRL.
STK_CTRL: 65543 (=0x10007)

register with Arduino
the same value may come out.


it is the same.

Could it be that the interrupt for the systick is disabled somewhere else, e.g. in the Cortex M4’s NVIC?

Or maybe the SysTick->VAL never reaches 0 after all.

Is the current clock code setup for 200MHz from 25MHz crystal + PLL?

240MHz


I set the system clock to internal and also set it to 120MHz, but it doesn’t work.

https://raw.githubusercontent.com/CommunityGD32Cores/gigadevice-firmware-and-docs/main/GD32F4xx/GD32F4xx_User_Manual_Rev2.5.pdf page 158 interestingly says something about fixed clock frequency and using 200MHz.

I hoped, but it still doesn’t work.

Is there a way to use the arduino library in the SPL framework?

Arduino completely builds on the SPL library, I don’t know how it still doesn’t work if you have fixed in the SPL files and copied those fixed files into the Arduino framework… At least the interrupt should fire.

Can you upload the current state of the framework-arduinogd32 folder?

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

I copied only 3 files(system_gd32f4xx.c, system_gd32f4xx.h, gd32f4xx.h) and pasted them into the Arduino package.

  1. The version of core_cm3.h is different. The version used for spl fremework was higher, so I copied and built it. A lot of compilation errors occur. Is it correct to copy this?
    core_cm4 (v3.30, arduino core) vs. core_cm4 (v5.1.2, spl core)

  2. The file structure is different. Which files should I copy?

In the SPL framework I’ve upgraded the CMSIS core files – if those work (because your arduino example works), you should copy all headers from right to left.

I replaced all the files in the path below with spl framework files, but it still doesn’t work.

C:\Users\JJS.platformio\packages\framework-arduinogd32\system\GD32F4xx_firmware\CMSIS
C:\Users\JJS.platformio\packages\framework-arduinogd32\system\GD32F4xx_firmware\CMSIS\GD\GD32F4xx\Source
C:\Users\JJS.platformio\packages\framework-arduinogd32\system\GD32F4xx_firmware\CMSIS\GD\GD32F4xx\Include

C:\Users\JJS.platformio\packages\framework-arduinogd32\system\GD32F4xx_firmware\GD32F4xx_standard_peripheral\Source
C:\Users\JJS.platformio\packages\framework-arduinogd32\system\GD32F4xx_firmware\GD32F4xx_standard_peripheral\Include