Saturday, March 15, 2014

Turning on the LED at ZedBoard

The ZedBoard has many available leds, but the one of them can be accessed direct when you are in bare metal without any address translation. This tool can be very helpful specially if you debug the first steps of a new operating system and you don't have console output. The led belongs to the General Purpose I/O (GPIO) mechanism.

Here is an example of the code:

    asm volatile (
   "ldr     r7, =0xE000A204\n"
   "ldr     r8, =0x00000080\n"
   "str     r8,[r7],#4\n"
   "str     r8,[r7]\n"

   "ldr     r7, =0xE000A040\n"
   "ldr     r8, [r7]\n"
   "orr     r8, r8, #0x00000080\n"
   "str     r8,[r7]\n"

Of course someone can convert the code to the pure assembly, but again we have to use these addresses. The first part of the code set the register controls whether the IO pin is acting as an input or an output. Since the input logic is always enabled, this effectively enables/disables the output driver. Next we store again the same value 4 bytes later (note the #4). The second store is done in 0xE000A208 and sets output is enabled. The second store on 0xE000A040 controls the value being output when the GPIO signal is configured as an output. In this case i think a simple store with the value 0xFFFFFFFF can also work.

You can find more information about the control registers here.

No comments:

Post a Comment