2

So thinking about how I would make my own hardware/drivers I'm using the GPIO and I know the GPIO uses specific memory banks in a certain range for all hardware in fact, but how would I go about reading and writing them to these memory banks?

Does the USB work in a similar manner?

P.S I'm using a Raspberry Pi.

Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
Definity
  • 691
  • 2
  • 11
  • 31
  • Generally you'd write `peek` and `poke` assembler routines. You can also use various types of subterfuge to convert an int/long value into an address. – Hot Licks Sep 27 '12 at 18:17
  • 2
    Welcome to Stack Overflow! Are you coding for a particular operating system, or are you writing an embedded program with no o/s? – Robᵩ Sep 27 '12 at 18:22
  • 1
    USB is altogether a different protocol. GPIO should generally be register mapped. You should be able to read/write memory mapped registers to read/write GPIO. – Raj Sep 27 '12 at 18:22
  • possible duplicate of [Accessing the GPIO (of a raspberry pi) without ``sudo``](http://stackoverflow.com/questions/12133860/accessing-the-gpio-of-a-raspberry-pi-without-sudo) – Bo Persson Sep 27 '12 at 18:24
  • Thanks Rob. I was thinking of first starting it out in Linux and then may by just make my own small OS and go from their. – Definity Sep 27 '12 at 18:32
  • Are you using Linux on the RasPi, or just coding straight onto the bare metal? – slugonamission Sep 27 '12 at 18:35

2 Answers2

1

If you are using Linux, you can also use Proc interface to communicate with GPIO. For example if you see this link, it shows how GPIO pins can be read or written directly from the shell prompt.

Raj
  • 3,300
  • 8
  • 39
  • 67
0

If you are using a system that supports mmap(), https://groups.google.com/forum/?fromgroups=#!topic/comp.os.linux.development.apps/2kiUc-dNa3c discusses using mmap() to do this. The summary is that your process will open /dev/mem for reading and writing, and will map your base physical address as the offset into the file (and your addr parameter is whatever virtual address you wish to use).

mah
  • 39,056
  • 9
  • 76
  • 93