raspberry pi pico资料
https://datasheets.raspberrypi.o ... arted-with-pico.pdf
vscode设置:
cmake tools插件cmake:build environment--> add item
item: PICO_SDK_PATH
value: ../.../pico-sdk
Cmake: Generator(这里填自己对应平台的) - “Unix Makefiles” for Linux and macOS
- “NMake Makefiles” for Windows (if you built everything with Build Tools for Visual Studio)
- “MinGW Makefiles” for Windows (if you built everything with MinGW)
安装:
添加下面代码到.zshrc文件里
- export PICO_SDK_PATH=你的SDK路径
复制代码 执行source .zshrc生效,确认是否生效echo $PICO_SDK_PATH看输出是否跟你设置的一致.
sample:
在你project目录下新建两个文件
main.c
- #include <stdio.h>
- #include "pico/stdlib.h"
- int main() {
- const uint led_pin = 25;
- // Initialize LED pin
- gpio_init(led_pin);
- gpio_set_dir(led_pin, GPIO_OUT);
- // Initialize chosen serial port
- stdio_init_all();
- // Loop forever
- while (true) {
- // Blink LED
- printf("Blinking!\r\n");
- gpio_put(led_pin, true);
- sleep_ms(100);
- gpio_put(led_pin, false);
- sleep_ms(100);
- }
- }
复制代码 CMakeLists.txt
- # Set minimum required version of CMake
- cmake_minimum_required(VERSION 3.12)
- # Include build functions from Pico SDK
- include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
- # Set name of project (as PROJECT_NAME) and C/C++ standards
- project(blink C CXX ASM)
- set(CMAKE_C_STANDARD 11)
- set(CMAKE_CXX_STANDARD 17)
- # Creates a pico-sdk subdirectory in our project for the libraries
- pico_sdk_init()
- # Tell CMake where to find the executable source file
- add_executable(${PROJECT_NAME}
- main.c
- )
- # Create map/bin/hex/uf2 files
- pico_add_extra_outputs(${PROJECT_NAME})
- # Link to pico_stdlib (gpio, time, etc. functions)
- target_link_libraries(${PROJECT_NAME}
- pico_stdlib
- )
- # Enable usb output, disable uart output
- pico_enable_stdio_usb(${PROJECT_NAME} 1)
- pico_enable_stdio_uart(${PROJECT_NAME} 0)
复制代码 新建build文件夹
- mkdir build && cd build
- cmake -S project路径
- make
复制代码 以上命令完成没有报错就可以,接下来接着pico的bootsel键然后再把pico接到电脑,在build文件夹里找到你刚build的*.uf2文件,把这个文件拖到pico的盘里面就会自动运行.
pico在macos的端口通常是
常见报错
- CMake Error at CMakeLists.txt:13 (pico_sdk_init):
- Unknown CMake command "pico_sdk_init".
复制代码 通常都是PICO_SDK_PATH问题
|