Skip to content

Instantly share code, notes, and snippets.

@ftp27
Last active October 7, 2018 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ftp27/10401472 to your computer and use it in GitHub Desktop.
Save ftp27/10401472 to your computer and use it in GitHub Desktop.
Code for blinking led on board STM32L-Discovery
@olikraus
Copy link

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

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