This article is a quick setup guide to deploy Raspberry Pi Pico (RP2040) SDK and FT2232H for Windows 10 systems.
DetailsThis article is a quick and small guide to deploy the Raspberry Pi Pico (RP2040) SDK and the FT2232H into Windows 10 systems. Basically, the SDK is mainly built on Linux and there will be significant amount of effort to make it run on Windows 10.
You will need:
- Windows 10 with Linux Subsystem
- Visual Studio Code
- Cygwin
- Raspberry Pi version of OpenOCD
- FT2232H board (can be obtained through AliExpress or somewhere similar)
- Build Tools for VS2019
- Git
- GDB-multiarch
- Some jumpers, 470ohm resistor and a small breadboard
FT2232H board:
Step 1
As usual, from the manual (page 34 onwards!):
https://datasheets.raspberrypi.org/pico/getting_started_with_pico.pdf
Step 2
Install VS Code and the Build Tools for VS2019.
Then, launch VS Code from the Visual Studio 2019 Developer Command Prompt.
Launching it from elsewhere wouldn't work at all during the build stages!
Step 3
After launching VS Code there, set the path so that the build tools can locate the SDK:
setx PICO_SDK_PATH "..\..\pico-sdk"
Step 4
Install this extension, and then go to the Settings in the VS Code:
Click on the "Gear" button on the bottom left of the screen:
Then click on the "Settings":
Over there in the "Settings", click on Extensions->CMake Tools configuration and then scroll down until you see "Cmake: Generator". Fill it in with "NMake Makefiles":
Also, you need to set the path for the SDK inside the config as well:
Step 5
To start off with a simple code, we get the project generator through this git:
git clone https://github.com/raspberrypi/pico-project-generator.git
We may need to modify a bit on that script - it expects the SDK to be entirely inside the project folder. It's easier to have just one SDK for all the other Pico projects.
def CheckSDKPath(gui):
sdkPath = os.getenv('PICO_SDK_PATH')
if sdkPath == None:
m = 'Unabled to locate the Pico SDK, PICO_SDK_PATH is not set'
if (gui):
RunWarning(m)
else:
print(m)
elif not os.path.isdir(sdkPath):
m = 'Unabled to locate the Pico SDK, PICO_SDK_PATH does not point to a directory'
if (gui):
RunWarning(m)
else:
print(m)
sdkPath = None
sdkPath = "X:/pico-sdk/" # return this sdkPath instead!
return sdkPath
Then run the script:
python pico_project.py --gui
When you are inside the generator, fill in the "Project Name", "Location" and checkbox the "Create VSCode Project":
Click on OK, and it'll generate the thing for you.
Still inside VS Code, "Open Folder" this folder that you created from the generator.
When you open, it prompts you for what kind of compiler you need for this project. Select "GCC for arm-none-eabi".
In the main C file type in this:
#include <stdio.h>
#include "pico/stdlib.h"
int main()
{
stdio_init_all();
const uint LED_PIN = 25;
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
printf("Hello World Pico!\n");
while(1) {
gpio_put(LED_PIN,1);
sleep_ms(250);
gpio_put(LED_PIN,0);
sleep_ms(250);
}
return 0;
}
Step 6
Once all the project files are configured, just compile by hitting the F7 button. It'll take a few minutes depending on the size of the project.
If it is successful you will see "Build finished with exit code 0". On this one the project name there is "Hello" so yours will be different.
build] TinyUSB available at E:/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040; adding USB support.
[build] Compiling TinyUSB with CFG_TUSB_DEBUG=1
[build] -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
[build] ELF2UF2 will need to be built
[build] -- Configuring done
[build] -- Generating done
[build] -- Build files have been written to: E:/pico-projects-2021/hello/build
[build] [ 1%] Performing build step for 'ELF2UF2Build'
[build]
[build] Microsoft (R) Program Maintenance Utility Version 14.28.29333.0
[build] Copyright (C) Microsoft Corporation. All rights reserved.
[build]
[build] [100%] Built target elf2uf2
[build] [ 2%] No install step for 'ELF2UF2Build'
[build] [ 3%] Completed 'ELF2UF2Build'
[build] [ 10%] Built target ELF2UF2Build
[build] [ 13%] Built target bs2_default
[build] [ 14%] Built target bs2_default_bin
[build] [ 15%] Built target bs2_default_padded_checksummed_asm
[build] [100%] Built target hello
[build] Build finished with exit code 0
Step 7
Caution: From this OpenOCD tutorial onwards, this one is extremely tricky and some steps are bound to fail easily! Proceed with caution!
Once you done compiling, it'll give you the ELF file for you to do debug on the Pico. Rather than you just yank out the Pico and reconnecting it (with pressing BootSel) to reprogram it multiple times, you just load it through OpenOCD and the three debugging pins on the Pico.
From the manual Getting Started with Pico, clone this:
git clone https://github.com/raspberrypi/openocd.git --recursive --branch rp2040 --depth=1
Then install Cygwin according to this tutorial :https://mindchasers.com/dev/openocd-darsena-windows.
When you are done installing Cygwin, go to the OpenOCD directory and do this:
./bootstrap
and then after doing all the stuff needs doing, issue this:
./configure --enable-ftdi
Some more time later, after finishing the configuration, make, and then make install:
make -j4
make install
Step 8
Unfortunately, plain GDB doesn't run on ARM devices like Pico. It needs the GDB multiarch.
Sadly, I couldn't grab GDB-multiarch from Cygwin, so I had to resort to using the Linux Subsystem on Windows 10.
sudo apt install gdb-multiarch
Step 9
1.) Plug in the FT2232H board.
2.) Get Zadig. Switch the drivers to WinUSB (Options->List All Devices) :
[ If you couldn't see the Dual RS232-HS but the one with "Interface 0" and "Interface 1", pick the one with Interface 0 and switch it ]
Step 10
As the title said, connect the Pico to the FT2232 board. The blue board is the Adafruit version - but the AD0, AD1 and AD2 are the same. Make sure you ground the pin on the center (the three pins on the bottom of the Pico) too.
Source: https://github.com/raspberrypi/openocd/issues/11
Step 11
[OpenOCD] Modify the "ft232h-module-swd.cfg"
The green version is using PID 0x6010, so you need to change this one as well. Or, make a backup copy of it and rename it something else:
ftdi_vid_pid 0x0403 0x6010
and add that one:
adapter speed 100
Step 12
[OpenOCD] Run OpenOCD with the config files in Cygwin.
Get back to Cygwin. Run it. Like this:
openocd -f interface/raspberrypi-swd.cfg -f target/rp2040.cfg
The output should look like this:
$ openocd -f tcl/interface/ftdi/ft232h-module-swd.cfg -f tcl/target/rp2040.cfg
Open On-Chip Debugger 0.10.0+dev-g7c96119-dirty (2021-01-25-21:56)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : FTDI SWD mode enabled
adapter speed: 400 kHz
Info : Hardware thread awareness created
Info : Hardware thread awareness created
Info : RP2040 Flash Bank Command
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 400 kHz
Info : SWD DPIDR 0x0bc12477
Info : SWD DLPIDR 0x00000001
Info : SWD DPIDR 0x0bc12477
Info : SWD DLPIDR 0x10000001
Info : rp2040.core0: hardware has 4 breakpoints, 2 watchpoints
Info : rp2040.core1: hardware has 4 breakpoints, 2 watchpoints
Info : starting gdb server for rp2040.core0 on 3333
Info : Listening on port 3333 for gdb connections
It is now waiting for GDB connection. You will have to switch back to the Linux Subsystem to start the GDB-multiarch.
Step 13
[OpenOCD] Go back to Linux Subsystem -> load program!
Go to your project build folder (example MyProject/build) and run GDB-multiarch:
gdb-multiarch myProject.elf
Then when you can log into it, enter this:
target extended-remote localhost:3333
You will see this:
GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
warning: No executable has been specified and target does not support
determining executable automatically. Try using the "file" command.
0x10000e98 in ?? ()
Reading symbols from hello.elf...done.
__wfe () at E:\pico-sdk\src\rp2_common\hardware_sync\include/hardware/sync.h:95
95 E:\pico-sdk\src\rp2_common\hardware_sync\include/hardware/sync.h: No such file or directory.
(gdb)
Load a program, just send "load" and it'll do the magic for you!
(gdb) load
Loading section .boot2, size 0x100 lma 0x10000000
Loading section .text, size 0x7018 lma 0x10000100
Loading section .rodata, size 0x12ac lma 0x10007118
Loading section .binary_info, size 0x20 lma 0x100083c4
Loading section .data, size 0xb04 lma 0x100083e4
Start address 0x10000104, load size 36584
Transfer rate: 13 KB/sec, 6097 bytes/write.
(gdb)
Send "c" to let it run! You can see the LED blinking! :D
Step 14
[OpenOCD] One fast tip - automatic connect to localhost:3333
If you are bored with "target remote localhost:3333" everytime you start the GDB, you can create the.gdbinit file inside the build folder:
target extended-remote localhost:3333
On the Linux Subsystem, just run GDB with these parameters:
gdb-multiarch -iex "set auto-load safe-path /" myProject.elf
Comments
Please log in or sign up to comment.