Pico C/C++ Windows Tutorial 1

From Waveshare Wiki
Jump to: navigation, search

Environment Setting

Install arm gcc compiler

Download the webpage

Here I choose the same 2019-q4 version as the official one, and the operating system I use is Win10, so I choose:

gcc-arm-none-eabi-9-2019-q4-major-win32-sha2.exe

Windows 9-2019-q4.png
Note: Remember to add the path to the environment variable when installing. Pico C-C++ Windows Tutorial 102.png

Install Cmake

There is no special matter, it can be installed by default.

Install Visual Studio2019 (be sure to install 2019, different versions may cause it to fail to compile)

PicoC++ Windows Tutorial 1003.png
Install the corresponding components

  1. MSVC
  2. Windows 10 SDK (10.0.18362.0)
  3. C++ Cmake tool for windows
  4. Testing tool core features -Build Tools
  5. C++ AddressSanitizer(Experimental)

As shown
PicoC++ Windows Tutorial 1004.png

Install Python 3.7

Pico C++ Windows Tutorial 1005.png
Remember to add the path to the environment variable when installing (if it can be shown that the maximum PATH length can be removed, remove it).
Pico C++ Windows Tutorial 1006.png

  • If the build fails because make cannot find Python, you should add the symlink to the executable.

1. Type cmd in the Run window next to the Windows menu to open the developer command prompt window, right-click and select "Run as administrator" to open the window with administrator privileges.
2. Navigate to the python installation directory, where the default address is C:\Users\[username]\AppData\Local\Programs\Python\Python37
3. Then run the following command:
Pico C++ Windows Tutorial 1007.png

Install Git

The specific installation tutorial will be written separately. Here is just a simple text explanation:

  1. Allow git to use third-party tools (checkbox to allow Git to be used from third-party tools)
  2. Select "Checkout as is, commit as-is"
  3. Select "Use Windows' default console window"
  4. Select "Enable experimental support for pseudo consoles"

Configure PICO-SDK

Get PICO-SDK and PICO-EXAMPLES

  • In a file of the SDK and Examples you want to store, it is recommended that the path be short .
  • Open the git command line and enter the following command
git clone -b master https://github.com/raspberrypi/pico-sdk.git
git clone -b master https://github.com/raspberrypi/pico-examples.git

Initialize, grab and check out any nested submodules (must be run, otherwise it won't compile).

cd pico-sdk
git submodule update --init --recursive

Set PICO Path

  • Open Visual Studio 2019.
  • Tools -> Command Line -> Developer PowerShell Input.
setx PICO_SDK_PATH "[the path to store PICO-SDK]\pico-sdk"

C++ Windows Tutorial 1.png
Or use the official method (this method must use the relative path of the official storage folder).

setx PICO_SDK_PATH "..\..\pico-sdk"

Configure the Demo

Restart developer PowerShell input

cd [the path to store Pico-example]\pico-examples
mkdir build
cd build
cmake -G "NMake Makefiles" ..
nmake

C++ Windows Tutorial 2.png

Possible Problems

  • 'nmake' is not an internal or external command, nor is it a runnable program.
  1. Visual Studio 2019 does not install the correct corresponding components.
  2. Developer PowerShell not opening in Visual Studio 2019.
  • cl.exe appears in the error message.
  1. Visual Studio non-2019 version
  2. The component version selection is wrong, there are detailed instructions above
  • Cmake file ***
  1. Empty the build folder and recompile

Visual Studio Code Environment Setting

Install Visual Studio Code

https://visualstudio.microsoft.com/zh-hans/downloads/

Install the plugin

  1. Open the Visual Studio Code extension interface (shortcut Ctrl+Shift+X).
  2. Enter CMake Tools and install.
  3. F1 Enter open settings UI to open the settings UI interface.

C++ Windows Tutorial 3.png
4. Search for cmake.configureEnvironment.
5. Add item:
C++ Windows Tutorial 4.png

Item Value
PICO_SDK_PATH (the path to store PICO-SDK)\pico-sdk

Or (this method must use the relative path of the official storage folder)

Item Value
PICO_SDK_PATH ..\..\pico-sdk

Compile with Visual Studio Code

  • Note: Be sure to reopen Visual Studio Code using Visual Studio 2019's developer command line, as follows:
    • Open Visual Studio 2019
    • Tools -> Command Line -> Developer PowerShell Input:
code

C++ Windows Tutorial 1010.png

  1. Compile tool.2. Build 3. The projects to compile.

Open the pico-examples folder, select the compilation tool at the bottom as "GCC for arm-none-eabi", then select the project you want to compile, and finally click the build button.

  • CMake.exe reports an error or an error about CMakefile

1. Empty the build folder, restart Visual Studio Code and recompile.

  • Error about pioasm.exe.

2. The corresponding project may not be selected.

  • The compilation passed for the first time, and the error message "FindFirstFileExA" was reported later.

3. Search for cmake.generator in the settings and fill in:

NMake Makefiles

C++ Windows Tutorial 1011.png
Ctrl+S saves the settings, clears the build folder, restarts Visual Studio Code and recompiles.