Newer
Older
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
This repo contains Zephyr OS for Raspberry Pi Pico.
## Tools
Use **apt** to install the required dependencies:
```bash
sudo apt-get install --no-install-recommends -y git cmake ninja-build gperf tar
ccache dfu-util device-tree-compiler wget python3-dev python3-pip python3-setuptools python3-tk
python3-wheel xz-utils file make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 python3-venv
automake autoconf build-essential texinfo libtool libftdi-dev libusb-1.0-0-dev pkg-config
```
### West
> West (Zephyr’s meta-tool)
> The Zephyr project includes a swiss-army knife command line tool named west. West is developed in its own repository.
More info about [**WEST**][1]
Run the *initzephyr.sh* script found in the *zephyrproject* folder:
```bash
cd zephyrproject
./initzephyr.sh
```
This script will create a new python virtual environnement under *.venv* and install all the necessary packages. It will the
install *Zephyr* and it's dependencies.
### OpenOCD
OpenOCD is used to flash and debug the a *Zephyr* application. Clone the OpenOCD repo on your host machine
```bash
cd ~
git clone https://github.com/raspberrypi/openocd.git --branch rp2040-v0.12.0 --depth=1 --no-single-branch
```
Configure, build and install OCD
```bash
cd openocd
./bootstrap
./configure
make -j4
sudo make install
```
Check the OCD version
```bash
openocd --version
```
Output:
```bash
Open On-Chip Debugger 0.12.0-g4d87f6d (2024-01-08-14:31)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
```
Create a file with any name (ex. pico_openocd.rules) under /etc/udev/rules.d and put this line inside.
```bash
ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="000c", MODE="660", GROUP="plugdev", TAG+="uaccess"
```
To uninstall OCD run
```bash
sudo make uninstall
```
## Build a project
To build a project you can use **West** or the *build.sh* script.
> :warning: When using **West** directly you must activate the Python virtual environnement: ```source .venv/bin/activate```
The build script take the following arguments:
```bash
Build zephyr project
Syntax: ./build.sh [-b|c|d|f|h|] <args>
[ -b PATH ] Build project. Path to project folder
[ -c ] Clean
[ -d ] Launch debugger
[ -f ] Flash board
[ -h ] Help
```
We will build a simple *blinky* example:
```bash
./build.sh -b zephyr/samples/basic/blinky
```
The compilation output will be in the *build* folder.
## Hardware connection
![Pico debug connection](img/pico_debug_wiring.png)
## Flash the app
To flash the application code run the following:
```bash
./build.sh -f
```
You should now see the LED blinking.
## Debug
Install *gdb-multiarch*
```bash
sudo apt install gdb-multiarch
```
Create a *launch.json* configuration file in VSCode and copy the following:
```json
{
"version": "0.2.0",
"configurations": [
{
"name": "Pico Debug",
"type":"cortex-debug",
"cwd": "${workspaceRoot}",
"executable": "${workspaceFolder}/zephyrproject/build/zephyr/zephyr.elf",
"request": "launch",
"servertype": "external",
// This may need to be arm-none-eabi-gdb depending on your system
"gdbPath" : "gdb-multiarch",
// Connect to an already running OpenOCD instance
"gdbTarget": "localhost:3333",
"svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",
"runToEntryPoint":"main",
// Work around for stopping at main on restart
"postRestartCommands": [
"break main",
"continue"
]
}
]
}
```
Install the following extension in VSCode
- Cortex-Debug
- Cmake-tools
- C/C++
Run the board in debug mode:
```bash
./build.sh -d
```
Now run the debugger in VScode
[1]:https://docs.zephyrproject.org/latest/develop/west/index.html