blinky.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #if defined STM32L0
  2. #include <stm32l0xx_ll_gpio.h>
  3. #include <stm32l0xx_ll_cortex.h>
  4. #include <stm32l0xx_ll_rcc.h>
  5. // STM32L0538-Discovery green led - PB4
  6. #define LED_PORT GPIOB
  7. #define LED_PIN LL_GPIO_PIN_4
  8. #define LED_PORT_CLK_ENABLE() { RCC->IOPENR |= RCC_IOPENR_GPIOBEN; }
  9. #elif defined STM32F1
  10. #include <stm32f1xx_ll_gpio.h>
  11. #include <stm32f1xx_ll_cortex.h>
  12. #include <stm32f1xx_ll_rcc.h>
  13. // STM32VL-Discovery green led - PC9
  14. #define LED_PORT GPIOC
  15. #define LED_PIN LL_GPIO_PIN_9
  16. #define LED_PORT_CLK_ENABLE() { RCC->APB2ENR |= RCC_APB2ENR_IOPCEN; }
  17. #elif defined STM32F4
  18. #include <stm32f4xx_ll_gpio.h>
  19. #include <stm32f4xx_ll_cortex.h>
  20. #include <stm32f4xx_ll_rcc.h>
  21. // STM32F4-Discovery green led - PD12
  22. #define LED_PORT GPIOD
  23. #define LED_PIN LL_GPIO_PIN_12
  24. #define LED_PORT_CLK_ENABLE() { RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN; }
  25. #endif
  26. void SysTick_Handler(void)
  27. {
  28. static int counter = 0;
  29. counter++;
  30. // 1 Hz blinking
  31. if ((counter % 500) == 0)
  32. LL_GPIO_TogglePin(LED_PORT, LED_PIN);
  33. }
  34. void initGPIO()
  35. {
  36. LED_PORT_CLK_ENABLE();
  37. LL_GPIO_SetPinMode(LED_PORT, LED_PIN, LL_GPIO_MODE_OUTPUT);
  38. LL_GPIO_SetPinOutputType(LED_PORT, LED_PIN, LL_GPIO_OUTPUT_PUSHPULL);
  39. }
  40. int main(void)
  41. {
  42. initGPIO();
  43. // 1kHz ticks
  44. SystemCoreClockUpdate();
  45. SysTick_Config(SystemCoreClock / 1000);
  46. while(1);
  47. return 0;
  48. }