Skip to content

Commit d2c8bf2

Browse files
committed
Debugging instruction
1 parent b7da9de commit d2c8bf2

File tree

1 file changed

+79
-9
lines changed

1 file changed

+79
-9
lines changed

README.md

+79-9
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ The latest image is available on [Docker Hub](https://hub.docker.com/repository/
1010
and can be used to run a container.
1111
The following commands show how to run the container using the Docker Hub image:
1212

13-
```
13+
```bash
1414
docker run -d -it --name pico-sdk --mount type=bind,source=${PWD},target=/home/dev lukstep/raspberry-pi-pico-sdk:latest
1515
docker exec -it pico-sdk /bin/sh
1616
```
1717

1818
The directory from which the `docker run` command was executed will be mounted in the container at `/home/dev`.
1919
After attaching to the SDK container, you can build your project by executing the following steps:
2020

21-
```
21+
```bash
2222
cd /home/dev
2323
mkdir build
2424
cd build
@@ -29,7 +29,7 @@ cmake .. && make -j4
2929

3030
To build your own SDK image, clone this repository and run the following commands:
3131

32-
```
32+
```bash
3333
cd raspberry-pi-pico-docker-sdk
3434
docker build . --tag pico-sdk
3535
docker run -d -it --name pico-sdk --mount type=bind,source=${PWD},target=/home/dev pico-sdk
@@ -50,15 +50,85 @@ Follow [this](https://code.visualstudio.com/docs/devcontainers/tutorial#_prerequ
5050

5151
#### Using the Dev Container for Pico IDE
5252

53-
- Clone [pico-dev-container](https://github.com/lukstep/pico-dev-container/tree/main) repository.
54-
- Open `pico-dev-container` folder in Visual Studio Code.
55-
- In VSCode, click the button in the bottom left corner of VSCode and select: Reopen in Container...
53+
- Clone [pico-dev-container](https://github.com/lukstep/pico-dev-container/tree/main) repository.
54+
- Open `pico-dev-container` folder in Visual Studio Code.
55+
- In VSCode, click the button in the bottom left corner of VSCode and select: Reopen in Container...
5656
![image-1](https://github.com/lukstep/raspberry-pi-pico-docker-sdk/assets/20487002/f1f06bca-cb0b-4c2d-bf4c-611ef004e70a)
57-
- Build the project.
58-
- Enjoy coding you Pico project with Intellisense.
57+
- Build the project.
58+
- Enjoy coding you Pico project with Intellisense.
5959
![image-1](https://github.com/lukstep/raspberry-pi-pico-docker-sdk/assets/20487002/ed367c06-aa9f-440a-9ca2-ddfbd7bdd266)
6060

61-
### Manual configuration of VSCode as Pico IDE (old)
61+
## Pico Memory Flashing and Debugging via Pico Probe and OpenOCD
62+
63+
To work efficiently on the project, we need the ability to upload firmware to the microcontroller, debug, and communicate through the serial port. The Raspberry Pi Pico board itself allows for software uploads, but this process is not very convenient or efficient for larger projects. The Pico Probe extends the capabilities of the Raspberry Pi Pico board to include fast firmware uploads to the microcontroller's memory, debugging via Serial Wire Debug (SWD), and it also serves as a USB UART converter.
64+
65+
The Debug Probe is compatible with the CMSIS-DAP interface, allowing OpenOCD to be used as the debugger server. By using OpenOCD, it becomes possible to communicate between development containers and the Debug Probe via TCP. On Linux, the Docker container can communicate directly through COM ports. However, on Mac and Windows, this is not possible because Docker runs in a dedicated virtual machine that does not have access to COM ports. Therefore, a solution with the OpenOCD server on the host machine was chosen.
66+
67+
The diagram below shows the environment topology:
68+
69+
1. Pico Probe is connected to the Raspberry Pi Pico board:
70+
71+
- SWD (Serial Wire Debug) interface for debugging.
72+
- UART (Universal Asynchronous Receiver/Transmitter) interface for serial communication.
73+
74+
2. The Pico Probe is connected to the PC via USB.
75+
76+
3. OpenOCD (Open On-Chip Debugger) runs on the PC and communicates with the Pico Probe.
77+
78+
4. The development container (devContainer) connects to OpenOCD via TCP.
79+
80+
![image-1](https://github.com/lukstep/raspberry-pi-pico-docker-sdk/assets/20487002/27bbb17d-5de4-4e41-9481-17a9e249e7b3)
81+
82+
### Instal required tools
83+
84+
To install OpenOCD on Linux, run the following command in a terminal:
85+
86+
```bash
87+
sudo apt install openocd
88+
```
89+
90+
To install OpenOCD on macOS, run the following command:
91+
92+
```bash
93+
brew install openocd
94+
```
95+
96+
### How to Use: Step-by-Step Instructions
97+
98+
1. Connect the Pico Probe to the Pico Board via SWD (1) and connect the Pico board UART to the UART-USB converter on the Pico Probe (2).
99+
100+
![image-1](https://github.com/lukstep/raspberry-pi-pico-docker-sdk/assets/20487002/92974093-0699-4299-b88c-b15633cee616)
101+
102+
2. Connect the Pico Probe and Pico Board to your PCś
103+
104+
3. Start the OpenOCD server in a new terminal by running the following command:
105+
106+
```bash
107+
sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c 'bindto 0.0.0.0' -c 'adapter speed 5000' -c 'init'
108+
```
109+
110+
4. Open the project in the Dev Container.
111+
112+
5. Make a debug build. Go to the CMake extension tab (1), click "Select Variant" (2), and choose "Debug" build (3). Start the build (4). If the build completes successfully, you can proceed to flashing the memory and debugging.
113+
114+
![image-1](https://github.com/lukstep/raspberry-pi-pico-docker-sdk/assets/20487002/262fb68b-8ef5-4ec2-a05e-8fd09597915d)
115+
116+
6. To start a debug session, first add a breakpoint in the main function. Next, go to the debugger extension tab (1), and click "Play" (2). The debug session starts by flashing the Pico's memory and restarting the microcontroller. After the reset, the flashed firmware starts and the program should stop at the breakpoint.
117+
118+
![image-1](https://github.com/lukstep/raspberry-pi-pico-docker-sdk/assets/20487002/598f6508-0b9a-44dc-b1f9-3a9eb391f0c3)
119+
120+
It is possible to flash the Pico's memory without starting a debugger session. To do that, run the preprogrammed tasks.
121+
122+
- Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac) to open the Command Palette.
123+
- Type Run Task into the Command Palette and press Enter.
124+
- Select task `Flash`.
125+
126+
## Manual configuration of VSCode as Pico IDE (old)
62127

63128
Refer [here](docs/vscode_manual_setup.md) for step-by-step instruction
64129

130+
## References
131+
132+
[Raspberry Pi Debug Probe](https://www.raspberrypi.com/documentation/microcontrollers/debug-probe.html)
133+
134+
[OpenOCD project page](https://openocd.org)

0 commit comments

Comments
 (0)