cancel
Showing results for 
Search instead for 
Did you mean: 

LED blink Performancestick

ev64bug
Associate II
Posted on October 28, 2008 at 11:39

LED blink Performancestick

6 REPLIES 6
ev64bug
Associate II
Posted on May 17, 2011 at 12:48

Does anyone have a simple example of an LED blink for the Performance Stick? I'm just looking for a simple piece of code in C that initializes the I/O without the libraries. I tend to avoid the libraries and roll my own code and this is the best way for me to get started.

ev64bug
Associate II
Posted on May 17, 2011 at 12:48

Since I haven't had any responses from the forum I thought I would post an example I wrote for the LM3S317 from Luminary micro. The ST micro reference manual doesn't give a procedure for initializing peripherals so I'm looking for an example.

/ LEDblink.c for the LM3S317

//Declare functions

int main(void);

void dummy_handler(void);

void isrPWM0(void);

//Define the vector table

__attribute__ ((section(''vectors'')))

int const VectorStackTop = 0x20000800; // Exception 0, Starting value of MSP

__attribute__ ((section(''vectors'')))

int (* const VectorMain) (void) = main; // Exception 1, Reset

__attribute__ ((section(''vectors'')))

int (* const VectorMNI) (void) = main; // Exception 2, NMI

__attribute__ ((section(''vectors'')))

void (* const VectorArray[]) (void) =

{

dummy_handler, // Exception 3, hard fault

dummy_handler, // Exception 4, MemManage fault

dummy_handler // Exception 5, Bus fault

};

//Dummy Handler

void dummy_handler(void)

{

return;

}

//*****************************************************************************

// Declarations

//*****************************************************************************

// Macro for Register access

#define HWREG(x) (*((volatile unsigned long *)(x)))

// System Control Registers

#define SYSCTL_BASE 0x400FE000 //Base address

#define RCGC2 HWREG(SYSCTL_BASE+0x0108)

// GPIO Registers

#define GPIOD 1<

#define GPIO_PORTD 0x40007000

#define GPIODATA_OFFSET 0x03FC //Data for 255 <

#define GPIODIR_OFFSET 0x0400

#define GPIODEN_OFFSET 0x051C

#define PDDATA HWREG(GPIO_PORTD+GPIODATA_OFFSET)

#define PDDIR HWREG(GPIO_PORTD+GPIODIR_OFFSET)

#define PDDEN HWREG(GPIO_PORTD+GPIODEN_OFFSET)

//Port Pins

#define P2 1<

//*****************************************************************************

// Initialize LED

//*****************************************************************************

void initLED (void)

{

RCGC2 |=GPIOD; //Enable Port D clocking

PDDIR |=P2; //Port D pin 2 output

PDDEN |=P2; //Port D pin 2 digital enable

}

//*****************************************************************************

// LED on

//*****************************************************************************

void LEDon (void)

{

PDDATA &= (~P2);

}

//*****************************************************************************

// LED off

//*****************************************************************************

void LEDoff (void)

{

PDDATA |=P2;

}

//*****************************************************************************

// Main

//*****************************************************************************

int main(void)

{

volatile unsigned long ulLoop;

initLED(); //Set up LED port

while(1)

{

for(ulLoop = 0; ulLoop < 0x10000; ulLoop++)

{

}

LEDon();

for(ulLoop = 0; ulLoop < 0x10000; ulLoop++)

{

}

LEDoff();

}

}

abraxa
Associate II
Posted on May 17, 2011 at 12:48

Well, I'd say it has to do with the fact that you specifically asked for code that does not make use of the libraries. If there's a library that makes life easier for you - why not use it?

ev64bug
Associate II
Posted on May 17, 2011 at 12:48

The short answer:

I'm concerned with the ''how'' not the ''why''

The long answer:

There was a thread a while back about a guy that wanted to write in assembly. I've only evolved one step beyond this person in that I use C to get away from the mechanics of assembly language and to make my code a little more readable. But I still come from an assembly code and hardware design background and I like to have control over the mcu at the register level.

paulsmitton9
Associate III
Posted on May 17, 2011 at 12:48

I don't know what port the performance stick led is on, or whether it is push-pull or open-drain, but this (untested code) ought to toggle PB10 in push-pull mode.

typedef unsigned long u32;

#define RCC_ABP2ENR *((u32*)0x40021018)

#define GPIOB_CRH *((u32*)0x40010C04)

#define GPIOB_ODR *((u32*)0x40010C0C)

int main(void)

{

RCC_ABP2ENR |= 0x8; // enable GPIOB in RCC_ABP2ENR

GPIOB_CRH = 0x00000300; // set PB10 to output push pull

u32 Delay;

while(1)

{

GPIOB_ODR = (1 << 10); // turn on PB10 in GPIOB_ODR

for (Delay = 0; Delay < 500000; Delay++);

GPIOB_ODR = 0; // turn off PB10 in GPIOB_ODR

for (Delay = 0; Delay < 500000; Delay++);

}

}

[ This message was edited by: paul.smitton on 28-10-2008 09:56 ]

ev64bug
Associate II
Posted on May 17, 2011 at 12:48

That is very helpful.

Thanks!