Вы находитесь на странице: 1из 10

Embedded Systems Programming with ARM on Linux Blinking LED

Pi19404
November 21, 2013

Contents

Contents
Embedded Systems Programming with ARM on Linux- Blinking LED 3

0.1 Introduction . . . . . . . . . . . . . . 0.2 Installations and Setup . . . . . . 0.2.1 Software Installations . 0.2.2 Setup . . . . . . . . . . . . . . 0.2.3 Programming the ARM GPIO Pins . . . . . . . . . . . 0.3 Code . . . . . . . . . . . . . . . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

3 3 4 4 8 9 9

2 | 10

Embedded Systems Programming with ARM on Linux- Blinking LED

Embedded Systems Programming with ARM on Linux- Blinking LED


0.1 Introduction
This article introduces the basic blinking LED program using ARM Cortex M4F microcontroller which is available on Stellaris LM4F232 board.The Host operating system is Ubuntu 12.04.

0.2 Installations and Setup

3 | 10

Embedded Systems Programming with ARM on Linux- Blinking LED

0.2.1 Software Installations


 Install Code Compose Studio IDE for coding and compliation. http://www.ti.com/tool/ccstudio  Install lm4flash tool for programming the microcontroller Clone the GIT repository https://github.com/utzig/lm4tools.git and build lm4flash binary by running the make file in the lm4tools/lm4flash directory You need libusb-dev package to compile this binary

 Download the stellarisware windows software http://www.ti. com/tool/sw-lm3s. Inflate the windows archive by unzipping the exe file. The examples for present board are located at $ARCHIVE_HOME/examples/boa lm4f232  Power the board using ICDI USB Cable from the PC,check if the board is detected . Run the lsusb command and check if Luminary Micro Inc is found

0.2.2 Setup
 Create a new project

(a) Code Composer Studio 1

4 | 10

Embedded Systems Programming with ARM on Linux- Blinking LED


 Add the following line in CCS Project Properties->Steps->PostBuildSteps dialog Refer figure 1b "$CCE_INSTALL_ROOT/utils/tiobj2bin/tiobj2bin" "$BuildArtifactFileName" "$BuildArtifactFileBaseName.bin" "$CG_TOOL_ROOT/bin/armofd" "$CG_TOOL_ROOT/bin/armhex" "$CCE_INSTALL_ROOT/utils/tiobj2bin/mkhex4bin" This will create a .bin file from .out file which will be used to program the microcontroller.

(b) Code Composer Studio 2

5 | 10

Embedded Systems Programming with ARM on Linux- Blinking LED


 in the Code Composer studio after creating the project set the Project Properties->Build->Processor option correctly,else it may lead to compilation error.

(c) Code Composer Studio 3

6 | 10

Embedded Systems Programming with ARM on Linux- Blinking LED


 In the code composer studio in Build->Include option add the path to the stellarisware inc directory which contains the header files for the microcontroller. item Once the program has been

(d) Code Composer Studio 4

compiled and .bin file is created in the build directory run the command lm4flash project1.bin to program the microcontroller.

7 | 10

Embedded Systems Programming with ARM on Linux- Blinking LED

0.2.3 Programming the ARM


 The first thing we require is the data sheet of the evaluation/development board Stellaris LM4F232 board. Check out the logical block diagrams to see what peripherals are connected to the board From the figure 1e we can see that the user LEDs is connect to the GPIO which means general purpose input output pins.

(e) Stellaris LM4F232 board Diagram

 The board contains one user LED.In this first example we will write a program to toggle this user LED one and off. We can find the detailed schematic at the end of the manual and figure 1f We can see that pin PG2 (pin 2 of port G is connected

8 | 10

Embedded Systems Programming with ARM on Linux- Blinking LED to the user LED)

(f) Stellaris LM4F232 :GPIO Pins

GPIO Pins The GPIO or general purpose input and output pins are easiest way to interact with peripherals like buttons,LEDs,switches and other components etc. The GPIO pins are controlled by the following registers.
 GPIODIR - DPIO direction register is used to configure each individual pins as input or output  GPIODATA - GPIO data allows for modification of data in individual GPIO registers without affecting the state of the other pins.  GPIODEN - GPIO Digital enable register,enables the use of GPIO pin as digital pin

These macros corresponding to registers can be found in lm4f232hqd.h header file found in StelarrisWare include Directory are GPIO_PORTG_DATA_R,GPIO_PORTG_DIR_R and GPIO_PORTG_DEN_R respectively.

0.3 Code
1 2 3 4 5 6 7

#include <stdint.h> #include "lm4f232h5qd.h" int main(void) { volatile uint32_t ui32Loop; // Enable the GPIO pin for the LED (PG2). Set the direction as output, and // enable the GPIO pin for digital function. //

9 | 10

Embedded Systems Programming with ARM on Linux- Blinking LED


8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

GPIO_PORTG_DIR_R = 0x04; GPIO_PORTG_DEN_R = 0x04; while(1) { // // Turn on the LED. // GPIO_PORTG_DATA_R |= 0x04; // // Delay for a bit. // for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++) { } // // Turn off the LED. // GPIO_PORTG_DATA_R &= ~(0x04); // // Delay for a bit. // for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++) { } } e code can also be found in GIT Repository rl{https://github.com/pi19404/m19404/tree/master/Embedded/blinkLED_ARM}

10 | 10

Вам также может понравиться