Skip to content

Commit

Permalink
First proof of concept with gd32vw55x
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgerhardt committed Jan 3, 2025
1 parent 35203aa commit 9c29563
Show file tree
Hide file tree
Showing 20 changed files with 38,921 additions and 31 deletions.
1 change: 1 addition & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
- "examples/gd32-arduino-blinky"
- "examples/gd32-mbedos-baremetal-blinky"
- "examples/gd32-spl-blinky"
- "examples/gd32-vw55x-blinky"
- "examples/gd32-w51x-wifi-scan"
- "examples/gd32-e503c_start-spl-blinky"
- "examples/zephyr-blink"
Expand Down
50 changes: 50 additions & 0 deletions boards/gd32vw553k_start.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"build": {
"core": "n307fd",
"f_cpu": "160000000L",
"cpu": "rv32imac_zba_zbb_zbc_zbs_xxldspn1x",
"hwids": [
[
"0x0403",
"0x6010"
]
],
"arch_ext": "_zba_zbb_zbc_zbs_xxldspn1x",
"soc": "gd32vw55x",
"mcu": "gd32vw553kmq6",
"download": "flashxip",
"ldscript": "",
"download_modes": [
"flashxip",
"sram"
],
"spl_series": "GD32VW55x",
"series": "GD32VW55x"
},
"debug": {
"jlink_device": "GD32VW553HM",
"svd_path": "GD32VW55X.svd",
"openocd_target": "gd32vw55x.cfg",
"onboard_tools": [
"gd-link"
]
},
"frameworks": [
"spl"
],
"name": "GD32VW553K-START Board",
"upload": {
"maximum_ram_size": 294912,
"maximum_size": 2097152,
"flash_start": "0x08000000",
"sram_start": "0x20000000",
"protocol": "gdlinkcli",
"protocols": [
"cmsis-dap",
"jlink",
"gdlinkcli"
]
},
"url": "https://www.gigadevice.com/product/mcu/risc-v",
"vendor": "GigaDevice"
}
52 changes: 40 additions & 12 deletions builder/frameworks/_bare.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#

from SCons.Script import DefaultEnvironment
from os.path import join

env = DefaultEnvironment()

Expand All @@ -27,8 +28,7 @@
"-Os", # optimize for size
"-ffunction-sections", # place each function in its own section
"-fdata-sections",
"-Wall",
"-mthumb"
"-Wall"
],

CXXFLAGS=[
Expand All @@ -44,22 +44,50 @@

LINKFLAGS=[
"-Os",
"-Wl,--gc-sections,--relax",
"-mthumb"
'-Wl,-Map="%s"' % join("${BUILD_DIR}", "${PROGNAME}.map"),
"-Wl,--gc-sections,--relax"
],

LIBS=["c", "gcc", "m", "stdc++"]
)

if "BOARD" in env:
env.Append(
CCFLAGS=[
"-mcpu=%s" % env.BoardConfig().get("build.cpu")
],
LINKFLAGS=[
"-mcpu=%s" % env.BoardConfig().get("build.cpu")
]
)
board = env.BoardConfig()
is_riscv = board.get("build.mcu", "").startswith("gd32vw")

if is_riscv:
env.Append(
CCFLAGS=[
"-march=%s" % board.get("build.cpu"),
"-mabi=ilp32"
],
LINKFLAGS=[
"-march=%s" % board.get("build.cpu"),
"-mabi=ilp32",
"-nostartfiles",
"-Wl,--no-warn-rwx-segments"
]
)
else: #arm
env.Append(
CCFLAGS=[
"-mcpu=%s" % board.get("build.cpu"),
"-mthumb"
],
LINKFLAGS=[
"-mcpu=%s" % board.get("build.cpu"),
"-mthumb"
]
)

# copy CCFLAGS to ASFLAGS (-x assembler-with-cpp mode)
env.Append(ASFLAGS=env.get("CCFLAGS", [])[:])

# create .lst file
env.AddPostAction(
"$BUILD_DIR/${PROGNAME}.elf",
env.VerboseAction(" ".join([
"$OBJDUMP", "-drwC",
"$BUILD_DIR/${PROGNAME}.elf", ">", "$BUILD_DIR/${PROGNAME}.lst"
]), "Building .pio/build/$PIOENV/${PROGNAME}.lst")
)
18 changes: 8 additions & 10 deletions builder/frameworks/spl.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

env.SConscript("_bare.py")

is_riscv = board.get("build.mcu", "").startswith("gd32vw")

def get_flag_value(flag_name:str, default_val:bool):
flag_val = board.get("build.%s" % flag_name, default_val)
flag_val = str(flag_val).lower() in ("1", "yes", "true")
Expand Down Expand Up @@ -143,10 +145,14 @@ def get_startup_filename(board):
startup_file = f"startup_{spl_series.lower()}.S"
return startup_file

if is_riscv:
core_path = join(FRAMEWORK_DIR, spl_chip_type, "cmsis", "cores", "gd32_riscv", "drivers")
else: #arm
core_path = join(FRAMEWORK_DIR, spl_chip_type, "cmsis", "cores", spl_chip_type)

env.Append(
CPPPATH=[
join(FRAMEWORK_DIR, spl_chip_type,
"cmsis", "cores", spl_chip_type),
core_path,
join(FRAMEWORK_DIR, spl_chip_type,
"cmsis", "startup_files"),
join(FRAMEWORK_DIR, spl_chip_type, "cmsis",
Expand Down Expand Up @@ -178,14 +184,6 @@ def get_startup_filename(board):
extra_flags = board.get("build.extra_flags", "")
src_filter_patterns = ["+<*>"]
# could come in handy later to exclude certain files, not needed / trigger now
if "STM32F40_41xxx" in extra_flags:
src_filter_patterns += ["-<stm32f4xx_fmc.c>"]
if "STM32F427_437xx" in extra_flags:
src_filter_patterns += ["-<stm32f4xx_fsmc.c>"]
elif "STM32F303xC" in extra_flags:
src_filter_patterns += ["-<stm32f30x_hrtim.c>"]
elif "STM32L1XX_MD" in extra_flags:
src_filter_patterns += ["-<stm32l1xx_flash_ramfunc.c>"]

libs = []

Expand Down
20 changes: 12 additions & 8 deletions builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,19 @@ def _update_max_upload_size(env):
platform = env.PioPlatform()
board = env.BoardConfig()

is_riscv = board.get("build.mcu", "").startswith("gd32vw")
toolchain_triple = "arm-none-eabi" if not is_riscv else "riscv64-unknown-elf"

env.Replace(
AR="arm-none-eabi-gcc-ar",
AS="arm-none-eabi-as",
CC="arm-none-eabi-gcc",
CXX="arm-none-eabi-g++",
GDB="arm-none-eabi-gdb",
OBJCOPY="arm-none-eabi-objcopy",
RANLIB="arm-none-eabi-gcc-ranlib",
SIZETOOL="arm-none-eabi-size",
AR="%s-gcc-ar" % toolchain_triple,
AS="%s-as" % toolchain_triple,
CC="%s-gcc" % toolchain_triple,
CXX="%s-g++" % toolchain_triple,
GDB="%s-gdb" % toolchain_triple,
OBJCOPY="%s-objcopy" % toolchain_triple,
OBJDUMP="%s-objdump" % toolchain_triple,
RANLIB="%s-gcc-ranlib" % toolchain_triple,
SIZETOOL="%s-size" % toolchain_triple,

ARFLAGS=["rc"],

Expand Down
2 changes: 2 additions & 0 deletions examples/gd32-vw55x-blinky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.pio
.vscode
39 changes: 39 additions & 0 deletions examples/gd32-vw55x-blinky/include/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

This directory is intended for project header files.

A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.

```src/main.c

#include "header.h"

int main (void)
{
...
}
```

Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.

In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.

Read more about using header files in official GCC documentation:

* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes

https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
46 changes: 46 additions & 0 deletions examples/gd32-vw55x-blinky/lib/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.

The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").

For example, see a structure of the following two libraries `Foo` and `Bar`:

|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c

and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>

int main (void)
{
...
}

```

PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.

More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
14 changes: 14 additions & 0 deletions examples/gd32-vw55x-blinky/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:gd32vw553k_start]
platform = gd32
board = gd32vw553k_start
framework = spl
Loading

0 comments on commit 9c29563

Please sign in to comment.