Здравствуйте, господа. Запускаю на STM32F4Discovery следующую программу:
#include "stm32f4xx.h"
int main()
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_ResetBits(GPIOD, GPIO_Pin_15);
/*
HCLK: 168 MHz
APB1 Prescaler: 4 => CK_PSC = 2 * 42 MHz = 84 MHz
*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
TIM_TimeBaseStructure.TIM_Prescaler = 84 - 1; // CK_CNT = 1 MHz
TIM_TimeBaseStructure.TIM_Period = 1000 - 1; // CK_CNT / 1000 = 1 kHz
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
TIM_ARRPreloadConfig(TIM5, ENABLE);
TIM_ITConfig(TIM5, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM5, ENABLE);
NVIC_EnableIRQ(TIM5_IRQn);
while (1) { }
}
void TIM5_IRQHandler()
{
if (TIM_GetITStatus(TIM5, TIM_IT_Update) == SET){
TIM_ClearITPendingBit(TIM5, TIM_IT_Update);
GPIO_ToggleBits(GPIOD, GPIO_Pin_15);
}
}