在线时间240 小时
UID416136
注册时间2022-10-3
NXP金币785
TA的每日心情 | 无聊 2024-8-29 10:59 |
---|
签到天数: 15 天 [LV.4]偶尔看看III
金牌会员
- 积分
- 2946
- 最后登录
- 2025-1-6
|
本身想做的事把RTT现有驱动一个一个的测试一轮,顺便把缺少的驱动一个一个的添加上去。由于自己的工作习惯是通过敲命令的方式来测试各个模块,而且RTT也支持msh命令行,因此便决定采用敲命令的方式进行驱动测试。
查询LPC55sxx代码,发现应用层的驱动测试接口并未添加,因此手动添加测试接口。
修改配置文件“bsp\lpc55sxx\lpc55s69_nxp_evk\applications\SConscript”
- import rtconfig
- from building import *
- cwd = GetCurrentDir()
- #src = Glob('main.c')
- src = Glob('*.c')
- CPPPATH = [cwd]
- # add for startup script
- if rtconfig.PLATFORM in ['gcc']:
- CPPDEFINES = ['__START=entry']
- else:
- CPPDEFINES = []
- group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES=CPPDEFINES)
- Return('group')
复制代码
- 代码添加
- 在“bsp\lpc55sxx\lpc55s69_nxp_evk\applications”目录下添加文件“gpio_test.c”,并添加以下内容:
- /*
- * Copyright (c) 2006-2023, RT-Thread Development Team
- * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2023-02-07 Liuxiequan First Version
- *
- */
- #include <rtdevice.h>
- #include "drv_pin.h"
- int gpio_mode(int argc, char **argv)
- {
- int err = -RT_ERROR;
- int port, pin, level;
- if (argc == 4)
- {
- port = atoi(argv[1]);
- pin = atoi(argv[2]);
- if ((port != -1) && (pin != -1))
- {
- if (strcmp("in", argv[3]) == 0)
- {
- rt_pin_mode(GET_PINS(port, pin), PIN_MODE_INPUT);
- rt_kprintf("PIO%d_%d input\n", port, pin);
- err = RT_EOK;
- }
- else if (strcmp("in_pu", argv[3]) == 0)
- {
- rt_pin_mode(GET_PINS(port, pin), PIN_MODE_INPUT_PULLUP);
- rt_kprintf("PIO%d_%d input pull up\n", port, pin);
- err = RT_EOK;
- }
- else if (strcmp("in_pd", argv[3]) == 0)
- {
- rt_pin_mode(GET_PINS(port, pin), PIN_MODE_INPUT_PULLDOWN);
- rt_kprintf("PIO%d_%d input pull down\n", port, pin);
- err = RT_EOK;
- }
- else if (strcmp("out", argv[3]) == 0)
- {
- rt_pin_mode(GET_PINS(port, pin), PIN_MODE_OUTPUT);
- rt_kprintf("PIO%d_%d output\n", port, pin);
- err = RT_EOK;
- }
- else if (strcmp("out_od", argv[3]) == 0)
- {
- rt_pin_mode(GET_PINS(port, pin), PIN_MODE_OUTPUT_OD);
- rt_kprintf("PIO%d_%d output od\n", port, pin);
- err = RT_EOK;
- }
- }
- }
- if (err)
- {
- rt_kprintf("Param error: Need input gpio_mode port pin [in/in_pu/in_pd/out/out_od]\n");
- }
- }
- MSH_CMD_EXPORT(gpio_mode, gpio_mode)
- int gpio_read(int argc, char **argv)
- {
- int err = -RT_ERROR;
- int port, pin, level;
- if (argc == 3)
- {
- port = atoi(argv[1]);
- pin = atoi(argv[2]);
- if ((port != -1) && (pin != -1))
- {
- rt_kprintf("PIO%d_%d: %d\n", port, pin, rt_pin_read(GET_PINS(port, pin)));
- err = RT_EOK;
- }
- }
- if (err)
- {
- rt_kprintf("Param error: Need input gpio_read port pin\n");
- }
- }
- MSH_CMD_EXPORT(gpio_read, gpio_read)
- int gpio_write(int argc, char **argv)
- {
- int err = -RT_ERROR;
- int port, pin, level;
- if (argc == 4)
- {
- port = atoi(argv[1]);
- pin = atoi(argv[2]);
- level = atoi(argv[3]);
- if ((port != -1) && (pin != -1) && ((level == 0) || (level == 1)))
- {
- rt_pin_write(GET_PINS(port, pin), level);
- rt_kprintf("PIO%d_%d level : %d\n", port, pin, level);
- err = RT_EOK;
- }
- }
- if (err)
- {
- rt_kprintf("Param error: Need input gpio_write port pin level\n");
- }
- }
- MSH_CMD_EXPORT(gpio_write, gpio_write)
复制代码
- 在“bsp\lpc55sxx\lpc55s69_nxp_evk\”目录下启动env,并运行命令“scons --target=mdk5”,生成新工程
- > scons --target=mdk5
- scons: Reading SConscript files ...
- scons: warning: No version of Visual Studio compiler found - C/C++ compilers most likely not set correctly
- File "E:\Project\RT-Thread\github\rt-thread\bsp\lpc55sxx\lpc55s69_nxp_evk\SConstruct", line 45, in <module>
- Keil5 project is generating...
- Keil Version: 0.0
- Keil-MDK project has generated successfully!
复制代码
通过查看开发板原理图,发现PIO0_0属于悬空状态,适合用作接口测试,因此暂时使用该口做接口测试(论坛一贴图就说超,删掉图片,具体自行查看原理图)
- \ | /
- - RT - Thread Operating System
- / | \ 5.0.0 build Feb 7 2023 20:41:22
- 2006 - 2022 Copyright by RT-Thread team
- [I/I2C] I2C bus [i2c4] registered
- using armclang, version: 6180002
- msh />sd mount to / failed
- msh />
- msh />
- msh />
- msh />gpio_mo
- gpio_mode
- msh />gpio_mode 0 0 in
- msh />gpio_mode 0 0 in
- PIO0_0 input
- msh />gpio_r
- gpio_read
- msh />gpio_read 0 0
- PIO0_0: 1
- msh />gpio_mode 0 0 in_pd
- msh />gpio_mode 0 0 in_pd
- PIO0_0 input pull down
- msh />
- msh />
- msh />gpio_re
- gpio_read
- msh />gpio_read 0 0
- PIO0_0: 0
- msh />gpio_re
- gpio_read
- msh />gpio_mode 0 0 in_pu
- PIO0_0 input pull up
- msh />
- msh />
- msh />gpio_read 0 0
- PIO0_0: 1
- msh />gpio_mode 0 0 out
- PIO0_0 output
- msh />gpio_r
- gpio_read
- msh />gpio_read 0
- Param error: Need input gpio_read port pin
- msh />gpio_r
- gpio_read
- msh />gpio_read 0 0
- PIO0_0: 1
- msh />gpio_out 0 0 0
- gpio_out: command not found.
- msh />gpio_wri
- gpio_write
- msh />gpio_write 0 0 0
- PIO0_0 level : 0
- msh />gpio_re
- gpio_read
- msh />gpio_read 0
- Param error: Need input gpio_read port pin
- msh />gpio_re
- gpio_read
- msh />gpio_read 0 0
- PIO0_0: 0
- msh />gpio_mode 0 0 out_od
- PIO0_0 output od
- msh />gpio_re
- gpio_read
- msh />gpio_read 0 0
- PIO0_0: 1
- msh />gpio_w
- gpio_write
- msh />gpio_write 0 0 0
- PIO0_0 level : 0
- msh />gpio_read 0 0
- PIO0_0: 0
- msh />
复制代码
通过测试PIO0_0,发现该gpio驱动层实现逻辑正常。由于板载其他IO口大部分存在上下拉情况,在测试时读取的值会与悬空态读取的值有差异,发现差异时通过查找原理图,发现与实际效果一致。
另外,测试发现NXP芯片一个很好的地方,在IO口设置为输出态时,使用gpio_read读回的IO口状态正确,查驱动层和fsl层代码,并未发现特殊处理,怀疑是芯片硬件层面实现了该方面的兼容。
LPC55S69-SCH.zip
oxlm/rt-thread: RT-Thread is an open source IoT operating system. (github.com)
|
|