August 1, 2013

Raspberry pi : A LCD display hardware and software example

Following the previous article about the linux kernel module’s compilation, this post will expose a concrete example of hardware wiring to the Pi GPIOs , and also cover the software aspect, with the implementation of a kernel module who drives the hardware.

The basic idea, and schematic of the hardware, is here:

The Pi GPIO ports, P0 and P5 ( rev2 , raspi version) are visible.
Some GPIO outputs/inputs pins are connected to a 74hc574 latch , wich, in turn, is connected to the LCD display ( industry standard, HD44780 based display).

It’s not obvious, why there is a 74hc574 between the Pi and the LCD display. but, in fact, this ‘574 Latch is freeing 6 pins of the GPIO when the LCD does not have to be adressed. The only pin permanently occupied is the latch clock pin, wich latches the datas to THIS latch (adressing-like, on a microproc. bus). a little bit thinking will let you imagine that the latch enables a BUS-like architecture (more on this later).

The uggly hardware proto board, as usual

The 4x20 LCD display used for my proto

Well the second thing one can notice, is that the LCD display is used in 4-bit mode. nothing new here. 4 bit mode data bus is ‘GPIO-pin-efficient’ solution.
The third thing is that 2 bits of the latch remains unused ( free for other ouputs, your taste… )

I know there’s plenty of LCD connected to raspberry pi everywhere on the internet.latched LCD’s ? there must be less . latched LCD’s with complete kernel module in C code ? there should be lesser again.

A test display text

a capture showing the console in linux : INSMOD of the module, then dump of the kernel messages queue, then echo the test TEXT to /dev/mynull

that’s why this post is here : dive into that code, and help you understand what i’ve understood by diggin and trying a lot of things.
Like for the past post about kernel module’s build under linux, i’ll go straightforward to the essential.It’s up to you to dig into the links i give, and google for words or concepts you dont understand.
- And dont forget i’m a linux newbie -

coming after my hollidays : The why of a linux module : the char device, ioctl accesses and so on…


July 30, 2013

Creating a linux device driver for the raspberry PI

first (i had hard times figuring out what missed me for correct compilation of a driver module ) ,try to Install the module-assistant for debian (i assume you’re logged in as ROOT ):
$ apt-get install module-assistant
$ m-a prepare(trys to get linux-headers )

At this epoch, you get an error : cant locate 3.6.11+ linux headers ( if you run the same version as mine is ..)
in doubt, you can check your linux version :

$ uname -r

thats bullshit.. GPL, linux, and so on… looks like it’s an adventure to get something going straight easy on the linux/raspberry Pi world.. :(
OK, lets get the linux headers (wget) from here : linux-headers-3611_3611-2_armhf (huge - i eihis.Com hosts it )
then, unpack it :

$ dpkg -i linux-headers-3.6.11+_3.6.11+-2_armhf.deb

At this point, the 3.6.11+ headers (tree) should be found here : /usr/src/linux-headers-3.6.11+
So, now let’s create a link to it for Kernel’s MAKE , after removing existing (bad) ones directories links :

$ rm -r /lib/modules/3.6.11+/build
$ rm -r /lib/modules/3.6.11+/src

[may be present. in my case, it was, but i tried many things before so, anyway, in a doubt , do it ]
Now, actually create the links :

$ ln -s /usr/src/linux-headers-3.6.11+ /lib/modules/3.6.11+/build
$ ln -s /usr/src/linux-headers-3.6.11+ /lib/modules/3.6.11+/src

now time to reboot ..

$ reboot

upon new login , CD to the directory of the module you want to compile, then ‘make’ to execute the Makefile.( beware of the Makefile name : case sensitive ! )
now, in the directory where your module.c code was, you get a module.ko file. thats the kernel module file created.
the Makefile should look like this :

obj-m :=yourmodule.o
KDIR :=/lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
[tab here] $(MAKE) -C $(KDIR) M=$(PWD) modules

where :
obj-m is the name of the object you want to build. the corresponding object.c file will be found by the MAKE command…
KDIR is the build directory (where parameters for kernel build,headers, and so on are located )
PWD is the destination (output .ko file) directory ( the current directory where your makefile and yourmodule.c file are located, for instance )

in case of problem, you can start by checking if the links have been created, actually.
Doing a :

$ ls -al /lib/modules/3.6.11+/build

should return :

/lib/modules/3.6.11+/build -> /usr/src/linux-headers-3.6.11+

If everything has run, you should now have a yourmodule.ko file into the current projects directory.
wich prove that the link is existing…
If everything has run, you should now have a yourmodule.ko file into the current projects directory.
you can test it by doing :

$ insmod yourmodule.ko

And stop it by doing :

$ rmmod yourmodule

I guess you now what to put in your ‘yourmodule.c’ file. hello world program examples can be found at many places dealing with linux driver’s compilation how-to websites.
This information post uses many sources (not listed) where i’ve found, finally, the way to compile drivers with no errors on the Raspberry Pi RASPBIAN , linux version 3.6.11+.
Hope this helps !

portions of code, with adaptations ,updates, modifications, and also Informations are coming from :

http://www.tldp.org/LDP/lkmpg/2.6/lkmpg.pdf (The linux kernel Module programming guide )

http://www.linuxforu.com/2011/04/character-device-files-creation-operations/ ( full of usefull articles )

http://gauss.ececs.uc.edu/Courses/c4029/lectures/work_queue.pdf ( work queues in Linux )


cat{ } { post_423 } { } 2009-2015 EIhIS Powered by WordPress