Hello,
I have bought the olimex stm32 development board. I am trying to use this with the tools included and the standard library from ST.
Now I am trying to use a output compare interupt on timer 2. The problem is that the functions in the file stm32f10x_it.c are not used.
When I define manually the vectors I can get the timer 2 interrupt but this is not developer friendly. So my question is how do I use the stm32f10x_it.c functions?
The code that is currently working:
#include "stm32f10x.h"
//Declarations
void nmi_handler(void);
void hardfault_handler(void);
int main(void);
void myDelay(unsigned long delay );
void Clk_Init (void);
void GPIO_Configuration(void);
void Init_USART2(void);
void NVIC_Configuration(void);
void unimplemented_handlertrap(void);
void TIM2_handler(void);
unsigned int * myvectors[76]
__attribute__ ((section("vectors")))= {
(unsigned int *) 0x20000800, // stack pointer
(unsigned int *) main, // code entry point
(unsigned int *) nmi_handler, // NMI handler
(unsigned int *) hardfault_handler, // hard fault handler
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) unimplemented_handlertrap, //unimplemented placeholder
(unsigned int *) TIM2_handler
};
// VARIABLES
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
uint16_t capture = 0;
// MAIN
int main(void)
{
// Init clock system
Clk_Init();
NVIC_Configuration();
GPIO_Configuration();
TIM_TimeBaseStructure.TIM_Period = 65535;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_PrescalerConfig(TIM2, 4, TIM_PSCReloadMode_Immediate);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 65535;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM2, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Disable);
TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);
TIM_Cmd(TIM2, ENABLE);
GPIOB->BSRR |= GPIO_Pin_5; //Green led off
while(1)
{
if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) != Bit_RESET)
{
GPIOC->BRR |= GPIO_Pin_12;
myDelay(500000);
}else{
GPIOC->BRR |= GPIO_Pin_12;
myDelay(500000);
GPIOC->BSRR |= GPIO_Pin_12;
myDelay(500000);
}
}
}
void nmi_handler(void)
{
GPIOB->BRR |= GPIO_Pin_5; //Green led
return ;
}
void hardfault_handler(void)
{
GPIOB->BRR |= GPIO_Pin_5; //Green led
return ;
}
//Functions definitions
void myDelay(unsigned long delay )
{
while(delay) delay--;
}
void Clk_Init (void)
{
SystemInit();
/* PCLK1 = HCLK/4 */
RCC_PCLK1Config(RCC_HCLK_Div16);
/* TIM2 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
// Configure PC.12 as output push-pull (LED)
GPIO_WriteBit(GPIOC,GPIO_Pin_12,Bit_SET);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
// Configure PB.00, PB.01, PB.05 as output push-pull (LED)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
// Configure PA.0 as input button (WAKE_UP)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
// Configure USART2 Rx (PA.3) as input floating
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// Configure USART2 Tx (PA.2) as alternate function push-pull
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void NVIC_Configuration(void)
{
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the TIM2 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void unimplemented_handlertrap(void)
{
GPIOB->BRR |= GPIO_Pin_5; //Green led
}
void TIM2_handler(void)
{
if (TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);
if(GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_0))
{
GPIOB->BRR |= GPIO_Pin_0;
GPIOB->BSRR |= GPIO_Pin_1;
}
else
{
GPIOB->BSRR |= GPIO_Pin_0;
GPIOB->BRR |= GPIO_Pin_1;
}
}
}
[/code]