-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tutorial for simulation via vscode
- Loading branch information
Showing
4 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
# Setting up a Prusa MK4/Mini/XL development and simulation system in Linux Ubuntu 22.03.4 LTS | ||
|
||
## Install Visual Studio Code | ||
1. go to https://code.visualstudio.com/docs/setup/linux and download the .deb package | ||
```bash | ||
wget https://vscode.download.prss.microsoft.com/dbazure/download/stable/0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2/code_1.85.1-1702462158_amd64.deb | ||
``` | ||
|
||
2. ```bash | ||
sudo apt install ./code_1.85.1-1702462158_amd64.deb -y | ||
``` | ||
|
||
## Install compilation tools | ||
1. ```bash | ||
sudo apt install build-essential pre-commit git libncurses5-dev libusb-1.0-0-dev pkg-config libtool freeglut3-dev libglew-dev python-is-python3 python3-venv -y | ||
``` | ||
2. ```bash | ||
git clone https://github.com/Kitware/CMake | ||
cd CMake | ||
mkdir build && cd build | ||
../bootstrap && make -j && sudo make install | ||
cd .. | ||
``` | ||
3. ```bash | ||
sudo ln -s /usr/lib/x86_64-linux-gnu/libtinfo.so.6 /usr/lib/x86_64-linux-gnu/libtinfo.so.5 | ||
sudo ln -s /usr/lib/x86_64-linux-gnu/libncurses.so.6 /usr/lib/x86_64-linux-gnu/libncurses.so.5 | ||
``` | ||
|
||
## Setup openocd | ||
1. ```bash | ||
git clone https://github.com/ntfreak/openocd.git | ||
``` | ||
2. ```bash | ||
sudo apt install libjaylink-dev -y | ||
``` | ||
3. ```bash | ||
cd openocd | ||
./bootstrap | ||
``` | ||
4. ```bash | ||
./configure --enable-stlink --enable-jlink | ||
``` | ||
5. ```bash | ||
make -j && sudo make install | ||
cd .. | ||
``` | ||
|
||
## Setup gdb-multiarch | ||
1. ```bash | ||
sudo apt install gdb-multiarch -y | ||
``` | ||
|
||
## Get the prusa xbuddy source code | ||
1. ```bash | ||
git clone https://github.com/prusa3d/Prusa-Firmware-Buddy | ||
``` | ||
2. ```bash | ||
cd Prusa-Firmware-Buddy | ||
```bash | ||
3. ```bash | ||
python -m venv .venv | ||
``` | ||
4. ```bash | ||
pre-commit | ||
``` | ||
5. ```bash | ||
python ./utils/build.py --preset=mk4 --build-type=debug | ||
``` (replace mk4 here with mini or xl if needed, this will download the other requirements) | ||
|
||
|
||
## Start and setup Visual Studio Code | ||
1. Start visual studio code ("code" in shell) | ||
2. Press Ctrl-Shift-X to open up the extensions menu | ||
3. Enter in the search bar and install: | ||
"Cortex Debug" | ||
"Cortex Debug: Device Support Pack - STM32F4" | ||
"clangd" | ||
"Code Spell Checker" | ||
"CMake Tools" | ||
"C/C++" | ||
"C/C++ Extension Pack" | ||
"Python" | ||
"Output Colorizer" | ||
|
||
4. Press Ctrl-Shift-P and enter "Preferences: Open User Settings (JSON)" and use the following snippet : | ||
``` { | ||
"terminal.integrated.env.linux": { | ||
"GTK_PATH": "" | ||
}, | ||
} | ||
``` | ||
|
||
## Setting up black-magic-probe / st-link | ||
1. ```bash | ||
echo 'SUBSYSTEM=="usb",GROUP="users",MODE="0666"' | sudo tee -a /etc/udev/rules.d/90-usbpermission.rules | ||
``` | ||
2. ```bash | ||
sudo udevadm control --reload-rules | ||
``` | ||
3. In VS Code, press Ctrl-Shift-P and enter "Preferences: Open User Settings (JSON)" and add the following after the commata: | ||
``` | ||
"cortex-debug.openocdPath":"/usr/local/bin/openocd" | ||
``` | ||
### After the project folder has been opened, in .vscode/launch.json, add this: | ||
``` | ||
{ | ||
"name": "Black Magic Probe", | ||
"type": "cppdbg", | ||
"request": "launch", | ||
"preLaunchTask": "CMake: build", | ||
"cwd": "${workspaceRoot}", | ||
"MIMode": "gdb", | ||
"targetArchitecture": "arm", | ||
"logging": { | ||
"engineLogging": true | ||
}, | ||
"program": "${workspaceRoot}/build-vscode-buddy/firmware", | ||
"miDebuggerPath": "arm-none-eabi-gdb", | ||
//"miDebuggerServerAddress": "/dev/ttyACM0", | ||
"customLaunchSetupCommands": [ | ||
{ | ||
"text": "cd ${workspaceRoot}" | ||
}, | ||
{ | ||
"text": "target extended-remote /dev/ttyACM0" /* replace with your COM or /dev/ttyX */ | ||
}, | ||
{ | ||
"text": "monitor swdp_scan" | ||
}, | ||
{ | ||
"text": "attach 1" | ||
}, | ||
{ | ||
"text": "file ${workspaceRoot}/build-vscode-buddy/firmware" | ||
}, | ||
{ | ||
"text": "load" | ||
}, | ||
{ | ||
"text": "cd ${workspaceRoot}" /* set bath back so VScode can find source files */ | ||
}, | ||
{ | ||
"text": "set mem inaccessible-by-default off" | ||
}, | ||
{ | ||
"text": "break main" | ||
} | ||
], | ||
"serverLaunchTimeout": 10000, | ||
"windows": { | ||
"miDebuggerPath": "arm-none-eabi-gdb.exe" | ||
} | ||
} | ||
``` | ||
|
||
## Opening the project in VS Code | ||
|
||
1. Start VS Code | ||
2. Click the folder icon on the left top sidemenu : Explorer | ||
3. Open Folder -> Double click on "Prusa-Firmware-Buddy" Folder and press open (top right) | ||
4. Select "Yes, I trust the authors" | ||
4. In the .vscode folder, double click on launch.json and add: | ||
``` | ||
"showDevDebugOutput": "raw", | ||
``` | ||
5. In utils/bootstrap.py locate the dependencies table, for mk4 the field 'bootloader-mk4' has to be copied as 'bootloader-mk4-027c' and for | ||
xl the field "bootloader-xl" has to be copied to "bootloader-xl-050". | ||
Example: | ||
``` | ||
'bootloader-mk4': { | ||
'version': '2.3.0', | ||
'url': 'https://prusa-buddy-firmware-dependencies.s3.eu-central-1.amazonaws.com/bootloader-mk4-2.3.0-A98CD828-A5FA-48C6-BE76-3BA986BC2F0C.zip', | ||
}, | ||
'bootloader-mk4-027c': { | ||
'version': '2.3.0', | ||
'url': 'https://prusa-buddy-firmware-dependencies.s3.eu-central-1.amazonaws.com/bootloader-mk4-2.3.0-A98CD828-A5FA-48C6-BE76-3BA986BC2F0C.zip', | ||
}, | ||
``` | ||
|
||
6. Click on the pyramid symbol (CMake), then over over the mouse on "Configure" project status, click on "[No Configure Preset Selected]", then on the pen symbol and select your Printer firmware, for example "mk4_debug_noboot". | ||
|
||
![cmake_preset](/home/bjk/Prusa-Firmware-Buddy/doc/editor/vscode_tutorial/cmake_preset.png) | ||
|
||
7. Hover over the "Build" project status and then click on the Build icon. Wait for the build to finish. | ||
|
||
![cmake_build](/home/bjk/Prusa-Firmware-Buddy/doc/editor/vscode_tutorial/build.png) | ||
|
||
|
||
8. Click on the Debug Symbol (sidebar, play icon) and on top, click on the drag drop window of run and debug, select "Launch simulator". Press F5. | ||
You can now use the simulator by clicking into it and using the cursor and enter keys on the keyboard to navigate. Also PrusaLink should be accessible via http://127.0.0.1:3333 in the host browser. Enjoy ! | ||
![](/home/bjk/Prusa-Firmware-Buddy/doc/editor/vscode_tutorial/simulator.jpeg) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.