u8g2-copy/sys/arm/stm32l011x4/blink/main.c

42 lines
1.0 KiB
C
Raw Normal View History

2018-10-08 02:19:08 +08:00
/*
LED blink project for the STM32L011
Assumes LED at Pin 6, GPIO PA0
*/
2018-10-08 01:31:45 +08:00
2018-10-12 21:33:54 +08:00
#include "stm32l011xx.h"
2018-10-08 01:31:45 +08:00
volatile unsigned long SysTickCount = 0;
void __attribute__ ((interrupt, used)) SysTick_Handler(void)
{
SysTickCount++;
2018-10-08 02:19:08 +08:00
2018-10-08 01:31:45 +08:00
if ( SysTickCount & 1 )
2018-10-08 02:19:08 +08:00
GPIOA->BSRR = GPIO_BSRR_BS_0; /* atomic set PA0 */
2018-10-08 01:31:45 +08:00
else
2018-10-08 02:19:08 +08:00
GPIOA->BSRR = GPIO_BSRR_BR_0; /* atomic clr PA0 */
2018-10-08 01:31:45 +08:00
}
int main()
{
RCC->IOPENR |= RCC_IOPENR_IOPAEN; /* Enable clock for GPIO Port A */
__NOP();
__NOP();
2018-10-08 02:19:08 +08:00
GPIOA->MODER &= ~GPIO_MODER_MODE0; /* clear mode for PA0 */
GPIOA->MODER |= GPIO_MODER_MODE0_0; /* Output mode for PA0 */
GPIOA->OTYPER &= ~GPIO_OTYPER_OT_0; /* no Push/Pull for PA0 */
GPIOA->OSPEEDR &= ~GPIO_OSPEEDER_OSPEED0; /* low speed for PA0 */
GPIOA->PUPDR &= ~GPIO_PUPDR_PUPD0; /* no pullup/pulldown for PA0 */
GPIOA->BSRR = GPIO_BSRR_BR_0; /* atomic clr PA0 */
2018-10-08 01:31:45 +08:00
SysTick->LOAD = 2000*500 - 1;
SysTick->VAL = 0;
SysTick->CTRL = 7; /* enable, generate interrupt (SysTick_Handler), do not divide by 2 */
for(;;)
;
}