Blink LED with timer
This commit is contained in:
113
build/main.i
113
build/main.i
@@ -1963,6 +1963,20 @@ extern intmax_t _wcstoimax_r(struct _reent *, const wchar_t *__restrict, wchar_t
|
||||
extern uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int);
|
||||
extern uintmax_t _wcstoumax_r(struct _reent *, const wchar_t *__restrict, wchar_t **__restrict, int);
|
||||
# 2 "src/main.c" 2
|
||||
# 1 "/nix/store/yr89i11mszv2az19r26l372zgaiivj1c-gcc-arm-embedded-12.3.rel1/lib/gcc/arm-none-eabi/12.3.1/include/stdbool.h" 1 3 4
|
||||
# 29 "/nix/store/yr89i11mszv2az19r26l372zgaiivj1c-gcc-arm-embedded-12.3.rel1/lib/gcc/arm-none-eabi/12.3.1/include/stdbool.h" 3 4
|
||||
#define _STDBOOL_H
|
||||
|
||||
|
||||
|
||||
#define bool _Bool
|
||||
|
||||
#define true ((_Bool)+1u)
|
||||
#define false ((_Bool)+0u)
|
||||
# 50 "/nix/store/yr89i11mszv2az19r26l372zgaiivj1c-gcc-arm-embedded-12.3.rel1/lib/gcc/arm-none-eabi/12.3.1/include/stdbool.h" 3 4
|
||||
#define __bool_true_false_are_defined 1
|
||||
# 3 "src/main.c" 2
|
||||
|
||||
# 1 "src/rcc.h" 1
|
||||
|
||||
#define RCC_H_
|
||||
@@ -2085,26 +2099,17 @@ struct rcc {
|
||||
|
||||
#define RCC_APB1ENR_PWREN_BIT 28
|
||||
#define RCC_APB1ENR_PWREN_CLOCK_ENABLE (1 << RCC_APB1ENR_PWREN_BIT)
|
||||
# 3 "src/main.c" 2
|
||||
|
||||
#define RCC_APB1ENR_TIM4_BIT 2
|
||||
#define RCC_APB1ENR_TIM4_ENABLE (1 << RCC_APB1ENR_TIM4_BIT)
|
||||
# 5 "src/main.c" 2
|
||||
# 1 "src/gpio.h" 1
|
||||
|
||||
#define GPIO_H_
|
||||
|
||||
# 1 "/nix/store/yr89i11mszv2az19r26l372zgaiivj1c-gcc-arm-embedded-12.3.rel1/lib/gcc/arm-none-eabi/12.3.1/include/stdbool.h" 1 3 4
|
||||
# 29 "/nix/store/yr89i11mszv2az19r26l372zgaiivj1c-gcc-arm-embedded-12.3.rel1/lib/gcc/arm-none-eabi/12.3.1/include/stdbool.h" 3 4
|
||||
#define _STDBOOL_H
|
||||
|
||||
|
||||
|
||||
#define bool _Bool
|
||||
|
||||
#define true ((_Bool)+1u)
|
||||
#define false ((_Bool)+0u)
|
||||
# 50 "/nix/store/yr89i11mszv2az19r26l372zgaiivj1c-gcc-arm-embedded-12.3.rel1/lib/gcc/arm-none-eabi/12.3.1/include/stdbool.h" 3 4
|
||||
#define __bool_true_false_are_defined 1
|
||||
# 5 "src/gpio.h" 2
|
||||
|
||||
|
||||
struct gpio {
|
||||
volatile uint32_t MODER;
|
||||
volatile uint32_t OTYPER;
|
||||
@@ -2143,7 +2148,7 @@ void gpio_write(uint16_t pin,
|
||||
_Bool
|
||||
# 40 "src/gpio.h"
|
||||
val);
|
||||
# 4 "src/main.c" 2
|
||||
# 6 "src/main.c" 2
|
||||
# 1 "src/flash.h" 1
|
||||
|
||||
#define FLASH_H_
|
||||
@@ -2177,7 +2182,7 @@ struct flash {
|
||||
#define FLASH_ACR_LATENCY_BIT 0
|
||||
#define FLASH_ACR_LATENCY_MASK (0b1111)
|
||||
#define FLASH_ACR_LATENCY(latency) ((latency & FLASH_ACR_LATENCY_MASK) << FLASH_ACR_LATENCY_BIT)
|
||||
# 5 "src/main.c" 2
|
||||
# 7 "src/main.c" 2
|
||||
# 1 "src/pwr.h" 1
|
||||
|
||||
#define PWR_H_
|
||||
@@ -2199,7 +2204,45 @@ struct pwr {
|
||||
#define PWR_CR_VOS_BIT 14
|
||||
#define PWR_CR_VOS_MASK (0b11)
|
||||
#define PWR_CR_VOS(scale) ((scale & PWR_CR_VOS_MASK) << PWR_CR_VOS_BIT)
|
||||
# 6 "src/main.c" 2
|
||||
# 8 "src/main.c" 2
|
||||
# 1 "src/timer.h" 1
|
||||
|
||||
#define TIMER_H_
|
||||
|
||||
|
||||
|
||||
struct timer {
|
||||
volatile uint32_t CR1;
|
||||
volatile uint32_t CR2;
|
||||
volatile uint32_t SMCR;
|
||||
volatile uint32_t DIER;
|
||||
volatile uint32_t SR;
|
||||
volatile uint32_t EGR;
|
||||
volatile uint32_t CCMR1;
|
||||
volatile uint32_t CCMR2;
|
||||
volatile uint32_t CCER;
|
||||
volatile uint32_t CNT;
|
||||
volatile uint32_t PSC;
|
||||
volatile uint32_t ARR;
|
||||
volatile uint32_t RCR;
|
||||
volatile uint32_t CCR1;
|
||||
volatile uint32_t CCR2;
|
||||
volatile uint32_t CCR3;
|
||||
volatile uint32_t CCR4;
|
||||
volatile uint32_t BDTR;
|
||||
volatile uint32_t DCR;
|
||||
volatile uint32_t DMAR;
|
||||
};
|
||||
|
||||
#define TIM4_BASE_ADDR (0x40000800U)
|
||||
#define TIM4 ((struct timer *) TIM4_BASE_ADDR)
|
||||
|
||||
#define TIM4_CR_CEN_BIT 0
|
||||
#define TIM4_ENABLE (1 << TIM4_CR_CEN_BIT)
|
||||
|
||||
void tim4_init(void);
|
||||
void tim4_start(void);
|
||||
# 9 "src/main.c" 2
|
||||
|
||||
#define exit 42
|
||||
|
||||
@@ -2267,29 +2310,33 @@ static void system_clock_init(void) {
|
||||
((struct rcc *) (0x40023800U))->CR &= ~(1 << 0);
|
||||
}
|
||||
|
||||
static inline void spin(volatile uint32_t count) {
|
||||
while (count--) (void) 0;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
(void) system_clock_init();
|
||||
(void) tim4_init();
|
||||
|
||||
(void) tim4_start();
|
||||
|
||||
uint16_t led = (((('C') - 'A') << 8) | 13);
|
||||
((struct rcc *) (0x40023800U))->AHB1ENR |= (1 << (led >> 8));
|
||||
gpio_set_mode(led, GPIO_MODE_OUTPUT);
|
||||
for (;;) {
|
||||
gpio_write(led,
|
||||
# 84 "src/main.c" 3 4
|
||||
((_Bool)+1u)
|
||||
# 84 "src/main.c"
|
||||
);
|
||||
spin(999999);
|
||||
gpio_write(led,
|
||||
# 86 "src/main.c" 3 4
|
||||
((_Bool)+0u)
|
||||
# 86 "src/main.c"
|
||||
);
|
||||
spin(999999);
|
||||
|
||||
uint16_t counter = ((struct timer *) (0x40000800U))->CNT;
|
||||
|
||||
# 87 "src/main.c" 3 4
|
||||
_Bool
|
||||
# 87 "src/main.c"
|
||||
led_on =
|
||||
# 87 "src/main.c" 3 4
|
||||
((_Bool)+0u)
|
||||
# 87 "src/main.c"
|
||||
;
|
||||
while(1) {
|
||||
if ((((struct timer *) (0x40000800U))->CNT - counter) >= 250) {
|
||||
led_on = !led_on;
|
||||
gpio_write(led, led_on);
|
||||
|
||||
counter = ((struct timer *) (0x40000800U))->CNT;
|
||||
}
|
||||
};
|
||||
|
||||
return 42;
|
||||
|
||||
Reference in New Issue
Block a user