Skip to content

Commit 0a78d2d

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

File tree

1 file changed

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

1 file changed

+32
-7
lines changed

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

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ The result will look something like this:
8484

8585
![make menuconfig](img/make_menuconfig.webp)
8686

87+
In addition to the debugging capability, it is recommended to enable merge bin option to have one binary in case of different bootloader usage such as MCUBoot. To enable that option select `Merge raw binary files into a single file` option under the `Board Selection` menu. The rest of this article assumes that this option is enabled.
8788

8889
After configuration and setup, we can use the following command to compile:
8990

@@ -97,6 +98,7 @@ We should see the following output:
9798
LD: nuttx
9899
CP: nuttx.hex
99100
CP: nuttx.bin
101+
Generated: nuttx.merged.bin
100102
```
101103

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

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

118-
- Add the `nuttx` file path to the `wokwi.toml` file
120+
- Add the `nuttx` and `nuttx.merged.bin` file paths to the `wokwi.toml` file
119121
- Add the circuit diagram in the `diagram.json` file to use in simulation
120122

121123
The file contents we need in this example project will be as follows:
@@ -124,7 +126,7 @@ The file contents we need in this example project will be as follows:
124126
```toml
125127
[wokwi]
126128
version = 1
127-
firmware = 'nuttx'
129+
firmware = 'nuttx.merged.bin'
128130
elf = 'nuttx'
129131
```
130132

@@ -135,7 +137,11 @@ elf = 'nuttx'
135137
"author": "Anonymous maker",
136138
"editor": "wokwi",
137139
"parts": [
138-
{ "type": "board-esp32-devkit-c-v4", "id": "esp", "top": 0, "left": 0, "attrs": {} } }
140+
{
141+
"type": "board-esp32-devkit-c-v4",
142+
"id": "esp",
143+
"attrs": { "firmwareOffset": "0"}
144+
}
139145
],
140146
"connections": [
141147
[ "esp:TX", "$serialMonitor:RX", "", [] ],
@@ -145,6 +151,8 @@ elf = 'nuttx'
145151
}
146152
```
147153

154+
*Note: If merge bin option is not enabled, `firmware` variable in `wokwi.toml` file will be set to `nuttx.bin`, and `firmwareOffset` variable in the `diagram.json` file will be `0x1000`*
155+
148156
After creating the necessary files, we can start the simulation by pressing `F1` and selecting the `Wokwi: Start Simulator` option:
149157

150158
![start simulator](img/start_simulator.webp)
@@ -173,12 +181,31 @@ As a result of the process, the `wokwi.toml` file will look like this for this e
173181
```toml
174182
[wokwi]
175183
version = 1
176-
firmware = 'nuttx'
184+
firmware = 'nuttx.merged.bin'
177185
elf = 'nuttx'
178186
gdbServerPort=3333
179187
```
180188

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.
189+
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:
190+
191+
```text
192+
target remote :3333
193+
set remote hardware-watchpoint-limit 2
194+
mon reset halt
195+
symbol-file nuttx
196+
flushregs
197+
c
198+
```
199+
200+
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:
201+
202+
```bash
203+
xtensa-esp32-elf-gdb -x gdbinit
204+
```
205+
206+
After running the debugger, you can start to debug with Wokwi using the `F5` key in simulator.
207+
208+
If you want to avoid using the terminal-based debugger you can 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. This launch file is optional, does not necessary to enable debugging.
182209

183210
![NuttX debug](img/wokwi_debug.webp)
184211

@@ -202,8 +229,6 @@ Here's a template you can use:
202229
}
203230
```
204231

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-
207232
For more detailed information about the debugging, you can visit [this link](https://docs.wokwi.com/guides/debugger).
208233

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

0 commit comments

Comments
 (0)