Skip to content

Commit

Permalink
Enable Zephyr support for GD32A503 example board
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgerhardt committed Dec 23, 2024
1 parent 78fe50d commit 5f9127d
Show file tree
Hide file tree
Showing 17 changed files with 308 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
- "examples/gd32-spl-blinky"
- "examples/gd32-w51x-wifi-scan"
- "examples/gd32-e503c_start-spl-blinky"
- "examples/zephyr-blinky"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand Down
10 changes: 7 additions & 3 deletions boards/genericGD32A503RD.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"f_cpu": "100000000L",
"mcu": "gd32a503rdt3",
"spl_series": "GD32A50X",
"series": "GD32A503"
"series": "GD32A503",
"zephyr": {
"variant": "gd32a503v_eval"
}
},
"debug": {
"jlink_device": "GD32A503RD",
Expand All @@ -21,14 +24,15 @@
]
},
"frameworks": [
"spl"
"spl",
"zephyr"
],
"name": "GD32A503RD (48k RAM, 384k Flash)",
"upload": {
"disable_flushing": false,
"maximum_ram_size": 49152,
"maximum_size": 393216,
"protocol": "stlink",
"protocol": "gdlinkcli",
"protocols": [
"jlink",
"cmsis-dap",
Expand Down
30 changes: 30 additions & 0 deletions builder/frameworks/zephyr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2019-present PlatformIO <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
The Zephyr Project is a scalable real-time operating system (RTOS) supporting multiple
hardware architectures, optimized for resource constrained devices, and built with
safety and security in mind.
https://github.com/zephyrproject-rtos/zephyr
"""

from os.path import join

from SCons.Script import Import, SConscript

Import("env")

SConscript(
join(env.PioPlatform().get_package_dir("framework-zephyr"), "scripts",
"platformio", "platformio-build.py"), exports="env")
11 changes: 11 additions & 0 deletions builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ def _update_max_upload_size(env):
join("frameworks", "wifi-sdk-pre.py"),
exports={"env": env}
)
if "zephyr" in pioframework:
env.SConscript(
join(platform.get_package_dir(
"framework-zephyr"), "scripts", "platformio", "platformio-build-pre.py"),
exports={"env": env}
)

target_elf = None
if "nobuild" in COMMAND_LINE_TARGETS:
Expand All @@ -197,6 +203,11 @@ def _update_max_upload_size(env):
else:
target_elf = env.BuildProgram()
target_firm = env.ElfToBin(join("$BUILD_DIR", "${PROGNAME}"), target_elf)

if "zephyr" in pioframework and "mcuboot-image" in COMMAND_LINE_TARGETS:
target_firm = env.MCUbootImage(
join("$BUILD_DIR", "${PROGNAME}.mcuboot.bin"), target_firm)

env.Depends(target_firm, "checkprogsize")

# replace target_firm variable with *combined* .bin image
Expand Down
6 changes: 3 additions & 3 deletions examples/gd32-spl-blinky/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
#define LEDPIN GPIO_PIN_1
#define LED_CLOCK RCU_GPIOA
#else
#define LEDPORT GPIOC
#define LEDPIN GPIO_PIN_0
#define LED_CLOCK RCU_GPIOC
#define LEDPORT GPIOA
#define LEDPIN GPIO_PIN_5
#define LED_CLOCK RCU_GPIOA
#endif

void systick_config(void);
Expand Down
1 change: 1 addition & 0 deletions examples/zephyr-blink/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.pio
38 changes: 38 additions & 0 deletions examples/zephyr-blink/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.. Copyright 2019-present PlatformIO <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

How to build PlatformIO based project
=====================================

1. [Install PlatformIO Core](https://docs.platformio.org/page/core.html)
2. Download [development platform with examples](https://github.com/platformio/platform-ststm32/archive/develop.zip)
3. Extract ZIP archive
4. Run these commands:

```shell
# Change directory to example
$ cd platform-ststm32/examples/zephyr-blink

# Build project
$ pio run

# Upload firmware
$ pio run --target upload

# Build specific environment
$ pio run -e blackpill_f103c8

# Upload firmware for the specific environment
$ pio run -e blackpill_f103c8 --target upload

# Clean build files
$ pio run --target clean
```
39 changes: 39 additions & 0 deletions examples/zephyr-blink/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/zephyr-blink/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
13 changes: 13 additions & 0 deletions examples/zephyr-blink/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter, extra scripting
; Upload options: custom port, speed and extra flags
; Library options: dependencies, extra library storages
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:genericGD32A503RD]
platform = gd32
framework = zephyr
board = genericGD32A503RD
46 changes: 46 additions & 0 deletions examples/zephyr-blink/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>

/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS 300

/* The devicetree node identifier for the "led3" alias, defined in zephyr/app.overlay */
#define LED_NODE DT_ALIAS(led3)

/*
* A build error on this line means your board is unsupported.
* See the sample documentation for information on how to fix this.
*/
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED_NODE, gpios);

void main(void)
{
int ret;

if (!gpio_is_ready_dt(&led))
{
return;
}

ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
if (ret < 0)
{
return;
}

while (1)
{
ret = gpio_pin_toggle_dt(&led);
if (ret < 0)
{
return;
}
k_msleep(SLEEP_TIME_MS);
}
}
11 changes: 11 additions & 0 deletions examples/zephyr-blink/test/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

This directory is intended for PIO Unit Testing and project tests.

Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.

More information about PIO Unit Testing:
- https://docs.platformio.org/page/plus/unit-testing.html
7 changes: 7 additions & 0 deletions examples/zephyr-blink/zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(blinky)

target_sources(app PRIVATE ../src/main.c)
12 changes: 12 additions & 0 deletions examples/zephyr-blink/zephyr/app.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/ {
aliases {
led3 = &myled0;
};
leds {
compatible = "gpio-leds";
myled0: led_0 {
gpios = <&gpioa 7 GPIO_ACTIVE_LOW>;
label = "LED3";
};
};
};
1 change: 1 addition & 0 deletions examples/zephyr-blink/zephyr/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_GPIO=y
33 changes: 33 additions & 0 deletions platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
"description": "GD32W51x WIFI SDK",
"homepage": "http://www.gd32mcu.com/en/download/0?kw=GD32W5",
"title": "WiFi SDK"
},
"zephyr": {
"package": "framework-zephyr",
"script": "builder/frameworks/zephyr.py",
"description": "The Zephyr Project is a scalable real-time operating system (RTOS) supporting multiple hardware architectures, optimized for resource constrained devices, and built with safety and security in mind",
"homepage": "https://www.zephyrproject.org",
"title": "Zephyr RTOS"
}
},
"packages": {
Expand Down Expand Up @@ -87,6 +94,12 @@
"owner": "maxgerhardt",
"version": "https://github.com/CommunityGD32Cores/gd32-pio-wifi-sdk.git"
},
"framework-zephyr": {
"type": "framework",
"optional": true,
"owner": "platformio",
"version": "https://github.com/CommunityGD32Cores/zephyr.git"
},
"tool-sreccat": {
"owner": "platformio",
"version": "~1.164.0",
Expand Down Expand Up @@ -121,6 +134,26 @@
"optional": true,
"owner": "platformio",
"version": "~1.9.190708"
},
"tool-cmake": {
"optional": true,
"owner": "platformio",
"version": "~3.21.0"
},
"tool-dtc": {
"optional": true,
"owner": "platformio",
"version": "~1.4.7"
},
"tool-ninja": {
"optional": true,
"owner": "platformio",
"version": "^1.7.0"
},
"tool-gperf": {
"optional": true,
"owner": "platformio",
"version": "^3.0.0"
}
}
}
Loading

0 comments on commit 5f9127d

Please sign in to comment.