#include "stm32f4xx.h" #include "stm32f4xx_rcc.c" #include "stm32f4xx_gpio.c" #include "stm32f4xx_tim.c" #include "dd.h" // initialize port E, Gpio_Pin_8 to GPIO_Pin_15 as outputs void GPIOEinit (void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11; GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOE, &GPIO_InitStructure); } // Timer 5 init function - time base void TIM5init_TimeBase_ReloadIRQ (int interval) { TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE); TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInitStructure.TIM_Period = interval; TIM_TimeBaseInitStructure.TIM_Prescaler = 0; TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM5, &TIM_TimeBaseInitStructure); NVIC_EnableIRQ(TIM5_IRQn); // Enable IRQ for TIM5 in NVIC TIM_ITConfig(TIM5, TIM_IT_Update, ENABLE); // Enable IRQ on update for Timer5 TIM_Cmd(TIM5, ENABLE); } void main(void) { GPIOEinit (); TIM5init_TimeBase_ReloadIRQ (84000); // 84000 == 1ms while (1) {}; } // IRQ function for Timer5 void TIM5_IRQHandler(void) { int i; TIM_ClearITPendingBit(TIM5, TIM_IT_Update); // clear interrupt flag GPIOE->ODR |= BIT_8; for (i=0; i<10; i++) {}; GPIOE->ODR &= ~BIT_8; for (i=0; i<10; i++) {}; GPIOE->ODR |= BIT_8; for (i=0; i<10; i++) {}; GPIOE->ODR &= ~BIT_8; }