Код: Выделить всё
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_tim.h"
#define TIMER_PRESCALER 720
uint16_t previousState;
GPIO_InitTypeDef port;
TIM_TimeBaseInitTypeDef timer;
void initAll()
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
GPIO_StructInit(&port);
port.GPIO_Mode = GPIO_Mode_OUT;
port.GPIO_Pin = GPIO_Pin_14;
port.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOB, &port);
TIM_TimeBaseStructInit(&timer);
timer.TIM_Prescaler = TIMER_PRESCALER;
timer.TIM_Period = 50;
TIM_TimeBaseInit(TIM4, &timer);
}
int main()
{
__enable_irq();
initAll();
TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM4, ENABLE);
NVIC_EnableIRQ(TIM4_IRQn); //<--- problem
while(1)
{
__NOP();
}
}
void TIM4_IRQHandler()
{
GPIO_SetBits(GPIOG, GPIO_Pin_14); //red led
if (previousState == 0)
{
previousState = 1;
timer.TIM_Period = 50;
TIM_TimeBaseInit(TIM4, &timer);
TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
}
else
{
previousState = 0;
timer.TIM_Period = 250;
TIM_TimeBaseInit(TIM4, &timer);
TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
}
}


