10

I'm a high level app developer (C#, python) and I'd like to get my hands dirty with low level embedded application development. Cambridge University has posted a series of tutorials teaching you how to create an operating system for the Raspberry Pi called Baking Pi. I've intended to post my question regarding this tutorial here and update the answers as I go along. Maybe even post some points that I figured out myself.

So I've been following along with lesson 1 and I'm confused already. Here is the page link.

The first part of the tutorial say we need to (I assume) turn on the GPIO controller by writing the value 0x20200000 to register r0. I cannot find such relevant information anywhere in the data sheet. (link). I've looked at the GPIO section but I didn't see any indication of 16 registers or r0. Where is this information?

UPDATE

First of all, the tutorial talks about turning on the OK LED, which is the status LED. You might be wondering where in the Manual does it say GPIO 16 is connected to the OK LED. It won't. You need to look at the Raspberry Schematics and find which GPIO is the status_led connected to. Here is the link the the schematics. Page 2, Block BCM2835.

So the goal is to select the GPIO16 pin. (more updates to come...)

ArmenB
  • 235
  • 2
  • 12

3 Answers3

6

Here is the relevant information in that tutorial:

Addresses in computers are just numbers, and so the number 0x20200000 happens to be the address of the GPIO controller. This is just a design decision taken by the manufacturers, they could have used any other address (providing it didn't conflict with anything else). I know this address only because I looked it up in a manual [3], there is no particular system to the addresses (other than that they are all large round numbers in hexadecimal).

r0 is simply a section of memory on the processor where you can store whatever information you like; these are called general purpose registers. We write the location of the GPIO controller to this location so that we can reuse it later, as we would usually do using a variable in high level programming.

I think the value 0x20200000 actually refers to the first memory location in the table on page 90. You'll notice that before we write to the register we increment it by 4, giving us Function Select 1 (see table), the register that controls a few pins, including the one we want to write to.

Does that help at all?

Jivings
  • 22,538
  • 11
  • 90
  • 139
4

Thanks to Jivings and emcconville for answering the question.

In the data sheet pdf, page 6 section ARM physicall address, there is a section which says

Physical addresses range from 0x20000000 to 0x20FFFFFF for peripherals. The bus addresses for peripherals are set up to map onto the peripheral bus address range starting at 0x7E000000. Thus a peripheral advertised here at bus address 0x7Ennnnnn is available at physical address 0x20nnnnnn.

Going to page 90, the first row of the table states:

0x7E200000 GPFSEL0 GPIO Function Select 0 32 R/W

so the 0x7E200000 translates to the physical address 0x20200000, which is the GPIO Function select 0 bit.

As for r0, there are 16 general purpose registers in the ARM, which we can use to store numbers, and that is why in the tutorial he is choosing r0 since it's the first free register.

ArmenB
  • 235
  • 2
  • 12
2

The register r0 through r12 are general purpose. Naturally, it's easiest to start with r0. As Jivings pointed out, The manual list each address, and states:

Physical addresses range from 0x20000000 to 0x20FFFFFF for peripherals.

emcconville
  • 450
  • 3
  • 11
  • I cannot choose two correct Answers! this is lame. Please fix this website...Thanks for your input. I finally understood the meaning of RTFM. – ArmenB Oct 06 '12 at 01:07