Skip to content

Commit 8532ffa

Browse files
committed
Updates to Using Wokwi with NuttX article
Article changes to use Wokwi with NuttX properly
1 parent 0f42ea7 commit 8532ffa

File tree

1 file changed

+35
-7
lines changed
  • content/blog/2024/11/using-wokwi-with-nuttx

1 file changed

+35
-7
lines changed

content/blog/2024/11/using-wokwi-with-nuttx/index.md

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: "Using Wokwi with NuttX"
33
date: 2024-11-13T00:08:20+01:00
4+
lastmod: 2025-12-10
45
tags: ["NuttX", "Apache", "ESP32", "POSIX", "Linux", "Wokwi", "Simulation"]
56
showAuthor: false
67
featureAsset: "img/featured_nuttx_using_wokwi.webp"
@@ -84,6 +85,7 @@ The result will look something like this:
8485

8586
![make menuconfig](img/make_menuconfig.webp)
8687

88+
In addition to the debugging capability, it is recommended to enable the merge bin option to have one binary file. To enable that option, go to the `Board Selection` menu and set `Merge raw binary files into a single file`. The rest of this article assumes that this option is enabled.
8789

8890
After configuration and setup, we can use the following command to compile:
8991

@@ -97,6 +99,7 @@ We should see the following output:
9799
LD: nuttx
98100
CP: nuttx.hex
99101
CP: nuttx.bin
102+
Generated: nuttx.merged.bin
100103
```
101104

102105
After the compilation process is successfully completed, we need the `nuttx` file for the simulation.
@@ -115,7 +118,7 @@ For details about Wokwi configuration files, see [here](https://docs.wokwi.com/v
115118

116119
If we go back to the Simulation section after these definitions, we need to do two things:
117120

118-
- Add the `nuttx` file path to the `wokwi.toml` file
121+
- Add the `nuttx` and `nuttx.merged.bin` file paths to the `wokwi.toml` file
119122
- Add the circuit diagram in the `diagram.json` file to use in simulation
120123

121124
The file contents we need in this example project will be as follows:
@@ -124,7 +127,7 @@ The file contents we need in this example project will be as follows:
124127
```toml
125128
[wokwi]
126129
version = 1
127-
firmware = 'nuttx'
130+
firmware = 'nuttx.merged.bin'
128131
elf = 'nuttx'
129132
```
130133

@@ -135,7 +138,11 @@ elf = 'nuttx'
135138
"author": "Anonymous maker",
136139
"editor": "wokwi",
137140
"parts": [
138-
{ "type": "board-esp32-devkit-c-v4", "id": "esp", "top": 0, "left": 0, "attrs": {} } }
141+
{
142+
"type": "board-esp32-devkit-c-v4",
143+
"id": "esp",
144+
"attrs": { "firmwareOffset": "0"}
145+
}
139146
],
140147
"connections": [
141148
[ "esp:TX", "$serialMonitor:RX", "", [] ],
@@ -145,6 +152,10 @@ elf = 'nuttx'
145152
}
146153
```
147154

155+
{{< alert >}}
156+
If the merge bin option is not enabled, the `firmware` variable in `wokwi.toml` file will be set to `nuttx.bin`, and the `firmwareOffset` variable in the `diagram.json` file will be `0x1000`.
157+
{{< /alert >}}
158+
148159
After creating the necessary files, we can start the simulation by pressing `F1` and selecting the `Wokwi: Start Simulator` option:
149160

150161
![start simulator](img/start_simulator.webp)
@@ -173,12 +184,31 @@ As a result of the process, the `wokwi.toml` file will look like this for this e
173184
```toml
174185
[wokwi]
175186
version = 1
176-
firmware = 'nuttx'
187+
firmware = 'nuttx.merged.bin'
177188
elf = 'nuttx'
178189
gdbServerPort=3333
179190
```
180191

181-
Also you need to create a launch configuration file for Visual Studio Code. You can create the file at `.vscode/launch.json` path or you can use `Open user settings (JSON)` option with pressing `F1` key.
192+
After that, press `F1` and select `Wokwi: Start Simulator and Wait for Debugger` to start the simulator. Wokwi will then go into standby mode to allow the debugger to connect. In a separate terminal tab you can run GDB with `xtensa-esp32-elf-gdb` or similar commands for Xtensa devices or `riscv-none-elf-gdb` for RISC-V devices. To establish a proper connection with Wokwi, the following commands need to be applied:
193+
194+
```text
195+
target remote :3333
196+
set remote hardware-watchpoint-limit 2
197+
mon reset halt
198+
symbol-file nuttx
199+
flushregs
200+
c
201+
```
202+
203+
These commands can be entered manually after starting the debugger, or they can be provided as a script file. For example, if the commands are saved in a file named `gdbinit`, you can run GDB with this command:
204+
205+
```bash
206+
xtensa-esp32-elf-gdb -x gdbinit
207+
```
208+
209+
After running the debugger, you can start to debug with Wokwi using the `F5` key in simulator.
210+
211+
This is one way to debug using the terminal, but there is also an alternative method that doesn’t require the terminal and everything can be done directly inside Visual Studio Code. If you want to avoid using the terminal-based debugger you need to create a launch configuration file for Visual Studio Code. You can create the file at `.vscode/launch.json` path or you can use `Open user settings (JSON)` option with pressing `F1` key.
182212

183213
![NuttX debug](img/wokwi_debug.webp)
184214

@@ -202,8 +232,6 @@ Here's a template you can use:
202232
}
203233
```
204234

205-
After that, press `F1` and select `Wokwi: Start Simulator and Wait for Debugger` to start the simulator. Wokwi will then go into standby mode to allow the debugger to connect. In a separate terminal tab you can run GDB with `xtensa-esp32-elf-gdb` or similar commands for Xtensa devices or `riscv-none-elf-gdb` for RISC-V devices. After running the debugger, you can start to debug with Wokwi using the `F5` key in simulator.
206-
207235
For more detailed information about the debugging, you can visit [this link](https://docs.wokwi.com/guides/debugger).
208236

209237
Of course, our hope is that you will not need this process :)

0 commit comments

Comments
 (0)