Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
树莓派Pico
树莓派 PICO pio 使用
发布于 2023-10-18 13:26:54 浏览:323
订阅该版
[tocm] # 树莓派 PICO pio 使用 在树莓派 Pico 小小的板子上总是能让我们发现一些惊喜。其所使用的RP2040芯片还具备8个可编程I/O(PIO)状态机,用于自定义外围设备,与 FPGA 类似,开发者可以灵活的使用 PIO 自定义功能。可编程I/O(PIO)是为 RP2040 开发的一种新型硬件,可以通过 PIO 创建新类型的(或附加)硬件接口。通过使用 PIO ,可以模拟更多,更丰富,更快的硬件接口,有助于提升性能和扩展性。 与 PIO 相比,FPGA 往往更加昂贵,而且需要使用其他的编程模式编写程序。但 PIO 仅仅只需要通过汇编语言就可以实现,开发者不需要去适应 FPGA 那种编程模式即可很快的实现自定义硬件接口。 ## PIO 一个简单的 demo: 主要需要用到一个汇编实现的pio文件,一些C文件,和Cmake文件,实现串口打印 hello **pio文件:** ```assembly .program hello ; Repeatedly get one word of data from the TX FIFO, stalling when the FIFO is ; empty. Write the least significant bit to the OUT pin group. loop: pull out pins, 1 jmp loop % c-sdk { static inline void hello_program_init(PIO pio, uint sm, uint offset, uint pin) { pio_sm_config c = hello_program_get_default_config(offset); // Map the state machine's OUT pin group to one pin, namely the `pin` // parameter to this function. sm_config_set_out_pins(&c, pin, 1); // Set this pin's GPIO function (connect PIO to the pad) pio_gpio_init(pio, pin); // Set the pin direction to output at the PIO pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true); // Load our configuration, and jump to the start of the program pio_sm_init(pio, sm, offset, &c); // Set the state machine running pio_sm_set_enabled(pio, sm, true); } %} ``` 其流程主要如下: 1. 将程序加载到PIO的指令存储器中; 2. 设置PIO状态机以运行程序; 3. 在状态机运行时与状态机交互。 **C文件:** ```c #include "pico/stdlib.h" #include "hardware/pio.h" // Our assembled program: #include "hello.pio.h" int main() { #ifndef PICO_DEFAULT_LED_PIN #warning pio/hello_pio example requires a board with a regular LED #else // Choose which PIO instance to use (there are two instances) PIO pio = pio0; // Our assembled program needs to be loaded into this PIO's instruction // memory. This SDK function will find a location (offset) in the // instruction memory where there is enough space for our program. We need // to remember this location! uint offset = pio_add_program(pio, &hello_program); // Find a free state machine on our chosen PIO (erroring if there are // none). Configure it to run our program, and start it, using the // helper function we included in our .pio file. uint sm = pio_claim_unused_sm(pio, true); hello_program_init(pio, sm, offset, PICO_DEFAULT_LED_PIN); // The state machine is now running. Any value we push to its TX FIFO will // appear on the LED pin. while (true) { // Blink pio_sm_put_blocking(pio, sm, 1); sleep_ms(500); // Blonk pio_sm_put_blocking(pio, sm, 0); sleep_ms(500); } #endif } ``` 我们会发现其中调用了 "hello.pio.h" 头文件,其与之前的 pio 文件相关,但 pio 文件并不能在 c 文件中直接调用,于是就需要 Cmake 文件将 pio 文件和 c 文件联系到一起,并构建一个可执行文件。 **Cmake文件** ```cmake add_executable(hello_pio) pico_generate_pio_header(hello_pio ${CMAKE_CURRENT_LIST_DIR}/hello.pio) target_sources(hello_pio PRIVATE hello.c) target_link_libraries(hello_pio PRIVATE pico_stdlib hardware_pio ) pico_add_extra_outputs(hello_pio) # add url via pico_set_program_url example_auto_set_url(hello_pio) ``` 其中的 `pico_generate_pio_header` 非常重要,其将之前用汇编语言写的 pio 文件生成为一个 .h 头文件,以供 c 文件调用。 通过这写文件和 pico 官方提供的 sdk 就可以构建一个串口打印 hello 的程序了。 ## 其他 我是在移植 pico-w 板载的 Wi-Fi 功能时注意到这一功能的,因为需要使用到 `cyw43_bus_pio_spi.pio` 。但是由于 RT-Thread 这边使用的是 Scons,于是我就先利用 pico-examples 的 cmake 生成该 pio文件对应的 .h 文件 `cyw43_bus_pio_spi.pio.h` 然后复制过来是以供项目调用。
3
条评论
默认排序
按发布时间排序
登录
注册新账号
关于作者
螺丝松掉的人
这家伙很懒,什么也没写!
文章
28
回答
0
被采纳
0
关注TA
发私信
相关文章
1
raspberry pi pico 使用 studio 产生 uf2 无法运行
2
studio 的 pico 1.0.3 sdk 中 elf2uf2 缺 dll
3
Raspberry Pi Pico 下面的bsp文档在哪里?目前支持多少外设
4
使用env编译树莓派pico(raspberry-pico)时编译报错
5
有没有喜欢玩树莓派pico的,RTTHREAD BSP 一起来贡献
6
树莓派pico lvgl 无法生成uf2文件
7
ubuntu 下编译 pico ,menuconfig 没有env 下配置选项?
8
树莓派pico hardware/pio.h: No such file or directory
9
关于RP2040-RASPBERRYPI-PICO编译报错ImportError: No module named building,请问是哪里出现问题
10
新建的raspberry pico工程无法编译成功
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
机器人操作系统 (ROS2) 和 RT-Thread 通信
4
五分钟玩转RT-Thread新社区
5
国产MCU移植系列教程汇总,欢迎查看!
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
热门标签
RT-Thread Studio
串口
LWIP
Env
AT
SPI
Bootloader
FinSH
ART-Pi
CAN总线
Hardfault
USB
文件系统
RT-Thread
DMA
SCons
线程
MQTT
RT-Thread Nano
STM32
RTC
rt-smart
ESP8266
flash
ota在线升级
WIZnet_W5500
FAL
I2C
packages_软件包
UART
cubemx
freemodbus
潘多拉开发板_Pandora
定时器
BSP
PWM
ADC
socket
中断
rt_mq_消息队列_msg_queue
keil_MDK
SDIO
Debug
AB32VG1
MicroPython
编译报错
C++_cpp
msh
ulog
QEMU
本月问答贡献
出出啊
1501
个答案
338
次被采纳
小小李sunny
1390
个答案
276
次被采纳
张世争
715
个答案
157
次被采纳
crystal266
522
个答案
153
次被采纳
whj467467222
1216
个答案
146
次被采纳
本月文章贡献
出出啊
1
篇文章
12
次点赞
小小李sunny
1
篇文章
1
次点赞
张世争
2
篇文章
2
次点赞
crystal266
2
篇文章
5
次点赞
whj467467222
2
篇文章
1
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部