以一个简单的LED驱动及按键驱动编写为例

1.驱动编写要点:

linux 2.6
以上版本很多函数的名称和以前有所不同,如果学习资料年份比较早,按此操作可能会出现很多问题,这会让初学者感到非常困惑:为什么完全按照视频/书中操作,视频/书中没有问题,我的总是出现很多错误?

驱动程序有以下几个函数有更新:

a 设备节点创建 class_device_create 更新为 device_create


    格式举例:ledsdrv_class = class_create(THIS_MODULE, "leds");

          device_create(ledsdrv_class, NULL, MKDEV(major, 0), NULL, "LED");


b.设备节点注销 class_device_unregister函数使用,往往会出错,可用device_destroy函数代替


    格式举例: device_destroy(ledsdrv_class, MKDEV(major, 0));

c.头文件

    #include <asm/arch/regs-gpio.h> 改为#include <mach/regs-gpio.h>


    #include <asm/hardware.h>改为#include <mach/hardware.h>


驱动及应用程序的编译及错误解决办法

a. 驱动程序编译时会进入内核目录,要保证内核已事先编译过,否则会报错:

    Kernel configuration is invalid. include/linux/autoconf.h or
include/config/auto.conf are missing


b.编译内核,驱动和应用程序所用交叉编译器版本要一致,如内核编译使用的时arm-linux-gcc 4.1.2版本,则编译驱动也要用     4.1.2版本

c.编译内核,menuconfig中enable loadble module support -->选择support module
unloading,否则驱动不能使用rmmod卸载

d.编译错误:implicit declaration of fuction 'request_irq'

            解决办法:该函数在/include/linux/interrupt.h中定义,增加头文件 #include
<linux/interrupt.h>


            'IRQT_ BOTHEDGE' undeclared(first use in this fuction)


            解决办法:IRQT_ BOTHEDGE换成IRQ_TYPE_EDGE_BOTH,增加头文件#include <linux/irq.h>


            implicit declaration of fuction 's3c2410_gpio_getpin'



            解决办法:该函数定义在arch/arm/mach-s3c2410/include/mach/gpio-fns.h中,增加#include
<mach/gpio-fns.h>


            implicit declaration of fuction 'class_creat'


            implicit declaration of fuction 'device_creat'

            解决办法:该2个函数定义在/include/linux/device.h中,增加头文件#include
<linux/device.h>


应用程序的执行

以使用SecureCRT命令行说明

    因应用程序已设置了相关led亮灭的参数,以该参数仅有两个 on|off为例,应用程序名为ledcontrol

    将驱动程序放到开发板/lib/modules目录下(若无此目录自己先创建一个,同时创建/lib/modules/[内核版本]目录,如内核

    是2.6.31版本,则创建/lib/modules/2.6.31,以便临时文件保存);将应用程序放入usr/bin目录,执行ledcontrol
on         或ledcontrol off验证能否正确运行;若在其他目录,可能要进入该目录,执行./ledcontrol on
或./ledcontrol off




    




友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信