这是pico板子的两个点灯实验,并非自己写的代码,仅是作为临摹的记录
pico的micropython使用
工具:Thonny, Python IDE for beginners 设置解释器为micro python (pico), 选择好串口,按住按键插入usb,电脑会多出来一个盘
之后把rp2-pico-20210418-v1.15.uf2 复制进去,自动重启后连接上。 此时thonny内输入代码:
import machine
import utime
led_onboard = machine.Pin(25, machine.Pin.OUT)
while True:
led_onboard.value(1)
utime.sleep_ms(1000)
led_onboard.value(0)
utime.sleep_ms(1000)
点击运行当前脚本 ,板子上的灯就会闪烁了。
由于在公司做的项目都是和freeRTOS有关,而且看到这个RPI-pico是Arm Cortex-M0 + 的,是不是也可以在RPI-pico上运行起轻量操作系统呢?答案是肯定的👇
pico跑freeRTOS
出于好奇搜了一下,果然有有意思的项目: Raspberry Pi Pico Gets supports for Rust, RT-Thread OS and FreeRTOS 上面这个链接中提到了有人在用pico树莓派跑freeRTOS PicoCPP/RPI-pico-FreeRTOS (github.com)
虽然这个项目只有60个star,但是被网站引用了,看来是可行的
搞起来!
下载代码
git clone --recursive git@github.com:PicoCPP/RPI-pico-FreeRTOS.git
看一下代码。main.cpp 中进行了task创建并开启调度,他创建了这一个task:
static pico_cpp::GPIO_Pin ledPin(25,pico_cpp::PinType::Output);
void vTaskCode( void * pvParameters )
{
/* The parameter value is expected to be 1 as 1 is passed in the
pvParameters value in the call to xTaskCreate() below.
configASSERT( ( ( uint32_t ) pvParameters ) == 1 );
*/
for( ;; )
{
ledPin.set_high();
vTaskDelay(1000);
ledPin.set_low();
vTaskDelay(1000);
}
}
环境: cmake : 我用的cmake-3.21.0-windows-x86_64.msi ,最好版本>3.12 GNU Arm Embedded Toolchain: 我用的10 2020-q4-major python:python3的环境即可,我是python3.7.9 把上面两个工具的bin文件目录加到系统path中,python目录也加入path内
由于我安装了Visual Studio,已经有MSVC环境,在Windows上,默认情况下,CMake生成MSVC解决方案。所以要在cmake时指定使用的是Unix平台,这样可以生成Makefile。即使用-G"Unix Makefiles" (如果没有装Visual Studio的话不用加) 输入下面命令:
$ mkdir build
$ cd build
$ cmake .. -G"Unix Makefiles"
可以打印出以下log,表示cmake完成:
D:\work\pico\RPI-pico-FreeRTOS>mkdir build
D:\work\pico\RPI-pico-FreeRTOS>cd build
D:\work\pico\RPI-pico-FreeRTOS\build>cmake .. -G"Unix Makefiles"
PICO_SDK_PATH is D:/work/pico/RPI-pico-FreeRTOS/pico-sdk
Defaulting PICO_PLATFORM to rp2040 since not specified.
Defaulting PICO platform compiler to pico_arm_gcc since not specified.
-- Defaulting build type to 'Release' since not specified.
PICO compiler is pico_arm_gcc
-- The C compiler identification is GNU 10.2.1
-- The CXX compiler identification is GNU 10.2.1
-- The ASM compiler identification is GNU
-- Found assembler: C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2020-q4-major/bin/arm-none-eabi-gcc.exe
Defaulting PICO target board to pico since not specified.
Using board configuration from D:/work/pico/RPI-pico-FreeRTOS/pico-sdk/src/boards/include/boards/pico.h
-- Found Python3: C:/python37/python.exe (found version "3.7.9") found components: Interpreter
TinyUSB available at D:/work/pico/RPI-pico-FreeRTOS/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040; adding USB support.
-- Configuring done
-- Generating done
-- Build files have been written to: D:/work/pico/RPI-pico-FreeRTOS/build
D:\work\pico\RPI-pico-FreeRTOS\build>
再输入
$ make
打印出以下log(已省略),编译完成,并且编译出来的elf文件已经转换成uf2格式文件:
D:\work\pico\RPI-pico-FreeRTOS\build>make
Scanning dependencies of target bs2_default
[ 1%] Building ASM object pico-sdk/src/rp2_common/boot_stage2/CMakeFiles/bs2_default.dir/compile_time_choice.S.obj
[ 2%] Linking ASM executable bs2_default.elf
[ 2%] Built target bs2_default
。
。
。
[ 98%] Building C object CMakeFiles/hello_world.dir/pico-sdk/src/rp2_common/pico_stdio_uart/stdio_uart.c.obj
[100%] Linking CXX executable hello_world.elf
text data bss dec hex filename
19480 28 52832 72340 11a94 hello_world.elf
[100%] Built target hello_world
D:\work\pico\RPI-pico-FreeRTOS\build>
再按住树莓派pico上的按钮连接电脑,把uf2文件拖进去,就会看到程序已经在跑了,可以1秒闪烁一次,看来系统tick也是在工作的:
|