Skip to content

Commit

Permalink
Add Wokwi debug support.
Browse files Browse the repository at this point in the history
  • Loading branch information
slav-at-attachix committed Dec 11, 2023
1 parent 4231a8c commit c17b942
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 32 deletions.
65 changes: 37 additions & 28 deletions Tools/ide/vscode/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Sming hardware configuration tool
#

import os, sys, copy, shutil
import os, sys, copy

appPath = os.path.dirname(os.path.realpath(__file__))
libPath = appPath + '/../common/'
Expand Down Expand Up @@ -58,36 +58,46 @@ def update_launch():
filename = '.vscode/launch.json'
launch = load_json(filename, False)
template = load_template('launch.json', appPath)
if env.get('ENABLE_WOKWI'):
wokwi_template = load_template('wokwi/launch.json', appPath)
template["configurations"].extend(wokwi_template["configurations"])
if launch is None:
launch = template.copy()
configurations = get_property(launch, 'configurations', [])
config_name = "%s GDB" % env['SMING_ARCH']
config = find_object(configurations, config_name)
template_config = find_object(template['configurations'], config_name)
if template_config is None:
print("Warning: Template launch configuration '%s' not found" % config_name)
elif not config is None:
configurations.remove(config)
config = template_config.copy()
configurations.append(config)

if config is None:
return

config['miDebuggerPath'] = find_tool(env['GDB'])
dbgargs = "-x ${env:SMING_HOME}/Arch/%s/Components/gdbstub/gdbcmds" % env['SMING_ARCH']
if env['SMING_ARCH'] == 'Host':
args = []
args += env['CLI_TARGET_OPTIONS'].split()
args += ["--"]
args += env['HOST_PARAMETERS'].split()
config['args'] = args
else:
if not env.isWsl():
dbgargs += " -b %s" % env.resolve('${COM_SPEED_GDB}')
config['miDebuggerServerAddress'] = env.resolve('${COM_PORT_GDB}')
config['miDebuggerArgs'] = dbgargs
config['program'] = "${workspaceFolder}/" + env.resolve('${TARGET_OUT_0}')
wokwi_config_name = "Wokwi GDB"
config_names = ["%s GDB" % env['SMING_ARCH']]
if env.get('ENABLE_WOKWI'):
config_names.append(wokwi_config_name)
for config_name in config_names:
config = find_object(configurations, config_name)
template_config = find_object(template['configurations'], config_name)
if template_config is None:
print("Warning: Template launch configuration '%s' not found" % config_name)
elif not config is None:
configurations.remove(config)
config = template_config.copy()
configurations.append(config)

if config is None:
return

config['miDebuggerPath'] = find_tool(env['GDB'])
dbgargs = "-x ${env:SMING_HOME}/Arch/%s/Components/gdbstub/gdbcmds" % env['SMING_ARCH']
if env['SMING_ARCH'] == 'Host':
args = []
args += env['CLI_TARGET_OPTIONS'].split()
args += ["--"]
args += env['HOST_PARAMETERS'].split()
config['args'] = args
else:
if not env.isWsl():
dbgargs += " -b %s" % env.resolve('${COM_SPEED_GDB}')
if config_name != wokwi_config_name:
config['miDebuggerServerAddress'] = env.resolve('${COM_PORT_GDB}')
if config_name != wokwi_config_name:
config['miDebuggerArgs'] = dbgargs
config['program'] = "${workspaceFolder}/" + env.resolve('${TARGET_OUT_0}')

save_json(launch, filename)

Expand All @@ -111,7 +121,6 @@ def update_wokwi():
extensions = template.copy()
save_json(extensions, filename)
return

extensions["recommendations"] = extensions["recommendations"] + list(set(template["recommendations"]) - set(extensions["recommendations"]))
save_json(extensions, filename)

Expand Down
18 changes: 18 additions & 0 deletions Tools/ide/vscode/template/wokwi/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Wokwi GDB",
"type": "cppdbg",
"request": "launch",
"program": "",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerServerAddress": "localhost:3333"
}
]
}
1 change: 1 addition & 0 deletions Tools/ide/vscode/template/wokwi/wokwi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
version=1
firmware='${FW_BASE}/app-merged.bin'
elf='${TARGET_OUT_0}'
gdbServerPort=3333
Binary file added docs/source/experimental/wokwi-debug.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 16 additions & 4 deletions docs/source/experimental/wokwi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ From the root directory of your application, run the following command to consol

make mergeflash SMING_ARCH=Esp32

Example Usage
=============
Usage
=====

Basic_Blink
-----------
Expand All @@ -43,7 +43,19 @@ Follow the commands below to get started::
Once the compilation is complete, open the folder in VS Code, install the recommended extensions, and either open the ``diagram.json`` file or press F1 and type ``Wokwi``.
From the options, choose to start the Wokwi simulator.

Debugging
=========

Running the Basic_Blink sample in the simulator enables you to debug it directly in VS Code.
Set a breakpoint in the ``init`` function in the Basic_Blink ``app/application.cpp`` file.
Press F1 and select "Start Simulator and Wait for Debugger." In the Launch configurations, choose "Wokwi GDB" and click the play button.
This initiates a new debugging session, allowing you to debug the code running in the simulator.

.. image:: wokwi-debug.jpg
:height: 192px

Diagram Editor
==============
The ``diagram.json`` file, which includes elements and their connections, can be edited on the Wokwi official website <https://wokwi.com/>__.
You can add new elements such as extra LEDs or servos. Ensure to copy the modified contents of the diagram.json from the website to your local environment.

The ``diagram.json`` file, which includes elements and their connections, can be edited on the `Wokwi official website <https://wokwi.com/>`__.
You can add new elements such as extra LEDs or servos. Ensure to copy the modified contents of the diagram.json from the website to your local environment.

0 comments on commit c17b942

Please sign in to comment.