查看: 1327|回复: 3

[原创] 【DIY-LPC553X】+ 基于zephyr OS的led驱动测试

[复制链接]
  • TA的每日心情
    开心
    2024-4-10 10:22
  • 签到天数: 1317 天

    [LV.10]以坛为家III

    124

    主题

    2831

    帖子

    31

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    7570
    最后登录
    2024-4-10
    发表于 2022-11-15 23:50:40 | 显示全部楼层 |阅读模式
        这篇来学习开发板硬件上的LED驱动程序。

        一 、硬件部分
         在zephyr的sample\basic\blinky例程是测试板卡上的LED指示灯的。
         1.1、lpcxpresso55s36板卡对应的LED硬件端口配置
         root@ubuntu:~/zephyrproject/zephyr/boards/arm/lpcxpresso55s36#
         lpcxpresso55s36.dts文件内LED端口的定义

          20221114162210.png


         1.2、DIY板卡的LED硬件端口


        20221114162713.png
         将上面的文件修改成自己板卡的硬件端口
        20221114162926.png
       
        二、程序部分


        测试程序修改sample\basic\blinky\src\main.c代码
        mian.c
    1. /*
    2. * Copyright (c) 2016 Intel Corporation
    3. *
    4. * SPDX-License-Identifier: Apache-2.0
    5. */

    6. #include <zephyr/kernel.h>
    7. #include <zephyr/drivers/gpio.h>

    8. /* 1000 msec = 1 sec */
    9. #define SLEEP_TIME_MS   500

    10. /* The devicetree node identifier for the "led0" alias. */
    11. #define LED0_NODE DT_ALIAS(led0)
    12. #define LED1_NODE DT_ALIAS(led1)
    13. #define LED2_NODE DT_ALIAS(led2)
    14. #define LED3_NODE DT_ALIAS(led3)

    15. /*
    16. * A build error on this line means your board is unsupported.
    17. * See the sample documentation for information on how to fix this.
    18. */
    19. static const struct gpio_dt_spec led0 = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
    20. static const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(LED1_NODE, gpios);
    21. static const struct gpio_dt_spec led2 = GPIO_DT_SPEC_GET(LED2_NODE, gpios);
    22. static const struct gpio_dt_spec led3 = GPIO_DT_SPEC_GET(LED3_NODE, gpios);

    23. void main(void)
    24. {
    25.        
    26.         gpio_pin_configure_dt(&led0, GPIO_OUTPUT_ACTIVE);
    27.         gpio_pin_configure_dt(&led1, GPIO_OUTPUT_ACTIVE);
    28.         gpio_pin_configure_dt(&led2, GPIO_OUTPUT_ACTIVE);
    29.         gpio_pin_configure_dt(&led3, GPIO_OUTPUT_ACTIVE);

    30.         gpio_pin_set_dt(&led0, 0);
    31.         gpio_pin_set_dt(&led1, 1);
    32.         gpio_pin_set_dt(&led2, 0);
    33.         gpio_pin_set_dt(&led3, 1);

    34.         while (1) {
    35.        
    36.                 gpio_pin_toggle_dt(&led0);
    37.                 gpio_pin_toggle_dt(&led1);
    38.                 gpio_pin_toggle_dt(&led2);
    39.                 gpio_pin_toggle_dt(&led3);
    40.                 k_msleep(SLEEP_TIME_MS);
    41.         }
    42. }
    复制代码

        三、编译和下载

        执行命令:
        root@ubuntu:~/zephyrproject/zephyr# west build -p auto -b lpcxpresso55s36 /opt/zephyrprj/blinky/
        root@ubuntu:~/zephyrproject/zephyr# west flash


        四、程序运行


        LED指示灯交替点亮。
        200.gif

       
    哎...今天够累的,签到来了~
    回复

    使用道具 举报

  • TA的每日心情
    慵懒
    2024-4-9 17:01
  • 签到天数: 1478 天

    [LV.10]以坛为家III

    203

    主题

    2万

    帖子

    64

    超级版主

    Rank: 8Rank: 8

    积分
    92619
    最后登录
    2024-4-24
    发表于 2022-11-16 08:35:06 | 显示全部楼层
    大佬软硬件通吃呢~~
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    奋斗
    5 小时前
  • 签到天数: 1939 天

    [LV.Master]伴坛终老

    61

    主题

    1万

    帖子

    3

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    17288
    最后登录
    2024-4-25
    发表于 2022-11-16 09:25:05 | 显示全部楼层
    zephyr也整了个设备树啊
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2024-3-26 15:16
  • 签到天数: 266 天

    [LV.8]以坛为家I

    3299

    主题

    6546

    帖子

    0

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    32023
    最后登录
    2024-4-25
    发表于 2022-11-16 09:36:16 | 显示全部楼层
    续上了,感谢分享
    签到签到
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2024-4-25 14:40 , Processed in 0.117581 second(s), 22 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表