Skip to content

Instantly share code, notes, and snippets.

@JulioAlexanderAguilarAngulo
Created December 12, 2014 15:09
Show Gist options
  • Save JulioAlexanderAguilarAngulo/13d1754b45c37b7aff59 to your computer and use it in GitHub Desktop.
Save JulioAlexanderAguilarAngulo/13d1754b45c37b7aff59 to your computer and use it in GitHub Desktop.
STM32 Tutorial 001a: Blinking a led
/*************************************** STM32 Tutorial v.2015
Authors: Julio Alexander Aguilar Angulo. [email protected]
Elodie Pauly. [email protected]
(c) ISEN-TOULON. 2015. www.isen.fr
*******************************************************************************/
/**** Tuto 01a: Blinking a LED (and using registers and bit masking )**********/
/******************************************************************************/
#include "stm32l1xx.h" // prototypes and intrinsic declarations
/* Testboard: STM32L152 NUCLEO */
/**** Hardware to use on this Tutorial: Onboard USER LED ( on PA5 ) **********/
#define LED 1<<5; // Mask to map that LED
/*** Variable declarations ************************************************/
int i;
/* Private function prototypes -----------------------------------------------*/
void Initsyst(void);
/* Code Starts Here!! ********************************************************/
/* note: iar internals configure the system clock to 32 MHz */
void main()
{
Initsyst();
GPIOA->ODR &= ~LED;// turn off led as initial condition
while (1)
{
GPIOA->ODR^=LED; // blink the led
for(i=0;i<=100000;i++) // Software Delay
{
}
}
}
/***** Private Functions Definition **********************************/
void Initsyst(void)
{
RCC->AHBENR|=0x01;// affect clock to GPIOA
GPIOA->MODER|=0x5555;// output mode
GPIOA->OTYPER&=0x0000; // push pull
GPIOA->OSPEEDR|=0xFFFF;// High speed out
GPIOA->PUPDR&=0x0000; // no pullup
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment