12

I'd like to write a Linux device driver for some real hardware device. What Raspberry Pi peripherals are a good fit? Basically I need the following:

  1. It must be small enough for a beginner (few month at most, better few weeks).

  2. Datasheet must be available. At first I was thinking about USB-Ethernet adapter, but it looks like it has very limited datasheet.

Any ideas? May be something like making serial console work over GPIO?

Ghanima
  • 15,958
  • 17
  • 65
  • 125

3 Answers3

3

It can be hard to learn writing drivers when interfacing with complicated devices and/or complicated buses. Because of that I would recommend either using some simple and well known devices (ignoring existing implementation of their drivers in the kernel) like I²C/SPI devices that are usually used with microcontrollers. For example you could find any device that is "supported" by Arduino community (meaning there is a library/documentation for it) and try using it with RaspberryPi.

If that's not enough or you don't want to buy too much hardware, you can create one yourself. Just get some microcontroller (like atmega or something), create a program for it to become some device and then try interfacing with it using Linux drivers. This way you can easily create programs that will emulate different classes of devices. And since you will write your "firmware" yourself, it will help you debug problems.

You need some microcontroller programming skills for that but it's not hard to learn programming with Arduino and I believe it's useful knowledge for driver programmer anyway.

Krzysztof Adamski
  • 9,605
  • 1
  • 38
  • 53
2

Personally I would start with a very simple device, such as one or more LEDs connected directly to GPIO pins.

You could either buy a device ready to plug in, or wire your own one.

The reason I would suggest this is that debugging drivers is generally much more difficult then a normal program, therefore a simple challenge to get started is useful, also you can then use that code as a method of debug for more complex devices (status out to a GPIO pin to attach to an oscilloscope) where timing is important.

If it is of interest there is a kernel driver for LedBorg available here, the source should be a reasonably simple example for driving GPIO pins at a regular interval.

PiBorg
  • 1,537
  • 10
  • 11
0

The simplest "device" that you can write a hardware driver for (if hardware driver development is your thing) can also be as simple as a LED (I added the quotation marks because technically a LED is not a device but it's still a piece of hardware) as @PiBorg has suggested.

Other choices would be some easy-to-interface device/components like a photoresistors, passive infrared sensors (short: PIR), temperature sensors, PC fans (preferably a 4-wire fan that allows you not only to monitor but also to control the RPM), LED dot matrices and so on. Basically such simple devices will allow you to have the minimum on hardware (so that you can see and touch what you've actually accomplished) and at the same time you can learn about a lot of topics that are used for much more complex devices where the complexity comes mostly from the protocol they use.

Mind also that you don't need to go the extra mile digging into the kernel modules. Of course if you want to do that nobody is stopping you. :)

Here is an example of interfacing a passive infrared sensor (I'm going to test it soon when my PIR gets delivered :3). You can take this and start digging deeper into the world of the Linux kernel in order to see how you can for example create a kernel driver, which works with the PIR.

rbaleksandar
  • 257
  • 1
  • 3
  • 11