CubieBoard中文论坛

 找回密码
 立即注册
搜索
热搜: unable
查看: 29056|回复: 31

[教程]Cubieboard GPIO成功点亮LED[My first step on GPIO of Cubieboard]

[复制链接]
发表于 2013-2-2 17:31:56 | 显示全部楼层 |阅读模式
本帖最后由 WindLand 于 2013-4-7 17:37 编辑

2013-4-3更新:由于标准GPIO库已经可用了,不建议再使用sun4i_gpio.ko这个驱动。此文仅作思路上的参考,不用照搬
This driver is not recommended now. For the new gpio driver  "gpio-sunxi" is coming. So don't follow this.

为了方便老外,更新为双语版[2013-2-6] (英文很烂,见笑了)

GPIO是干嘛的?你能看到的就是那96个pin针脚,可以用来:外接其他外设或传感器,比如LED灯,步进电机,继电器,温度传感器,红外传感器,超声波传感器等。
**En**what is GPIO? what you can see is the 96 pin on the board. it can be used in : connecting to other device or sensor, eg. LED , motor , relay...
  理论上,51开发板上的针脚能实现的,cubieboard都能实现。
**En**Theoretically,It can do all what the c51 board can do.
  我折腾了很多天、很多个内核之后,终于迈出了第一步,成功点亮了一个LED灯。
**En**after testing on many kernel for many days , I took the first step finally. I light a LED.

正面

正面

正面

看看引脚

看看引脚

看看引脚

未命名3.jpg
控制输出电平


简单的说一下步骤:
**En**the simple step:
编译与你内核版本对应的sun4i-gpio.ko驱动(我同时也编译了uImage),我的内核版本是3.0.57+
**En**compile the sun4i-gpio.ko driver that match the version of your kernel, mine is 3.0.57+
内核以及驱动的源码在github上:https://github.com/linux-sunxi/linux-sunxi
**En**the source of driver and kernel can be found here:  link above.
将编译好的驱动放到SD卡上rootfs分区的/lib/modules/3.0.57+(换为你的内核版本)/kernel/drivers/misc/sun4i-gpio.ko
**En**copy your .ko file to the path above, replace 3.0.57+ to yours. i hope you can make it without error, god bless you.

然后修改script.bin,转为script.fex,添加gpio_para配置段,然后转回script.bin,放到SD卡第一个分区,覆盖script.bin(我同时也将uImage给替换了,应该不换uImage也可以)
**En**then modify the script.bin:turn it to script.fex, add the gpio_para, and return .fex back to script.bin. now put the .bin back, overwite the old one

gpio_para配置如下(只是测试,只配置了4个,没把所有的针脚都加进来):
**En**gpio_para config(I just test 4 pin):

[gpio_para]
gpio_used = 1
gpio_num = 4
gpio_pin_1 = port:PG00<1><default><default><default>
gpio_pin_2 = port:PB19<1><default><default><default>
gpio_pin_3 = port:PG02<1><default><default><default>
gpio_pin_4 = port:PG04<1><default><default><default>


引脚名字请参考  http://linux-sunxi.org/Cubieboard#Expansion_ports
名字后面的1表示把这个引脚以输出模式工作,0则为输入
**En**the name after port:(like PG00) you will refer the link above for more.
the number(1) stand for mode . 0 = make the pin work for input , 1 = for output

驱动和script.bin放进去后,把卡插回到cubieboard,启动,在系统中加载你编译好的驱动:insmod /lib/modules/3.0.57+(换为你的内核版本)/kernel/drivers/misc/sun4i-gpio.ko
**En**when you make the driver and the .bin , put uSD back to slot , rock it now! insmod the .ko you just made.

我用的PG0引脚来做测试的,根据wiki,PG0位于U15(即USB和以太网卡之间的那两排)的5号引脚,所以我接的这里,然后把led另一头接地(我用的U15的19号针脚)
**En**i use the pin named PG0 for my testing,accroding to the wiki, it's on the #5 of U15, so i connect the +DuPont line of LED to this pin, and the GND line to #19 of U19

然后通过 echo 1 > /sys/devices/virtual/misc/sun4i-gpio/pin/***来向对应的针脚输出高电平(***代表对应的针脚,echo 0则为低电平),当然也可以用C语言来实现。
**En**finally ,  follow the command on your console:  echo 1 > /sys/devices/virtual/misc/sun4i-gpio/pin/pg0    (1=high vol .  0=low vol), you can make it via other program such as c or python.

这里有篇老外的文章,内容差不多,需翻墙,里面提到了目前这个sun4i-gpio是一个ugly的驱动。。就是说,非标准驱动,为什么ugly,看这里:
Allwinner do not care too much for the GPIOs as they primary support Android and their major market is the tablet manufacturers. This SUN4I-GPIO is made by Tom Cubie who work at Allwinner and made available to community, this driver though is not so flexible as the sysfs and you can’t switch between input and output easily.
With this driver you permanently assign one port to be input or output in the script.bin and when this gpio kernel module is loading it reads from script.bin the assignments and make them permanently, so if you want to change some GPIO to input or output you have to unload the driver make change in the script.bin and load it again and this is ugly

输入模式和输出模式 是在 script.bin里面定义死的!!有木有!!!
求哪位大神给实现个标准的驱动啊!!


2013-3-20更新:标准的GPIO驱动已经在github上有了,stage分支里面

在此上传一个我编译好的 sun4i-gpio.ko  (仅适用于内核 3.0.57+)
**En** I have upload the sun4i-gpio.ko here.(just for kernel 3.0.57+)
sun4i-gpio.zip (2.82 KB, 下载次数: 374)


If u a interesting in GPIO, refer to my another article <Driven a stepper motor on Cubieboard> (sorry for “chinese only”,you can translate it by google) #^_^#
回复

使用道具 举报

发表于 2013-2-2 21:17:01 | 显示全部楼层
不错,赞一个。希望楼主再接再厉,多发点经验给大家。
回复 支持 反对

使用道具 举报

发表于 2013-2-2 22:00:12 | 显示全部楼层
有意思~
回复 支持 反对

使用道具 举报

发表于 2013-2-4 15:39:04 | 显示全部楼层
求一个编译好的 sun4i-gpio.ko  谢谢  。  邮件 sunfang@injupt.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-2-4 16:18:56 | 显示全部楼层
sunfang1cn 发表于 2013-2-4 15:39
求一个编译好的 sun4i-gpio.ko  谢谢  。  邮件

这个涉及到版本问题,我编译的版本是:3.0.57+
如果版本和你系统版本对不上就加载不了,你是什么版本(uname -r)?
回复 支持 反对

使用道具 举报

发表于 2013-2-4 20:37:58 | 显示全部楼层
WindLand 发表于 2013-2-4 16:18
这个涉及到版本问题,我编译的版本是:3.0.57+
如果版本和你系统版本对不上就加载不了,你是什么版本(una ...

和你一样的哦, 谢谢~
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-2-5 10:08:32 | 显示全部楼层
sunfang1cn 发表于 2013-2-4 20:37
和你一样的哦, 谢谢~

已上传到本帖附件
回复 支持 反对

使用道具 举报

发表于 2013-2-27 15:16:36 | 显示全部楼层
留着用,收藏先
回复 支持 反对

使用道具 举报

发表于 2013-3-14 23:38:02 | 显示全部楼层
我驱动和fex都修改了
但是执行会出现这个问题
root@pizzro-udesktop:~# echo 1 > /sys/devices/virtual/misc/sun4i-gpio/pin/pg0
-bash: /sys/devices/virtual/misc/sun4i-gpio/pin/pg0: No such file or directory
root@pizzro-udesktop:~# tail -f /var/log/syslog
Jan  1 00:11:11 pizzro-udesktop kernel: [  671.740000] Parse_VideoData_Block: VIC 2 support
Jan  1 00:11:11 pizzro-udesktop kernel: [  671.760000] Parse_VideoData_Block: VIC 3 support
Jan  1 00:11:11 pizzro-udesktop kernel: [  671.760000] Parse_VideoData_Block: VIC 0 support
Jan  1 00:11:11 pizzro-udesktop kernel: [  671.780000] Parse_VideoData_Block: VIC 0 support
Jan  1 00:11:11 pizzro-udesktop kernel: [  671.780000] Parse_VideoData_Block: VIC 0 support
Jan  1 00:11:11 pizzro-udesktop kernel: [  671.800000] Parse_AudioData_Block: max channel=2
Jan  1 00:11:11 pizzro-udesktop kernel: [  671.800000] Parse_AudioData_Block: SampleRate code=7
Jan  1 00:11:11 pizzro-udesktop kernel: [  671.820000] Parse_AudioData_Block: WordLen code=7
Jan  1 00:11:11 pizzro-udesktop kernel: [  671.820000] Find HDMI Vendor Specific DataBlock
Jan  1 00:11:11 pizzro-udesktop kernel: [  671.840000] PCLK=74250000 X 1280 1390 1430 1650 Y 720 725 730 750 fr 60 PP
回复 支持 反对

使用道具 举报

发表于 2013-3-14 23:39:06 | 显示全部楼层
root@pizzro-udesktop:~# lsmod
Module                  Size  Used by
gpio_sunxi              7111  0
hello                    736  0
8192cu                584788  0
usbserial              34015  0
root@pizzro-udesktop:~#
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|粤ICP备13051116号|cubie.cc---深刻的嵌入式技术讨论社区

GMT+8, 2024-4-30 03:36 , Processed in 0.027913 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2012 Comsenz Inc. | Style by Coxxs

返回顶部