Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code for blinking led on board STM32L-Discovery
@olikraus
Copy link

olikraus commented May 25, 2017

Thanks for this. I have published a systick based version here:
https://drolliblog.wordpress.com/2017/04/06/led-blink-with-the-stm32l031x6/

@stm32l152rc
Copy link

stm32l152rc commented Oct 7, 2018

can anyone please please correct my code because the led turns on but does not blink. I am using systick timer for i second delay.
thanks
k.arif4@hotmail.com

#include"stm32l1xx.h"

int main(void)

 {
RCC -> AHBENR |= RCC_AHBENR_GPIOBEN;
  GPIOB->MODER &= ~GPIO_MODER_MODER6;
  GPIOB->MODER |= GPIO_MODER_MODER6_0;
  GPIOB->OTYPER &= -(GPIO_OTYPER_OT_6);
  GPIOB->OSPEEDR &= ~GPIO_OSPEEDER_OSPEEDR6;
  GPIOB->PUPDR &= ~GPIO_PUPDR_PUPDR6;


    SysTick->LOAD = 319999;
    SysTick->VAL = 0;
    SysTick->CTRL = 5;

  while(1) {
     if (( SysTick->CTRL &= SysTick_CTRL_COUNTFLAG)==0)

      {
	        GPIOB -> BSRRL|= GPIO_BSRR_BS_6;   // turn led on
            SysTick->CTRL = 5;
       }
        else

       {
        	GPIOB ->BSRRH |= GPIO_BSRR_BR_6;

       }

    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment