Skip to content

Commit 350ba1e

Browse files
committed
feat: add smarty part one
1 parent b10c308 commit 350ba1e

File tree

9 files changed

+7279
-100
lines changed

9 files changed

+7279
-100
lines changed

.vscode/tasks.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@
3939
},
4040
{
4141
"label": "autobuild docs",
42-
"command": ".venv/Scripts/sphinx-autobuild -E -a ${workspaceFolder}/docs ${workspaceFolder}/build/docs",
42+
"command": ".venv/bin/sphinx-autobuild -E -a ${workspaceFolder}/docs ${workspaceFolder}/build/docs",
43+
"windows": {
44+
"command": ".venv/Scripts/sphinx-autobuild -E -a ${workspaceFolder}/docs ${workspaceFolder}/build/docs"
45+
},
4346
"type": "shell",
4447
"presentation": {
4548
"reveal": "always"
@@ -51,7 +54,13 @@
5154
},
5255
{
5356
"label": "open docs index.html",
54-
"command": "${workspaceFolder}/build/docs/index.html",
57+
"command": "xdg-open ${workspaceFolder}/build/docs/index.html",
58+
"osx": {
59+
"command": "open ${workspaceFolder}/build/docs/index.html"
60+
},
61+
"windows": {
62+
"command": "explorer ${workspaceFolder}\\build\\docs\\index.html"
63+
},
5564
"type": "shell",
5665
"presentation": {
5766
"reveal": "always"
539 KB
Loading
134 KB
Loading

docs/blogs/2026/smarty.md

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
---
2+
tags: smart home, matter, thread, zephyr, esp32, esp-idf
3+
category: learning
4+
date: 2026-01-25
5+
title: Smarty - Matter on ESP32 with Zephyr
6+
---
7+
8+
# Smarty - Matter on ESP32 with Zephyr
9+
10+
11+
```{admonition} Disclaimer
12+
:class: dropdown, warning
13+
14+
I am an engineer who knows his sh*t and prioritizes learning and innovation to getting certifications for tinkering with hardware. To follow along with the hardware portions of this guide, you should either:
15+
16+
- Be an engineer who also knows their sh*t.
17+
- Accept that you are responsible for your own components and safety.
18+
- Or just sit back and enjoy the read.
19+
20+
Reading is still learning, and you are more than welcome to just follow the code without touching a single wire. However, if you do decide to dive into the hardware and things go sideways, whether it's a fried ESP32, a tripped breaker, or a "spicy" encounter with mains power, I am not to be held accountable. I take no responsibility for your hardware, your home, or yourself. You are the captain of your own (hopefully well-insulated) ship.
21+
```
22+
23+
This is the first in a series of articles about upgrading my DIY smart home devices software stack to use Zephyr and Matter.
24+
25+
My existing smart home devices are based on `esp32-h2` development boards and use the ESP-IDF framework with the [esp-matter](https://github.com/espressif/esp-matter) stack. I had [Zephyr](https://zephyrproject.org/) on my todo list for a while now and I finally decided to give it a try.
26+
27+
The plan is to migrate my existing smart home devices to use Zephyr and Matter.
28+
29+
- Start with the `Hello World` Zephyr example and try to understand the build system
30+
- Build the same example using [yanga](https://github.com/cuinixam/yanga) build system generator. This will allow me to separate the Zephyr build tools from the Zephyr source code, and to use my own build system generator with the proper abstraction layer for defining software products.
31+
- Make the onboard LED a "smart light" Matter device that I can integrate with Home Assistant and Apple HomeKit.
32+
33+
## PART 1: Hello World on ESP32-H2
34+
35+
I started by following the [Zephyr Getting Started Guide](https://docs.zephyrproject.org/latest/develop/getting_started/index.html).
36+
I followed the Ubuntu instructions because I am using an Ubuntu VM on my Mac using Parallels.
37+
38+
These are basically the commands I ran:
39+
40+
```bash
41+
# Create a virtual environment and activate it
42+
python3 -m venv ~/zephyrproject/.venv
43+
source ~/zephyrproject/.venv/bin/activate
44+
45+
# Install west and initialize the zephyr project
46+
pip install west
47+
west init ~/zephyrproject\
48+
cd ~/zephyrproject\
49+
west update
50+
51+
# Export the zephyr project
52+
west zephyr-export
53+
54+
# Install west packages
55+
west packages pip --install
56+
cd ~/zephyrproject/zephyr
57+
58+
# Install Zephyr SDK
59+
west sdk install --help
60+
west sdk install --toolchains riscv64-zephyr-elf
61+
62+
# Fetch the hal_espressif zephyr module
63+
west blobs fetch hal_espressif
64+
65+
# Check available boards
66+
west boards | grep esp32h2
67+
68+
# Build the hello world example for the esp32-h2
69+
west build -b esp32h2_devkitm samples/hello_world
70+
```
71+
72+
I have an ESP32-H2 devkit board from Waveshare:
73+
74+
![esp32-h2 devkit board](images/esp32-h2-devkitm.jpeg){w=200px}
75+
76+
I connected it to my computer, answered yes to a dozen questions to confirm that I want to make the USB port available to my VM and then I wanted to flash the hello world example to it.
77+
78+
```bash
79+
west flash
80+
```
81+
82+
````{error}
83+
This failed because it could not access the serial port.
84+
85+
```txt
86+
Serial port /dev/ttyACM0:
87+
/dev/ttyACM0 failed to connect: Could not open /dev/ttyACM0: Permission denied
88+
```
89+
90+
I had to add my user to the dialout group (`sudo usermod -aG dialout $USER`) and reboot to make it work.
91+
I skipped installing the official espressif udev tools which ensures the system
92+
recognizes the ESP32-H2 correctly and assigns the right permissions every time you plug it in.
93+
````
94+
95+
I now flashed the hello world example to the esp32-h2 and connected to it using the espressif monitor.
96+
97+
```bash
98+
west flash
99+
west espressif monitor --port /dev/ttyACM0
100+
```
101+
102+
It worked! 🤓
103+
104+
```
105+
*** Booting Zephyr OS build v4.3.0-5066-gf28522e03666 ***
106+
Hello World! esp32h2_devkitm/esp32h2
107+
```
108+
109+
```{tip}
110+
If it still doesn't work, your board might be in the *download mode*.
111+
You can exit it by pressing and holding the *BOOT* button shortly.
112+
```
113+
114+
### Analyze the build environment and generated artifacts
115+
116+
First, let's analyze what did we installed:
117+
118+
- `~/zephyrproject - 9GB`:
119+
- `modules - 6.7GB`: it contains the hardware abstraction layers (HAL) modules, including `hal_espressif`
120+
- `zephyr - 1.4GB`: this is the main Zephyr source code (core, drivers, cmake scripts, west scripts, etc.)
121+
- `.venv - 800MB`: this is the virtual environment used to run west and other Zephyr tools
122+
- `~/zephyr-sdk-0.17.4 - 2.4GB`: this is the Zephyr SDK having the compiler suite for `riscv64-zephyr-elf` and the host tools
123+
124+
It seems we need around 12GB of disk space to build the hello world example. 🫣
125+
The modules directory has not only the espressif HAL, but also many other HAL modules.
126+
Of course, we downloaded more than we needed, but it is still a lot of space.
127+
128+
Let's us now have a look at the binary file to understand which components are included and the dependencies.
129+
130+
I implemented a python app [clanguru](https://github.com/cuinixam/clanguru) to help me analyze binary files and C code in general.
131+
132+
```bash
133+
# Install clanguru
134+
pipx install clanguru
135+
clanguru --version
136+
# Generate the objects dependencies graph
137+
clanguru analyze --help
138+
clanguru analyze --compilation-database build/compile_commands.json --output-file obj_deps.html
139+
```
140+
141+
I linked below the interactive objects dependencies graph.
142+
This is a interactive view where you can select which directories shall be visible, search for particular files or click on nodes to highlight their direct dependencies. Check the help button for an overview of all features.
143+
144+
145+
````{grid} 1
146+
:gutter: 1
147+
148+
```{grid-item-card} Objects dependencies
149+
:text-align: justify
150+
:img-top: images/obj_deps_hello_world.png
151+
:link: /objects_deps_hello_world_zephyr/index.html
152+
:width: 50%
153+
154+
```
155+
156+
157+
We can see that there are two main parts:
158+
159+
- `zephyr`: for the Zephyr kernel, drivers and `espressif` soc support
160+
- `hal_espressif`: for the espressif hardware abstraction layer including the bootloader support
161+
162+
163+
## Next steps
164+
165+
We identified the main parts and the toolchain required to build the hello world example. Next I will setup a [yanga](https://github.com/cuinixam/yanga) project to build the same example. The goal is to configure in `yanga`:
166+
167+
- the two external dependencies `zephyr` and `hal_espressif`
168+
- the toolchain `riscv64-zephyr-elf`
169+
- the platform `esp32h2_devkitm`
170+
- a `hello_world` component
171+
172+
One shall be able to clone the repository and build it using `yanga` on both Ubuntu and Windows by running a single command.
173+
No extra steps to install toolchains or other dependencies.
174+
175+
I think this will be fun and I hope I'll get to it by the end of the week.

docs/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
# copy button for code block
5858
extensions.append("sphinx_copybutton")
5959

60+
extensions.append("sphinx_togglebutton")
61+
6062
# -- HTML output ---------------------------------------------------
6163
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
6264

docs/presentations/objects_deps/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55329,7 +55329,7 @@
5532955329
]
5533055330
};
5533155331
</script>
55332-
55332+
5533355333
<script src="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.23.0/cytoscape.min.js"></script>
5533455334
<script src="https://unpkg.com/webcola@3.4.0/WebCola/cola.min.js"></script>
5533555335
<script src="https://unpkg.com/cytoscape-cola@2.5.1/cytoscape-cola.js"></script>
@@ -56404,4 +56404,3 @@ <h3>📁 Directory Filter</h3>
5640456404
</body>
5640556405

5640656406
</html>
56407-

0 commit comments

Comments
 (0)