Skip to content

Commit a489e01

Browse files
authored
Merge branch 'arduino' into fix_giga_config
2 parents 672192b + fe9e040 commit a489e01

File tree

17 files changed

+254
-111
lines changed

17 files changed

+254
-111
lines changed

.github/workflows/package_core.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,24 @@ jobs:
1010
name: Build and package core
1111
runs-on: ubuntu-latest
1212
env:
13-
ZEPHYR_SDK_INSTALL_DIR: /opt/zephyr-sdk-0.16.8
1413
CCACHE_IGNOREOPTIONS: -specs=*
1514
outputs:
1615
CORE_TAG: ${{ env.CORE_TAG }}
1716
CORE_ARTIFACT: ${{ env.CORE_ARTIFACT }}
1817
BOARD_VARIANTS: ${{ env.BOARD_VARIANTS }}
1918
steps:
20-
- name: Install toolchain
19+
- name: Install OS dependencies
2120
working-directory: /opt
2221
run: |
2322
sudo apt-get update
2423
sudo apt-get install -y --no-install-recommends git cmake wget python3-pip ninja-build ccache
25-
wget -nv https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.8/zephyr-sdk-0.16.8_linux-x86_64_minimal.tar.xz
26-
tar xf zephyr-sdk-0.16.8_linux-x86_64_minimal.tar.xz && cd zephyr-sdk-0.16.8 && ./setup.sh -t arm-zephyr-eabi -c
2724
2825
- uses: actions/checkout@v4
2926
with:
3027
fetch-depth: 0
3128
persist-credentials: false
3229

33-
- name: Initialize
30+
- name: Initialize Zephyr environment
3431
run: |
3532
./extra/bootstrap.sh -o=--filter=tree:0
3633
echo "CORE_TAG=$(git describe --always)" >> "$GITHUB_ENV"

README.md

Lines changed: 78 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,40 @@ Unlike traditional Arduino implementations, where the final output is a standalo
8080

8181
The `loader` is responsible for managing the interaction between your sketches and the underlying Zephyr system. After the initial bootloader installation, the `loader` takes over the sketch loading process automatically.
8282

83-
To ensure flexibility, the `loader` project is designed to be generic. Any necessary modifications for specific boards should be made in the corresponding `DTS overlay` or a special `fixup` file, using appropriate guards to maintain stability.
83+
To ensure flexibility, the `loader` project is designed to be generic. Any necessary modifications for specific boards should be made in the corresponding "DTS overlay" or a special "fixup" file, using appropriate guards to maintain compatibility.
8484

85-
The behavior of the `loader` can be adjusted through the `Mode` menu:
85+
The behavior of the `loader` can be adjusted through the `Mode` menu of the IDE:
8686
- `Standard`: The sketch is loaded automatically.
8787
- `Debug`: The user must type `sketch` in Zephyr's shell, which is accessible via the default Serial.
8888

8989
The most important components of this project are:
9090

9191
* [Zephyr based loader](/loader)
9292
* [LLEXT](https://docs.zephyrproject.org/latest/services/llext/index.html)
93-
* [Actual core](/cores/arduino) with [variants](/variants) and the usual `{platform,boards}.txt`
93+
* [Actual core](/cores/arduino) with [variants](/variants) and the usual [platform](/platform.txt) and [boards](/boards) files
9494
* [ArduinoCore-API](https://github.com/arduino/ArduinoCore-API)
95-
* [post_build_tool](/extra/post_build_tool)
95+
* [zephyr-sketch-tool](/extra/zephyr-sketch-tool)
9696

97-
## 🛠️ Setup the environment
97+
## 🏃 Shortcut: using the Core in Arduino IDE/CLI without installing Zephyr
9898

99-
In this section, we’ll guide you through setting up your environment to work with the core.
99+
> [!TIP]
100+
>
101+
> If you are only interested in developing features in the [core](/cores/arduino)
102+
> or [libraries](/libraries), and do not want to set up a full Zephyr build
103+
> environment, you can use the [`sync-zephyr-artifacts`](/extra/sync-zephyr-artifacts)
104+
> utility to download a pre-built version of the files needed to compile
105+
> sketches and flash the loader.
106+
>
107+
> To do so, after cloning this repo, compile the `sync-zephyr-artifacts`
108+
> utility via `go build` and run it as `sync-zephyr-artifacts .` to retrieve
109+
> the precompiled files for the current revision of the core.
110+
>
111+
> Next, follow the instructions in [Using the Core in Arduino IDE/CLI](#using-the-core-in-arduino-idecli).
112+
> Remember to [update the loader on your board](#flash-the-loader) as well.
113+
114+
## 🛠️ Setup a Zephyr build environment
115+
116+
In this section, we’ll guide you through setting up your environment to work on and update the Zephyr core.
100117

101118
Shell scripts are available to simplify the installation process (Windows is not supported at the moment 😔).
102119

@@ -118,57 +135,85 @@ sudo apt install python3-pip python3-setuptools python3-venv build-essential git
118135
cd ArduinoCore-zephyr
119136
./extra/bootstrap.sh
120137
```
121-
### Install the Zephyr SDK
122-
Download and install the Zephyr SDK for your OS from [here](https://github.com/zephyrproject-rtos/sdk-ng/releases/tag/v0.16.8).
123138

124-
> [!NOTE]
125-
> This core is validated for version v0.16.8. Compatibility with later versions has not been tested yet.
139+
This will take care of installing `west`, the Zephyr build tool. It will then
140+
download all packages required for a Zephyr build in addition to the toolchains
141+
in the Zephyr SDK.
142+
143+
> [!NOTE]
144+
> This core is validated with version v0.17.0 of the SDK. Compatibility with later versions has not been tested yet.
145+
146+
## 🛠️ Regenerate the compiled core files
126147

127148
### Build the Loader
128149

129-
To build the loader, run the following commands:
150+
The loader is compiled for each board by running the `./extra/build.sh` script.
151+
The target can be specified either with the Arduino board name (as defined in
152+
boards.txt), or with the Zephyr board name and any additional arguments that
153+
may be required by the Zephyr build system.
154+
155+
For example, to build for the Arduino Portenta H7, you can use either the
156+
Arduino name:
130157
```bash
131-
export ZEPHYR_SDK_INSTALL_DIR=$folder_where_you_installed_the_sdk
132-
./extra/build.sh $zephyr_board_name $arduino_variant_board_name
158+
./extra/build.sh portentah7
133159
```
134-
Replace `$zephyr_board_name` and `$arduino_variant_board_name` with the appropriate names for your board.
135160

136-
Example for Arduino Portenta H7:
161+
or the Zephyr board target:
162+
137163
```bash
138-
./extra/build.sh arduino_portenta_h7//m7 arduino_portenta_h7
164+
./extra/build.sh arduino_portenta_h7//m7
139165
```
140166

141-
The firmwares will be copied to [firmwares](/firmwares) folder.
167+
The firmwares will be copied to the [firmware](/firmware) folder, and the
168+
associated variant will be updated.
142169

143170
### Flash the Loader
144171

145172
If the board is fully supported by Zephyr, you can flash the firmware directly onto the board using the following command:
146173
```bash
147174
west flash
148175
```
176+
This can also be performed via the "Burn bootloader" action in the IDE if the core is properly installed, as detailed below.
149177

150178
### Using the Core in Arduino IDE/CLI
151179

152-
After running the `bootstrap` script, you can symlink the core to `$sketchbook/hardware/arduino-git/zephyr`. Once linked, it will appear in the IDE/CLI, and the board's Fully Qualified Board Name (FQBN) will be formatted as `arduino-git:zephyr:name_from_boards_txt`.
180+
After running the `bootstrap.sh` script, you can symlink the core to `$sketchbook/hardware/arduino-git/zephyr`. Once linked, it will appear in the IDE/CLI, and the board's Fully Qualified Board Name (FQBN) will be formatted as `arduino-git:zephyr:name_from_boards_txt`.
153181

154-
### Using the Core in Arduino IDE/CLI (without installing Zephyr toolchain)
182+
## 🚀 Adding a new target
155183

156-
To help core developers (who might not be interested at all in setting up a full Zephyr build system) we are providing [sync-zephyr-artifacts](/extra/sync-zephyr-artifacts) utility. After compiling it via `go build`, run as `sync-zephyr-artifacts .` to retrieve the files needed to compile sketches and flash the loader.
184+
> [!TIP]
185+
>
186+
> While Zephyr supports a lot of different hardware targets, only the few
187+
> currently used by the Arduino core are installed by default. To add the
188+
> support for every Zephyr target to your workspace, run the following
189+
> commands:
190+
>
191+
> ```bash
192+
> . venv/bin/activate
193+
> west config -d manifest.project-filter
194+
> west sdk install --version 0.17.0
195+
> west update
196+
> ```
157197
158-
## 🚀 Adding a new target
198+
To add a new board that is already supported by mainline Zephyr with the target `$your_board`, follow these steps:
159199
160-
To add a new board that is already supported by mainline Zephyr, follow these steps:
200+
* Get the variant name from your board by running `extra/get_variant_name.sh $your_board`.
201+
* Create a folder in the [`variants/`](/variants) directory with the same name as the variant for your new board.
202+
* Create the DTS `<variant>.overlay` and Kconfig `<variant>.conf` files in that directory.
161203
162-
* Create the `DTS overlay` and `.conf` files in the [loader](/loader/boards) directory.
163204
The overlay must include:
164-
* A flash partition called `user_sketch`, tipically located near the end of the flash.
205+
* A flash partition called `user_sketch`, typically located near the end of the flash.
165206
* A `zephyr,user` section containing the description for GPIOs, Analog, UART, SPI and I2C devices. Feel free to leave some fields empty in case Zephyr support is missing. This will result in some APIs not being available at runtime (eg. `analogWrite` if PWM section is empty).
166-
* Build the Loader: run `./extra.build.sh $your_board $your_board` and start debugging the errors. :grin:
207+
208+
The Kconfig file must include any board-specific options required by this target.
209+
* Build the Loader: run `./extra/build.sh $your_board` (with any additional arguments as required) and start debugging the errors. :grin:
167210
* Update the `boards.txt`: add an entry for your board, manually filling the required fields.
168-
* Implement touch support: if your board supports the `1200bps touch` method, implement `_on_1200_bps` in a file located inside the `variant/your_board` folder.
169-
* ⏳ Temporary steps
170-
* Create `includes.txt` based on `llext-edk/Makefile.cflags`, taking inspiration for other variants.
171-
* Amend `your_board.compiler.zephyr.*` with information from `llext-edk/Makefile.cflags`.
211+
212+
Make sure to set:
213+
* `build.zephyr_target` and `build.zephyr_args` to the arguments used in the `build.sh` call;
214+
* `build.zephyr_hals` to the (space-separated list of) HAL modules required by the board;
215+
* `build.variant` to the variant name identified above.
216+
* Implement touch support: if your board supports the "1200bps touch" method, implement `_on_1200_bps` in a file located inside the variant folder of your board.
172217
173218
## 🐛 Bug Reporting
174219
@@ -183,14 +228,12 @@ Contributions are always welcome. The preferred way to receive code contribution
183228
184229
## 📌 Upcoming features
185230
186-
- [x] Unify overlay in [loader](/loader/boards) with the one provided in [variant](/variant) for interoperability with GSoC project
187-
- [x] Autogenerate `defines.txt`, `includes.txt`, `cflags.txt` from `llext-edk` output
231+
- [ ] Remove binaries from this repo history (arduino/ArduinoCore-zephyr#102, :warning: will require a clean clone)
188232
- [x] Network: support UDP and TLS
189-
- [ ] USB: switch to USB_DEVICE_STACK_NEXT to support PluggableUSB
190-
- [ ] Relocate RODATA in flash to accomodate sketches with large assets
233+
- [ ] USB: switch to `USB_DEVICE_STACK_NEXT` to support PluggableUSB
234+
- [ ] Relocate RODATA in flash to accommodate sketches with large assets
191235
- [ ] Provide better error reporting for failed llext operations
192-
- [ ] Replace [llext_exports.c](/loader/llext_exports.c) with proper symbols generation (via includes)
193-
- [x] Provide better usability for `Debug` builds (eg. shell over USB)
236+
- [ ] Replace [`llext_exports.c`](/loader/llext_exports.c) with proper symbols generation (via includes)
194237
- [ ] Fix corner cases with `std::` includes (like `<iterator>`)
195238
- [ ] Get rid of all warnings
196239

boards.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ giga.menu.debug.true.postbuild_debug=-debug
1414

1515
giga.build.zephyr_target=arduino_giga_r1//m7
1616
giga.build.zephyr_args=--shield arduino_giga_display_shield
17+
giga.build.zephyr_hals=hal_stm32
1718
giga.build.variant=arduino_giga_r1_stm32h747xx_m7
1819
giga.build.mcu=cortex-m7
1920
giga.build.fpu=-mfpu=fpv5-d16
@@ -79,6 +80,7 @@ nano33ble.menu.debug.true.postbuild_debug=-debug
7980

8081
nano33ble.build.zephyr_target=arduino_nano_33_ble//sense
8182
nano33ble.build.zephyr_args=
83+
nano33ble.build.zephyr_hals=hal_nordic
8284
nano33ble.build.variant=arduino_nano_33_ble_nrf52840_sense
8385
nano33ble.build.mcu=cortex-m4
8486
nano33ble.build.fpu=-mfpu=fpv4-sp-d16
@@ -142,6 +144,7 @@ ek_ra8d1.menu.debug.true.postbuild_debug=-debug
142144

143145
ek_ra8d1.build.zephyr_target=ek_ra8d1
144146
ek_ra8d1.build.zephyr_args=
147+
ek_ra8d1.build.zephyr_hals=hal_renesas
145148
ek_ra8d1.build.variant=ek_ra8d1_r7fa8d1bhecbd
146149
ek_ra8d1.build.mcu=cortex-m85+nomve
147150
ek_ra8d1.build.fpu=-mfpu=fpv5-d16
@@ -200,6 +203,7 @@ frdm_mcxn947.menu.debug.true.postbuild_debug=-debug
200203

201204
frdm_mcxn947.build.zephyr_target=frdm_mcxn947//cpu0
202205
frdm_mcxn947.build.zephyr_args=
206+
frdm_mcxn947.build.zephyr_hals=hal_nxp
203207
frdm_mcxn947.build.variant=frdm_mcxn947_mcxn947_cpu0
204208
frdm_mcxn947.build.mcu=cortex-m33
205209
frdm_mcxn947.build.fpu=-mfpu=fpv5-sp-d16
@@ -253,6 +257,7 @@ portentah7.menu.debug.true.postbuild_debug=-debug
253257

254258
255259
portentah7.build.zephyr_args=
260+
portentah7.build.zephyr_hals=hal_stm32
256261
portentah7.build.variant=arduino_portenta_h7_stm32h747xx_m7
257262
portentah7.build.mcu=cortex-m7
258263
portentah7.build.fpu=-mfpu=fpv5-d16
@@ -318,6 +323,7 @@ frdm_rw612.menu.debug.true.postbuild_debug=-debug
318323

319324
frdm_rw612.build.zephyr_target=frdm_rw612
320325
frdm_rw612.build.zephyr_args=
326+
frdm_rw612.build.zephyr_hals=hal_stm32
321327
frdm_rw612.build.variant=frdm_rw612_rw612
322328
frdm_rw612.build.mcu=cortex-m33+nodsp
323329
frdm_rw612.build.fpu=-mfpu=fpv5-sp-d16
@@ -370,6 +376,7 @@ niclasense.menu.debug.true.postbuild_debug=-debug
370376

371377
niclasense.build.zephyr_target=arduino_nicla_sense_me
372378
niclasense.build.zephyr_args=
379+
niclasense.build.zephyr_hals=hal_nordic
373380
niclasense.build.variant=arduino_nicla_sense_me_nrf52832
374381
niclasense.build.mcu=cortex-m4
375382
niclasense.build.fpu=-mfpu=fpv4-sp-d16
@@ -449,6 +456,7 @@ portentac33.menu.mode.linked.postbuild_mode=-prelinked
449456

450457
portentac33.build.zephyr_target=arduino_portenta_c33
451458
portentac33.build.zephyr_args=
459+
portentac33.build.zephyr_hals=hal_renesas
452460
portentac33.build.variant=arduino_portenta_c33_r7fa6m5bh3cfc
453461
portentac33.build.mcu=cortex-m33
454462
portentac33.build.fpu=-mfpu=fpv5-sp-d16
@@ -504,6 +512,7 @@ opta.menu.debug.true.postbuild_debug=-debug
504512

505513
opta.build.zephyr_target=arduino_opta//m7
506514
opta.build.zephyr_args=
515+
opta.build.zephyr_hals=hal_stm32
507516
opta.build.variant=arduino_opta_stm32h747xx_m7
508517
opta.build.mcu=cortex-m7
509518
opta.build.fpu=-mfpu=fpv5-d16

cores/arduino/SerialUSB.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class SerialUSB_ : public ZephyrSerial {
1818
void begin(unsigned long baudrate) { begin(baudrate, SERIAL_8N1); }
1919

2020
operator bool() override;
21+
size_t write(const uint8_t *buffer, size_t size) override;
22+
void flush() override;
2123

2224
protected:
2325
uint32_t dtr = 0;

cores/arduino/USB.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,16 @@ arduino::SerialUSB_::operator bool() {
124124
return dtr;
125125
}
126126

127+
128+
size_t arduino::SerialUSB_::write(const uint8_t *buffer, size_t size) {
129+
if (!Serial) return 0;
130+
return arduino::ZephyrSerial::write(buffer, size);
131+
}
132+
133+
void arduino::SerialUSB_::flush() {
134+
if (!Serial) return;
135+
arduino::ZephyrSerial::flush();
136+
}
137+
127138
arduino::SerialUSB_ Serial(usb_dev);
128139
#endif

extra/bootstrap.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,23 @@ if [ ! -f platform.txt ]; then
55
exit 2
66
fi
77

8+
NEEDED_HALS=$(grep 'build.zephyr_hals=' boards.txt | cut -d '=' -f 2 | xargs -n 1 echo | sort -u)
9+
10+
HAL_FILTER="-hal_.*"
11+
for hal in $NEEDED_HALS; do
12+
HAL_FILTER="$HAL_FILTER,+$hal"
13+
done
14+
815
python3 -m venv venv
916
source venv/bin/activate
1017
pip install west
1118
west init -l .
19+
west config manifest.project-filter -- "$HAL_FILTER"
1220
west update "$@"
1321
west zephyr-export
1422
pip install -r ../zephyr/scripts/requirements-base.txt
15-
# download slim toolchain from https://github.com/zephyrproject-rtos/sdk-ng/releases/tag/v0.16.8
23+
west sdk install --version 0.17.0 -t arm-zephyr-eabi
1624

17-
# add here the required blobs based on supported platforms
18-
west blobs fetch hal_nxp
25+
for hal in $NEEDED_HALS; do
26+
west blobs fetch $hal
27+
done

0 commit comments

Comments
 (0)