Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
PIN_GPIO通用驱动
ARTPI 测试 PIN 所有接口
发布于 2023-06-09 14:55:15 浏览:222
订阅该版
[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 引脚图:   我们选择 PC6、PC7 两个引脚,PC7 输出,PC6 输入下拉。用一根杜邦线将两个引脚连接起来。  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:  最后显示 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
机器人操作系统 (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
串口
Env
LWIP
AT
SPI
Bootloader
FinSH
ART-Pi
CAN总线
Hardfault
USB
文件系统
DMA
RT-Thread
SCons
线程
RT-Thread Nano
MQTT
stm32
ESP8266
rt-smart
WIZnet_W5500
RTC
flash
ota
UART
FAL
packages_软件包
I2C
freemodbus
cubemx
潘多拉开发板_Pandora
定时器
BSP
PWM
ADC
socket
AB32VG1
SDIO
keil_MDK
中断
消息队列_msg_queue
编译报错
Debug
C++_cpp
msh
QEMU
SFUD
MicroPython
本月问答贡献
张世争
19
个答案
4
次被采纳
道友
41
个答案
3
次被采纳
CrazyH
52
个答案
2
次被采纳
踩姑娘的小蘑菇
15
个答案
2
次被采纳
xiaorui
8
个答案
2
次被采纳
本月文章贡献
paradox
5
篇文章
4
次点赞
螺丝松掉的人
4
篇文章
12
次点赞
Ryan_CW
3
篇文章
4
次点赞
子牧r
3
篇文章
2
次点赞
牧尘
2
篇文章
6
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部