title: Raspberry Pi: Embedded Programming Exercise, Getting Started
body: <p>First, I am following this tutorial here (<a href="http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/" rel="nofollow">http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/</a>).</p>
  
  <p>In the first exercise you learn about addressing the GPIO pin that is responsible for turning on the green okay LED. I have the rev C of the Raspberry pi which to my knowledge uses the Broadcom (BCM2835) micro processor which has the following datasheet for its peripherals: (<a href="http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/downloads/SoC-Peripherals.pdf" rel="nofollow">http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/downloads/SoC-Peripherals.pdf</a>).</p>
  
  <p>I have read pages 89 through 104 of the data sheet but I am still lost. The program provided by the author does not seem to run even with the cross compiler build chain provided. Striping the comments out of the source provided by the author I have:</p>
  
  <pre><code>.section .init
  .global _start
  _start:
    ldr r0, =0x20200000
  
    /* Enable output on the 16th pin */
    mov r1, #1
    lsl r1, #18
    str r1, [r0, #4]
  
    /* Turn the pin off to turn LED light on */
    mov r1,#1
    lsl r1,#16
    str r1, [r0, #40]
  
  loop$:
    /* Keep the system running */
    b loop$
  </code></pre>
  
  <p>Where I am stuck is, in the data sheet I see nothing about the address 0x20200000. Starting On page 91 in the table 6-2 we see the tables which describe the first 32 bits. And in table 6-1 we see a register description. The address of the first register is 0x7E200000. I have tried to use this address in its place but I still had no luck getting the light to turn on.</p>
  
  <p>Bottom line the LED light does not turn on, and so I can learn, where should I go to get information on how to debug this? Secondly, what am I missing?</p>
  
  <p>If it is useful, here is a hexdump of the img file that I am dd'ing to the SD card.</p>
  
  <pre><code>mehoggan@mehoggan-desktop:~/Devel/scripts/assembly/raspberry-pi-mini-os/example1$ make clean all
  rm -f build/*.o 
  rm -f build/output.elf
  rm -f kernel.img
  rm -f kernel.list
  rm -f kernel.map
  ../arm-2008q3/bin/arm-none-eabi-as -I source/ source/main.s -o build/main.o
  ../arm-2008q3/bin/arm-none-eabi-ld --no-undefined build/main.o -Map kernel.map -o build/output.elf -T kernel.ld
  ../arm-2008q3/bin/arm-none-eabi-objcopy build/output.elf -O binary kernel.img 
  ../arm-2008q3/bin/arm-none-eabi-objdump -d build/output.elf &gt; kernel.list
  mehoggan@mehoggan-desktop:~/Devel/scripts/assembly/raspberry-pi-mini-os/example1$ 
  
  hexdump -C ./kernel.img 
  00000000  18 00 9f e5 01 10 a0 e3  01 19 a0 e1 04 10 80 e5  |................|
  00000010  01 10 a0 e3 01 18 a0 e1  28 10 80 e5 fe ff ff ea  |........(.......|
  00000020  00 00 20 20                                       |..  |
  </code></pre>
  
  <hr>
  
  <p><em><strong>EDIT</em></strong><br>
  Here is the .list file</p>
  
  <pre><code>00000000 &lt;_start&gt;:
     0:   e59f0018    ldr r0, [pc, #24]   ; 20 &lt;loop$+0x4&gt;
     4:   e3a01001    mov r1, #1  ; 0x1
     8:   e1a01901    lsl r1, r1, #18
     c:   e5801004    str r1, [r0, #4]
    10:   e3a01001    mov r1, #1  ; 0x1
    14:   e1a01801    lsl r1, r1, #16
    18:   e5801028    str r1, [r0, #40]
  
  0000001c &lt;loop$&gt;:
    1c:   eafffffe    b   1c &lt;loop$&gt;
    20:   20200000    .word   0x20200000
  </code></pre>
  
  <p>If you reverse the endianess of the hexdump you see it lines up with the .list file.</p>
  
  <pre><code>e59f0018
  e3a01001
  e1a01901
  e5801004
  e3a01001
  e1a01801
  e5801028
  eafffffe
  20200000
  </code></pre>