University of Pennsylvania, ESE 5190: Intro to Embedded Systems, Lab 2A
Sizhe Ma
[email protected]
Tested on: Thinkpad X1, Windows 10 Pro, Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz 2.11 GHz
In this lab, firstly we need to set up laptop/PC for RP2040 development using the official C/C++ SDK to compile and run example code on our board.
If you are using Windows machine, you can follow the following steps to completly set up the environment. the Raspberry Pi Pico “getting started guide” includes the whole process of setups. See Section 9.2. Building on MS Windows or the steps below for the specific instruction.
Even though Chapter2. The SDK also includes the instruction to download SDK and examples, it does not include the instruction for installing extra tools/path to the SDK/cmake setup. See 9.2 for the full instruction.
Since we use Windows OS, there are several extra tools/software we need to install first:
In the link above, we need to download the file ended with arm-none-eabi.exe
After downloading the .exe file, we select English/English language, click "next" to continue, click "I Agree" to agree the license and finally click "install" to install the software.
After installing the Toolchain, remember to check "Add path to environment variable" before finishing installing. If not, our Developer Command Prompt will not detect arm none when we setup cmake. (I will mention it later in Command Line setup section)
In the link above, we need to download the file with windows-x86_64.msi
After downloading the .exe file, we click "next" to continue, check "I accept the terems in the Licence Agreement" to agree the license, check "Add CMakee to the system PATH for all users" and "next", then finally install the software.
For the Developer Command Prompt installation, notice that we need to download "Visual Studio 2022" instead of "VS Code"
We need to go down to the bottom and download "Build Tools for Visual Studio 2022"
Make sure you select "Desktop development with C++" and check options on the right in "Optional" list as shown below.
For the Python installing, make sure you download Latest Python 3 Release - Python 3.10.7, then click "Install Now."
In the link above, we need to click "64-bit Git for Windows Setup."
After downloading Git-2.38.0-64-bit.exe, we follow the instruction and download Git.
When installing Git, make sure we select "Notepad as Git's default editor", "Git from the command line as well as third-party software", "Checkout as is, commit as-is", "Use Windows' default console window" and finally "Enable experimental support for pseudo consoles".
Congrats! You have installed all extra tools. Then you can install C SDK in Developer Command Prompt
In this section, we will download SDK and examples through Developer Command Prompt. The Raspberry Pi Pico “getting started guide”, section 9.2.2 includes extremely helpful guide for this part. It is very easy for you to follow each steps and get SDK.
If you mistakenly downloaded VS code and followed the instruction in Chapter 2 to download SDK and examples, you can skip this part and jump to the section "Building "Hello World" from the Command Line." But before you follow the next section, I highly recommend you to download and use Visual Studio 2022 instead of VS code terminal. Using developer Command Prompt in Visual Studio 2022 is easier for you to set the path to the SDK and build files for the "hello_usb.c" in next step.
The started guide does not include the guide to create files named pico and Downloads, here is the instruction:
C:\Users> mkdir pico
C:\Users> cd pico
C:\Users\pico> mkdir Downloads
C:\Users\pico> cd Downloads
Then you can follow the guide to get the SDK and examples
Then you can set the path to the SDK as follows in a Developer Command Prompt window:
C:\Users\pico\Downloads> setx PICO_SDK_PATH "..\..\pico-sdk"
After entering this command line, the command window will prompt a hint information which indicating that the setup for the environment variable is completed. Now you need to remember to close your current Command Prompt Window and and open a second Developer Command Prompt window where this environment variable will now be set correctly before proceeding.
Then enter the command lines below: ''' C:\Users\pico\Downloads> cd pico-examples C:\Users\pico\Downloads\pico-examples> mkdir build C:\Users\pico\Downloads\pico-examples> cd build C:\Users\pico\Downloads\pico-examples\build> cmake -G "NMake Makefiles" .. C:\Users\pico\Downloads\pico-examples\build> nmake '''
After entering "cmake -G "NMake Makefiles" ..", if the command window prompt a hint information which indicating that there is an error "cannot find arm none". There are several reasons:
- you did not close your current Command Prompt Window and and open a second Developer Command Prompt after setting a path
- you did not check "Add path to environment variable" before finishing installing Toolchain. If not, our Developer Command Prompt will not detect arm none when we setup cmake.
- I initially used VS code terminal and it did not work. If you also use VS code terminal, try to download and use Developer Command Prompt in Visual Studio 2022.
If you successfully run the last two command lines, just wait until the building process is completed.
Then you can find hello_usb.uf2 file in hello_world/usb directories inside your build directory. (pico-examples > build > hello_world > usb)
Since there is no screen on Windows OS, we need to download PuTTY to see the result printed in the serial console. Last version of PuTTY can be downloaded here.
Before running PuTTY, we neeed to want to find out which serial port your board is using. When you plug your board in to USB on your computer, it connects to a serial port.
You'll use Windows Device Manager to determine which port the board is using. The easiest way to determine which port the board is using is to first check without the board plugged in. Open Device Manager. Click on Ports (COM & LPT). You should find something already in that list with (COM#) after it where # is a number.
Now plug in your board. The Device Manager list will refresh and a new item will appear under Ports (COM & LPT). You'll find a different (COM#) after this item in the list.
Notice the COM number when the list refreshes, sometimes it is not COM3.
Then after you connect your board to the USB port and run PuTTY:
- choose the button next to Serial under Connection type.
- enter the serial port you found that your board is using in the box under Serial line.
- enter 115200 in the box under Speed.
After click open, you can see the result printed in the serial console.