Write a baremetal program C program for the CC3200 LAUNCHPAD
Write a bare-metal program C program for the CC3200 LAUNCHPAD that does the following:
- Initially all the LEDs are off.
- Turns the green LED when the user presses once on SW2 and displays the message “GREEN ON” once on the console.
- Turns the yellow LED if the green LED was previously on and the user pressed SW2 and displays the message “YELLOW ON” once on the console.
- Turns the red LED if the yellow LED was previously on and the user presses SW2 and displays the message “red ON” once on the console.
- Keeps the red LED on if the user continues to press SW2.
- Turns the yellow LED if the red LED was previously on and the user pressed SW3 and displays the message “YELLOW ON” once on the console.
- Turns the green LED if the yellow LED was previously on and the user pressed SW3 and displays the message “GREEN ON” once on the console.
- Keeps all the LEDs off if the user continues to press SW3
Solution
In order to set GPIO16 as an output then we need to write a value of 1 in the relevant bits of
the function select register. Here we can rely on the fact that this register is set to 0 after
a reset and so all we need to do is set:
So in order to light the LED we need to output a 0. We need to write a 1 to bit 16 in the CLEAR
register:
Putting what we’ve learnt into the minimal example above gives us a program that compiles and
links into an executable which should provide us with a Raspberry-Pi that lights the OK LED
when it is powered. Here’s the complete code we’ll compile:
part-1/armc-02
We now compile with the slightly modified compilation line:
The linker gives us a warning, which we’ll sort out later, but importantly the linker has resolved
the problem for us. This is the warning we’ll see and ignore:
As we can see from the compilation, the standard output is ELF format which is essentially an
executable wrapped with information that an OS may need to know. We need a binary ARM executable
that only includes machine code. We can extract this using the objcopy utility:
