Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
PIN_GPIO通用驱动
ARTPI 测试 PIN 所有接口
发布于 2023-06-09 14:55:15 浏览:548
订阅该版
[tocm] # 目标 测试 ARTPI 上和 pin 有关的这些接口: ``` rt_pin_get() 获取引脚编号 rt_pin_mode() 设置引脚模式 rt_pin_write() 设置引脚电平 rt_pin_read() 读取引脚电平 rt_pin_attach_irq() 绑定引脚中断回调函数 rt_pin_irq_enable() 使能引脚中断 rt_pin_detach_irq() 脱离引脚中断回调函数 ``` RT-Thread PIN 设备文档:https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/pin/pin # 接线 根据 ARTPI 引脚图: ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20230609/ecfbab4113c48216418866488dec311d.png.webp) ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20230609/b4ad4f6703cec3ee1306361d7b210865.png.webp) 我们选择 PC6、PC7 两个引脚,PC7 输出,PC6 输入下拉。用一根杜邦线将两个引脚连接起来。 ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20230609/93e81ed24dd787a8a370f06f3e5726cf.png.webp) PC7 每隔半秒钟切换一次高低电平,PC6 设置成上升沿中断。同时每隔一秒切换一次中断使能状况。这样每过2秒钟就会触发执行中断回调函数。 # 代码 ``` // main.c #include
#include
#include "drv_common.h" //#define PC7_PIN GET_PIN(C, 7) //#define PC6_PIN GET_PIN(C, 6) // 中断回调函数 void pin_isr(void *args) { rt_uint32_t pin = (rt_uint32_t)args; // 获取引脚编号 rt_kprintf("pin %d level is high\n", pin); // 打印引脚电平状态 } int main(void) { rt_uint32_t count = 1; int pc6 = rt_pin_get("PC.6"); int pc7 = rt_pin_get("PC.7"); rt_kprintf("pc6 is %d\n", pc6); rt_kprintf("pc7 is %d\n", pc7); rt_pin_mode(pc7, PIN_MODE_OUTPUT); rt_pin_mode(pc6, PIN_MODE_INPUT_PULLDOWN); rt_pin_attach_irq(pc6, PIN_IRQ_MODE_RISING, pin_isr, (void *)pc6); rt_pin_irq_enable(pc6, PIN_IRQ_ENABLE); while (count ++) { if (count % 2) rt_pin_irq_enable(pc6, PIN_IRQ_DISABLE); else rt_pin_irq_enable(pc6, PIN_IRQ_ENABLE); rt_thread_mdelay(500); rt_pin_write(pc7, PIN_HIGH); rt_thread_mdelay(500); rt_pin_write(pc7, PIN_LOW); } return RT_EOK; } #include "stm32h7xx.h" static int vtor_config(void) { /* Vector Table Relocation in Internal QSPI_FLASH */ SCB->VTOR = QSPI_BASE; return 0; } INIT_BOARD_EXPORT(vtor_config); ``` # 运行结果 ``` \ | / - RT - Thread Operating System / | \ 4.1.0 build Jun 9 2023 14:46:16 2006 - 2022 Copyright by RT-Thread team pc6 is 38 pc7 is 39 msh />pin 38 level is high pin 38 level is high pin 38 level is high pin 38 level is high pin 38 level is high pin 38 level is high pin 38 level is high (每隔2秒输出一次 pin 38 level is high) ``` 至此,RT-Thread 中 PIN 的所有接口都已经测试完毕。 # utest 自动测试 在 application 目录下新建一个 pin_tc.c 文件,内容如下: ``` /* * Copyright (c) 2006-2023, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2023-06-09 IcyFeather the first version */ #include
#include
#include "drv_common.h" #include "utest.h" // 中断回调函数 void pin_isr(void *args) { rt_uint32_t pin = (rt_uint32_t)args; // 获取引脚编号 uassert_int_equal(pin, 38); uassert_int_equal(rt_pin_read(38), PIN_HIGH); } static void test_rt_pin(void) { int pc6 = rt_pin_get("PC.6"); int pc7 = rt_pin_get("PC.7"); uassert_int_equal(pc6, 38); uassert_int_equal(pc7, 39); rt_pin_mode(pc7, PIN_MODE_OUTPUT); rt_pin_mode(pc6, PIN_MODE_INPUT_PULLDOWN); rt_pin_attach_irq(pc6, PIN_IRQ_MODE_RISING, pin_isr, (void *)pc6); rt_pin_irq_enable(pc6, PIN_IRQ_ENABLE); rt_pin_write(pc7, PIN_HIGH); uassert_int_equal(rt_pin_read(pc6), PIN_HIGH); rt_pin_write(pc7, PIN_LOW); uassert_int_equal(rt_pin_read(pc6), PIN_LOW); } static rt_err_t utest_tc_init(void) { return RT_EOK; } static rt_err_t utest_tc_cleanup(void) { return RT_EOK; } static void testcase(void) { UTEST_UNIT_RUN(test_rt_pin); } UTEST_TC_EXPORT(testcase, "pin_tc", utest_tc_init, utest_tc_cleanup, 10); ``` 编译下载,在 finsh 中运行 utest_run: ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20230609/3b8ede85abb4aff6eb26be96afe2ee89.png) 最后显示 PASSED 即为测试通过。
2
条评论
默认排序
按发布时间排序
登录
注册新账号
关于作者
IcyFeather
这家伙很懒,什么也没写!
文章
10
回答
7
被采纳
1
关注TA
发私信
相关文章
1
PIN绑定引脚中断回调函数没有反应
2
rtthread PIN设备
3
关于引脚宏定义的一些疑惑
4
关于gpio引脚实在不懂了,求大家帮助
5
GET_PIN(A, 1) 提示 'A' 未定义
6
关于4.0.2版本中STM32的PIN设备外部中断的相关问题
7
自己按照官方手册 在drv_gpio.c里面找不到PIN脚信息
8
关于多个PIN设备同时读写的问题
9
翻车在一个GPIO上 开启pin中断 导致程序卡死
10
外部中断回调函数执行问题
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
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
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
I2C_IIC
ESP8266
UART
WIZnet_W5500
ota在线升级
cubemx
PWM
flash
freemodbus
BSP
packages_软件包
潘多拉开发板_Pandora
定时器
ADC
flashDB
GD32
socket
编译报错
中断
Debug
rt_mq_消息队列_msg_queue
SFUD
msh
keil_MDK
ulog
C++_cpp
MicroPython
本月问答贡献
出出啊
1518
个答案
343
次被采纳
小小李sunny
1444
个答案
290
次被采纳
张世争
813
个答案
177
次被采纳
crystal266
547
个答案
161
次被采纳
whj467467222
1222
个答案
149
次被采纳
本月文章贡献
出出啊
1
篇文章
5
次点赞
小小李sunny
1
篇文章
1
次点赞
张世争
1
篇文章
3
次点赞
crystal266
2
篇文章
2
次点赞
whj467467222
2
篇文章
2
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部