
/* Includes ------------------------------------------------------------------*/
#include "stm32f0xx.h"
#include "stm32f0xx_rcc.h"
#include "stm32f0xx_gpio.h"

GPIO_InitTypeDef        GPIO_InitStructure;

volatile uint32_t Milliseconds = 0, Seconds = 0;

void SysTick_Handler(void){
    Milliseconds++; //Increment millisecond variable
    if(Milliseconds%1000 == 999){ //If 1000 milliseconds have passed, increment seconds
        Seconds++;
    }
}

void DelayMil(uint32_t MilS){
      volatile uint32_t MSStart = Milliseconds;
      while( (Milliseconds - MSStart ) < MilS ) {
    	  GPIOA->ODR ^= GPIO_Pin_1;
      }
}

int main(void) {
  /* GPIOC Periph clock enable */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

  /* Configure PC8 and PC9 in output pushpull mode */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  SystemCoreClockUpdate();
  SysTick_Config(SystemCoreClock/1000);

  while (1) {
    GPIOA->ODR  ^= GPIO_Pin_0;

    /* Delay some time */
    //for(times = 0; times < 500000; times++);
    DelayMil(1000);
  }
}

