The GD32E230

I came across some GD32E230K8T6 microcontrollers on Aliexpress. They contain an ARM Cortex M23 that can run up to 72MHz, 64kB of Flash and 8kB of RAM. They were on sale for 72c so I had to try them out. The ones I bought were the in an LQFP32 package which can be soldered fairly easily onto a breakout board as shown below.

Also shown in the image is a CMSIS adapter (from Aliexpress too!). To connect to the board I had to modify the openocd cmsis-dap.cfg file as follows:

adapter driver cmsis-dap
cmsis_dap_vid_pid 0xc251 0xf001
cmsis_dap_backend hid

Openocd can then be started as follows:

openocd -f cmsis-dap.cfg -f /usr/share/openocd/scripts/target/gd32e23x.cfg

Gigadevices provide a firmware library over here https://www.gd32mcu.com/en/download/7?kw=GD32E2

This covers all the basics (GPIO,ADC,SPI etc) however the directory layout didn’t suit my usual way of doing things so I restructured it a little so that programs could be built from the command line using a simple script.

Blinky


#include <stdint.h>
#include "system_gd32e23x.h"
#include "gd32e23x_gpio.h"
#include "gd32e23x_rcu.h"
void delay(uint32_t dly)
{
    while(dly--);
}
int main()
{
    SystemInit();  // system clock is set to 72MHz
    
    rcu_periph_clock_enable(RCU_GPIOA);
    gpio_deinit(GPIOA);
    gpio_mode_set(GPIOA,GPIO_MODE_OUTPUT,GPIO_PUPD_NONE,GPIO_PIN_0);

    while(1)
    {
        gpio_bit_set(GPIOA,GPIO_PIN_0);
        delay(1000000);
        gpio_bit_reset(GPIOA,GPIO_PIN_0);
        delay(1000000);
    }
}

This program uses some functions from the driver library provided by Gigadevices. For simplicity I placed all of the header and c-source files for this library in a higher level directory called include. The program can be built using the following command:

arm-none-eabi-gcc -mthumb -g3 -mcpu=cortex-m23 init.c main.c ../include/*.c -I ../include  -T linker_script.ld -o main.elf -nostartfiles 

This is not at all optimal as it compiles all the driver code every time and also makes the final executable bigger than it needs to be. However it is useful for getting started and the executable file size can be trimmed later if needs be.

The blinky program has two source files : main.c (above) and init.c. The second of these contains all of the interrupt vectors and global/static data initilization routines. This, along with another couple of examples can be found over on my github page.

Leave a comment