cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L_Discovery Blinking LEDS

chuck_moore
Associate II
Posted on August 21, 2013 at 09:12

I have an STM32L-Discovery Board, I found this program compiled it and loaded it on my board but nothing happens.  What am I miising..  Thanks in Advanced. 

CM.

GPIO_InitTypeDef (GPIO_InitStructure);

int main() {

GPIO_InitTypeDef ledInit;

long i = 0;

  // enable the GPIOB peripheral

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; // 

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //  push-pull output 

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; 

GPIO_Init (GPIOB, & GPIO_InitStructure); // B port 

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; //

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //  push-pull output 

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; 

GPIO_Init (GPIOB, & GPIO_InitStructure); // B port 

  // configure pins 6 and 7 as GPIO output

ledInit.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_6;

ledInit.GPIO_Mode = GPIO_Mode_OUT;

  // initialize the peripheral

GPIO_Init(GPIOB, &ledInit);

  // turn pins 6 and 7 on

GPIO_SetBits(GPIOB, GPIO_Pin_7 | GPIO_Pin_6);

  // loop forever

for (;;) {

           // toggle pins 6 and 7

           

   

GPIOB->BSRRL = GPIO_Pin_7; 

        GPIOB->BSRRH = GPIO_Pin_7;

      GPIOB->BSRRL = GPIO_Pin_6;

           GPIOB->BSRRH = GPIO_Pin_6;

// waste time

       for (i=0; i<25000; i++);

     return 0;

       }
4 REPLIES 4
Posted on August 21, 2013 at 09:30

In fact, the LED blink, but you can't see it.

This

   

GPIOB->BSRRL = GPIO_Pin_7; 

        GPIOB->BSRRH = GPIO_Pin_7;

sets then resets PB.7 in rapid succession, producing a very short pulse on it. The same in the following two lines for PB.6. You won't see the LED to blink for a fraction of microsecond.

(Also, get rid of the second initialization of the GPIO)

JW

ran2
Associate III
Posted on August 21, 2013 at 17:04

Hi, Jan is right.

Try this:

GPIOB->BSRRL = GPIO_Pin_7;

       for (i=0; i<25000; i++);

        GPIOB->BSRRH = GPIO_Pin_7;

 

GPIOB->BSRRL = GPIO_Pin_6;

                for (i=0; i<25000; i++);

               GPIOB->BSRRH = GPIO_Pin_6;

chuck_moore
Associate II
Posted on August 21, 2013 at 19:44

You guys Rock :)...  This works for the STM32L-Discovery Boards compiled with Keil..

Not sure why this isn't in the SDK Project files...  Again many thanks for you quick response.

Chuck

Posted on August 21, 2013 at 23:51

I'd recommend looking at both the L1 Discovery examples, and those in the L1 Firmware Library. While the latter is targeting the EVAL series boards, it is still useful.

See also \Keil\ARM\Boards\ST\STM32L-Discovery\Blinky\Blinky.c

and examples posted to the forum.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..