|
1 |
| -# Arduino Core for Zephyr BETA |
| 1 | +> [!IMPORTANT] |
| 2 | +> This core is in **BETA**. 🧪 |
| 3 | +> Features may change, and bugs may be present. Use for testing only and provide feedback to help us improve. |
2 | 4 |
|
3 |
| -This repository contains the official implementation of **Arduino Core** for Zephyr based board. |
| 5 | +# 🚧 Arduino Core for Zephyr |
4 | 6 |
|
5 |
| -Easily install the core and its toolchains via Board Manager using this URL: https://downloads.arduino.cc/packages/package_zephyr_index.json |
| 7 | +This repository contains the official implementation of **Arduino Core** for Zephyr RTOS based board. |
6 | 8 |
|
7 |
| -## Theory of operation |
| 9 | +## 🧐 What is Zephyr? |
8 | 10 |
|
9 |
| -Unlike every other Arduino implementation (where the final compilation step is a standalone binary, eventually loaded by a bootloader), this one creates a freestanding elf file that can be dynamically loaded by a static (precompiled) Zephyr firmware. |
| 11 | +[Zephyr RTOS](https://zephyrproject.org/) is an open-source, real-time operating system designed for low-power, resource-constrained devices. It's modular, scalable, and supports multiple architectures. |
10 | 12 |
|
11 |
| -The most important parts of this project are: |
| 13 | + |
| 14 | + |
| 15 | +## ⚙️ Installation |
| 16 | + |
| 17 | +Install the core and its toolchains via Board Manager: |
| 18 | +* Download and install the latest [Arduino IDE](https://www.arduino.cc/en/software) |
| 19 | +* Open the *'Settings / Preferences'* window |
| 20 | +* Open the *'Boards Manager'* from the side menu and search for *'Zephyr'* |
| 21 | + * If it does not show up - enter `https://downloads.arduino.cc/packages/package_zephyr_index.json` in the *'Additional Boards Manager URLs'* field (add a comma in between if you have multiple URLs) |
| 22 | +* Install the `Arduino Zephyr Boards` platform |
| 23 | + |
| 24 | +## 🧢 Under the hood |
| 25 | + |
| 26 | +Unlike traditional Arduino implementations, where the final output is a standalone binary loaded by a bootloader, this core generates a freestanding `elf` file. This file can be dynamically loaded by a precompiled Zephyr firmware, referred to as the `loader`. |
| 27 | + |
| 28 | +For the end user, installing the `loader` is easy. Simply run `Burn Bootloader` option from the IDE/CLI while the board is in bootloader mode (by double-clicking the RESET button). Note that due to limitations in the Arduino IDE, you may need to select a `bogus` programmer from the `Programmers` menu. |
| 29 | + |
| 30 | +To load the first sketch, the board must also be manually placed into bootloader mode. After this initial setup, the standard "autoload" method will take over for future sketches. |
| 31 | + |
| 32 | +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. |
| 33 | + |
| 34 | +The behavior of the `loader` can be adjusted through the `Mode` menu: |
| 35 | +- `Standard`: The sketch is loaded automatically. |
| 36 | +- `Debug`: The user must type `sketch` in Zephyr's shell, which is accessible via the default Serial. |
| 37 | + |
| 38 | +The most important components of this project are: |
12 | 39 |
|
13 | 40 | * [Zephyr based loader](/loader)
|
14 | 41 | * [LLEXT](https://docs.zephyrproject.org/latest/services/llext/index.html)
|
15 | 42 | * [Actual core](/cores/arduino) with [variants](/variants) and the usual `{platform,boards}.txt`
|
16 | 43 | * [ArduinoCore-API](https://github.com/arduino/ArduinoCore-API)
|
17 | 44 | * [post_build_tool](/extra/post_build_tool)
|
18 | 45 |
|
19 |
| -The `loader` project should be kept generic and any modification required for a given board should be added to its dts overlay or a special `fixup` file (with the proper guards). |
20 |
| -The loader changes its behaviour based on the `Mode` menu. |
21 |
| -`Standard` means that the sketch is loaded automatically, while `Debug` requires the user to type `sketch` in Zephyr's shell (exposed over the default UART). |
22 |
| - |
23 |
| -For the end user, installing the `loader` only requires running `Burn Bootloader` while the board is in bootloader mode (double clicking the RESET button should be do the trick). Due to Arduino IDE limitiations, you must select a bogus programmer from `Programmers` menu. |
| 46 | +## 🛠️ Setup the environment |
24 | 47 |
|
25 |
| -Loading the first sketch also requires the board to be placed forcefully in bootloader mode. From then on, the usual "autoload" method will kick in. |
| 48 | +In this section, we’ll guide you through setting up your environment to work with the core, making it easy to compile and upload your sketches to compatible boards. |
26 | 49 |
|
27 |
| -## Setup the environment |
| 50 | +Shell scripts are available to simplify the installation process (Windows is not supported at the moment 😔). |
28 | 51 |
|
29 |
| -We provide some shell scripts to ease installation (Windows not supported ATM) |
30 |
| -On a new terminal, run |
31 |
| -``` |
| 52 | +### Clone the repository |
| 53 | +```bash |
32 | 54 | mkdir my_new_zephyr_folder && cd my_new_zephyr_folder
|
33 | 55 | git clone https://github.com/arduino/ArduinoCore-zephyr
|
| 56 | +``` |
| 57 | +### Pre-requirements |
| 58 | +Before running the installation script, ensure that `python3` and `pip` are installed on your system. The script will automatically install `west` and manage the necessary dependencies. |
| 59 | + |
| 60 | +### Run the ```bootstrap``` script |
| 61 | +```bash |
34 | 62 | cd ArduinoCore-zephyr
|
35 | 63 | ./extra/bootstrap.sh
|
36 | 64 | ```
|
| 65 | +### Install the Zephyr SDK |
| 66 | +Download and install the Zephyr SDK for your OS from [here](https://github.com/zephyrproject-rtos/sdk-ng/releases/tag/v0.16.8). |
37 | 67 |
|
38 |
| -Then you need to download and install the Zephyr SDK for your OS from https://github.com/zephyrproject-rtos/sdk-ng/releases/tag/v0.16.8 |
| 68 | +> [!NOTE] |
| 69 | +> This core is validated for version v0.16.8. Compatibility with later versions has not been tested yet. |
39 | 70 |
|
40 |
| -To build a loader, run |
41 |
| -``` |
| 71 | +### Build the Loader |
| 72 | + |
| 73 | +To build a loader, run the following commands: |
| 74 | +```bash |
42 | 75 | export ZEPHYR_SDK_INSTALL_DIR=$folder_where_you_installed_the_sdk
|
43 | 76 | ./extra/build.sh $zephyr_board_name $arduino_variant_board_name
|
44 |
| -# eg: ./extra/build.sh arduino_portenta_h7//m7 arduino_portenta_h7 |
45 | 77 | ```
|
| 78 | +Replace `$zephyr_board_name` and `$arduino_variant_board_name` with the appropriate names for your board. |
| 79 | + |
| 80 | +Example for Arduino Portenta H7: |
| 81 | +```bash |
| 82 | +./extra/build.sh arduino_portenta_h7//m7 arduino_portenta_h7 |
| 83 | +``` |
| 84 | + |
46 | 85 | The firmwares will be copied to [firmwares](/firmwares) folder.
|
47 | 86 |
|
48 |
| -If the board is fully supported by Zephyr, they can also be directly falshed with `west flash` |
| 87 | +### Flash the Loader |
| 88 | + |
| 89 | +If the board is fully supported by Zephyr, you can flash the firmware directly onto the board using the following command: |
| 90 | +```bash |
| 91 | +west flash |
| 92 | +``` |
49 | 93 |
|
50 |
| -## Use the core in Arduino environment |
| 94 | +## 🖥️ Using the Core in Arduino IDE/CLI |
51 | 95 |
|
52 |
| -After runnign the `bootstrap` script, you should be able to symlink the core to `$sketchbook/hardware/arduino-git/zephyr` and it will appear in the IDE/CLI. Boards FQBN will then become `arduino-git:zephyr:name_from_boards_txt` |
| 96 | +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`. |
53 | 97 |
|
54 |
| -## Toubleshooting |
| 98 | +## 🔧 Troubleshooting |
55 | 99 |
|
56 |
| -**Q: My Sketch doesn't start (Serial doen't appear)** |
| 100 | +### Common Issues |
57 | 101 |
|
58 |
| -**A:** Connect a USB-to-UART adapter to the default UART (eg. TX0/RX0 on Giga, TX,RX on Nano) and read the error message |
| 102 | +#### **Q: My Sketch doesn't start (Serial doesn't appear)** |
| 103 | +**A:** Connect a USB-to-UART adapter to the default UART (eg. TX0/RX0 on Giga, TX/RX on Nano) and read the error message (with the sketch compiled in `Default` mode). If you don't own a USB-to-UART adapter, compile the sketch in `Debug` mode; this will force the shell to wait until you open the Serial Monitor. Then, run `sketch` command and *probably* you'll be able to read the error (if generated by `llext`). For OS crashes, the USB-to-UART adapter is the only way to collect the crash. |
59 | 104 |
|
60 |
| -**Q: I did it and I get a `<err> llext: Undefined symbol with no entry in symbol table ...`** |
| 105 | +--- |
61 | 106 |
|
| 107 | +#### **Q: I did it and I get the error: `<err> llext: Undefined symbol with no entry in symbol table ...`** |
62 | 108 | **A:** This means you are trying to use a Zephyr function which has not yet been exported. Open `llext_exports.c`, add the function you need and recompile/upload the loader.
|
63 | 109 |
|
64 |
| -**Q: I want to use a Zephyr subsystem which is not compiled in** |
| 110 | +--- |
65 | 111 |
|
| 112 | +#### **Q: I want to use a Zephyr subsystem which is not compiled in** |
66 | 113 | **A:** Open the `.conf` file for your board, add the required `CONFIG_`, recompile/upload the loader.
|
67 | 114 |
|
68 |
| -**Q: I get an OS crash** |
| 115 | +--- |
| 116 | + |
| 117 | +#### **Q: I get an OS crash, like `<err> os: ***** USAGE FAULT *****`** |
| 118 | +**A:** This is usually due to a buffer overflow or coding error in the user's own code. However, since the project is still in beta 🧪, a [good bug report](#bug-reporting) could help identify any issues in our code. |
| 119 | + |
| 120 | +--- |
| 121 | + |
| 122 | +#### **Q: I get an out of memory error** |
| 123 | +**A:** Since collecting bug reports is very important at this time, we are keeping Zephyr's shell enabled to allow loading a full sketch (which requires a large stack). Adjust your board's `.conf` file to reduce the stack size if your platform doesn't have enough RAM. |
69 | 124 |
|
70 |
| -**A:** This is usally do to some buffer overflow/coding error in the user's own code. However, since the project is still in Beta, a [good bug report](#bug-reporting) could help identifying an issue in our code. |
| 125 | +## 📚 Libraries |
71 | 126 |
|
72 |
| -**Q: I get an out of memory error** |
| 127 | +### Included with the core: ### |
73 | 128 |
|
74 |
| -**A:** Since at this point in time collecting bug reports is very important, we are keeping Zephyr's shell enabled and able to load a full sketch (so its stack is very big). Tune your board's `.conf` to reduce that size if your platform down't have enough RAM |
| 129 | +### Separately supplied: ### |
| 130 | +- **ArduinoBLE**: This library is enabled only for the Arduino Nano 33 BLE. Please use [this branch](https://github.com/facchinm/ArduinoBLE/tree/zephyr_hci) to test it. |
75 | 131 |
|
76 |
| -## Bug Reporting |
| 132 | +## 🚀 Adding a new target |
| 133 | + |
| 134 | +To add a new board that is already supported by mainline Zephyr, follow these steps: |
| 135 | + |
| 136 | +* Create the `DTS overlay` and `.conf` files in the [loader](/loader/boards) directory. |
| 137 | + The overlay must include: |
| 138 | + * A flash partition called `user_sketch`, tipically located near the end of the flash. |
| 139 | + * 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). |
| 140 | +* Build the Loader: run `./extra.build.sh $your_board $your_board` and start debugging the errors. :grin: |
| 141 | +* Update the `boards.txt`: add an entry for your board, manually filling the required fields. |
| 142 | +* 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. |
| 143 | +* ⏳ Temporary steps |
| 144 | + * Create `includes.txt` based on `llext-edk/Makefile.cflags`, taking inspiration for other variants. |
| 145 | + * Amend `your_board.compiler.zephyr.*` with information from `llext-edk/Makefile.cflags`. |
| 146 | + |
| 147 | +## 🐛 Bug Reporting |
77 | 148 |
|
78 | 149 | To report a bug, open the [issues](/issues) and follow the instructions. Any issue opened without the needed information will be discarded.
|
79 | 150 |
|
80 |
| -## TODO |
| 151 | +## 🙌 Contributions |
| 152 | + |
| 153 | +Contributions are always welcome. The preferred way to receive code contribution is by submitting a [Pull Request](/pull). |
| 154 | + |
| 155 | +## 📌 Upcoming features |
81 | 156 |
|
82 | 157 | - [ ] Unify overlay in [loader](/loader/boards) with the one provided in [variant](/variant) for interoperability with GSoC project
|
83 | 158 | - [ ] Autogenerate `defines.txt`, `includes.txt`, `cflags.txt` from `llext-edk` output
|
84 | 159 | - [ ] Network: support UDP and TLS
|
85 | 160 | - [ ] USB: switch to USB_DEVICE_STACK_NEXT to support PluggableUSB
|
86 | 161 | - [ ] Relocate RODATA in flash to accomodate sketches with large assets
|
87 | 162 | - [ ] Provide better error reporting for failed llext operations
|
88 |
| -- [ ] Replace [llext_exports.c](/loader/llext_exports.c) with proper symbols generation (via inclues) |
| 163 | +- [ ] Replace [llext_exports.c](/loader/llext_exports.c) with proper symbols generation (via includes) |
89 | 164 | - [ ] Provide better usability for `Debug` builds (eg. shell over USB)
|
90 | 165 | - [ ] Fix corner cases with `std::` includes (like `<iterator>`)
|
| 166 | +- [ ] Get rid of all warnings |
91 | 167 |
|
92 |
| -## ADVANCED: Add a new target board |
93 |
| - |
94 |
| -* To add a new board (already supported by mainline Zephyr), you'll first need to create its `dts overlay` and `.conf` in [loader](/loader/boards). |
95 |
| - The overlay MUST contains: |
96 |
| - * A flash partition called `user_sketch`, usually near the end of the flash |
97 |
| - * 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) |
98 |
| -* Run `./extra.build.sh $your_board $your_board` and start debugging the errors :grin: |
99 |
| -* Add an entry in `boards.txt` for your board, manually filling the required fields |
100 |
| -* If your boards supports `1200pbs touch` method, implement `_on_1200_bps` in a file inside `variant/your_board` folder |
101 |
| -* Temporary: create `includes.txt` based on `llext-edk/Makefile.cflags`, taking inspiration for other variants |
102 |
| -* Temporary: amend `your_board.compiler.zephyr.*` with information from `llext-edk/Makefile.cflags` |
103 |
| -* Profit! |
104 |
| - |
105 |
| -## Acknowledgments |
| 168 | +## 🌟 Acknowledgments |
106 | 169 |
|
107 |
| -This effort would have been very hard without the [GSoC project](/README.gsoc.md) and in general the Zephyr community. |
| 170 | +This effort would have been very hard without the [GSoC project](/README.gsoc.md) and the Zephyr community. |
0 commit comments