~ruther/stm32-templates

ref: devices/stm32h747 stm32-templates/src/main.c -rw-r--r-- 1.1 KiB
229ffc40 — Rutherther feat: blinking leds on STM32H747I-DISCO 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdint.h>

#define PERIPHERAL_BASE (0x40000000U)
#define AHB4_BASE (PERIPHERAL_BASE + 0x18020000U)
#define GPIOI_BASE (AHB4_BASE + 0x2000U)
#define RCC_BASE (AHB4_BASE + 0x4400U)

#define RCC_AHB4ENR_OFFSET (0xE0U)
#define RCC_AHB4ENR ((volatile uint32_t*) (RCC_BASE + RCC_AHB4ENR_OFFSET))
#define RCC_AHB4ENR_GPIOIEN (0x08U)

#define GPIO_MODER_OFFSET (0x00U)
#define GPIOI_MODER ((volatile uint32_t*) (GPIOI_BASE + GPIO_MODER_OFFSET))
#define GPIO_MODER_MODER5 (10U)
#define GPIO_MODER_MODER13 (26U)
#define GPIO_MODER_MODER12 (24U)
#define GPIO_ODR_OFFSET (0x14U)
#define GPIOI_ODR ((volatile uint32_t*) (GPIOI_BASE + GPIO_ODR_OFFSET))

#define LED1_PIN 12
#define LED2_PIN 13

void main()
{
 *RCC_AHB4ENR |= (1 << RCC_AHB4ENR_GPIOIEN);

  // do two dummy reads after enabling the peripheral clock
  volatile uint32_t dummy;
  dummy = *(RCC_AHB4ENR);
  dummy = *(RCC_AHB4ENR);

  *GPIOI_MODER = (1 << GPIO_MODER_MODER12) | (1 << GPIO_MODER_MODER13);

  *GPIOI_ODR ^= (1 << LED2_PIN);
  while(1)
  {
    *GPIOI_ODR ^= (1 << LED1_PIN);
    *GPIOI_ODR ^= (1 << LED2_PIN);
    for (uint32_t i = 0; i < 2000000; i++);
  }
}