1 | #include "stm32f4xx.h"
|
2 |
|
3 | void TIM1_UP_TIM10_IRQHandler(void) {
|
4 | TIM_ClearITPendingBit(TIM1, TIM_IT_Update);
|
5 | }
|
6 |
|
7 | int main(void) {
|
8 | GPIO_InitTypeDef gpioInit;
|
9 | TIM_TimeBaseInitTypeDef timTimeBaseInit;
|
10 | NVIC_InitTypeDef nvicInit;
|
11 |
|
12 | // PD12, PD13, PD14, PD15 = LEDs
|
13 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
|
14 | gpioInit.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
|
15 | gpioInit.GPIO_Mode = GPIO_Mode_OUT;
|
16 | gpioInit.GPIO_OType = GPIO_OType_PP;
|
17 | gpioInit.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
18 | gpioInit.GPIO_Speed = GPIO_Speed_100MHz;
|
19 | GPIO_Init(GPIOD, &gpioInit);
|
20 |
|
21 | // PA0 = button input
|
22 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
|
23 | gpioInit.GPIO_Pin = GPIO_Pin_0;
|
24 | gpioInit.GPIO_Mode = GPIO_Mode_IN;
|
25 | gpioInit.GPIO_OType = GPIO_OType_PP;
|
26 | gpioInit.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
27 | gpioInit.GPIO_Speed = GPIO_Speed_100MHz;
|
28 | GPIO_Init(GPIOA, &gpioInit);
|
29 |
|
30 |
|
31 | // TIM1 setup
|
32 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
|
33 | timTimeBaseInit.TIM_Prescaler = 0;
|
34 | timTimeBaseInit.TIM_CounterMode = TIM_CounterMode_Up;
|
35 | timTimeBaseInit.TIM_Period = 2532;
|
36 | timTimeBaseInit.TIM_ClockDivision = TIM_CKD_DIV1;
|
37 | timTimeBaseInit.TIM_RepetitionCounter = 0;
|
38 |
|
39 |
|
40 | nvicInit.NVIC_IRQChannel = TIM1_UP_TIM10_IRQn;
|
41 | nvicInit.NVIC_IRQChannelCmd = ENABLE;
|
42 | nvicInit.NVIC_IRQChannelPreemptionPriority = 0x0F;
|
43 | nvicInit.NVIC_IRQChannelSubPriority = 0x0F;
|
44 |
|
45 | TIM_TimeBaseInit(TIM1, &timTimeBaseInit);
|
46 | NVIC_Init(&nvicInit);
|
47 |
|
48 | TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);
|
49 | TIM_Cmd(TIM1, ENABLE);
|
50 |
|
51 |
|
52 | volatile uint32_t x = SystemCoreClock;
|
53 |
|
54 | while(1 > 0) {
|
55 | if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)) {
|
56 | GPIO_SetBits(GPIOD, GPIO_Pin_13);
|
57 | } else {
|
58 | GPIO_ResetBits(GPIOD, GPIO_Pin_13);
|
59 | }
|
60 | }
|
61 |
|
62 |
|
63 | }
|