#include #include #define RCC_AHB1ENR_BIT_GPIODEN *(volatile uint32_t*)(0x42000000 + 0x00023830 * 32 + 3 * 4) #define GPIOD_BASE 0x40020C00 #define GPIOD_MODER *(volatile uint32_t*)(GPIOD_BASE + 0x00) #define GPIOD_ODR *(volatile uint32_t*)(GPIOD_BASE + 0x14) #define STK_CTRL *(volatile uint32_t*)(0xE000E010) #define STK_LOAD *(volatile uint32_t*)(0xE000E014) volatile bool flag = false; void SysTick_Handler() { flag = true; } int main(void) { // GPIO Port D Clock Enable RCC_AHB1ENR_BIT_GPIODEN = 1; // GPIO Port D Pin 15 down to 12 Push/Pull Output GPIOD_MODER = 0x55000000; // Set green and red LEDs GPIOD_ODR = 0x5000; // SysTick enable with interupt and clk source to AHB/8 STK_CTRL = (1<<1) | 1; STK_LOAD = 1000000; // 0.5 sec / (16 MHz / 8) // Do forever: while (1) { // Wait a moment while (!flag) { __asm__(" WFI"); // sleep until SysTick } flag = false; // Flip all LEDs GPIOD_ODR ^= 0xF000; } }