2015-09-14 04:36 AM
int main(){
/******************** SETUP OF CLOCKS ******************************/
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_OFF); //disable HSE oscilator
RCC_PLLCmd(DISABLE); // disable pll
RCC_HSICmd(ENABLE); // enable internal osc
RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_15);// PLL clock should be HSI /2 x 15 = 60MHZ
RCC_PLLCmd(ENABLE); // enable pll
/* Wait till PLL is ready */
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{ }
/* Select PLL as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */
while(RCC_GetSYSCLKSource() != 0x08)
{
}
/* Set HCLK, PCLK1, and PCLK2 to SCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK is = SYSCLK
RCC_PCLK1Config(RCC_HCLK_Div2); // PCLK is 30MHZ, and timer3 clk should be 2x PCLK ( 60 MHZ)
RCC_PCLK2Config(RCC_HCLK_Div2);
/******************* END OF CLOCKS SETUP **********************/
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/**** setup some clocks for timers and gpios *****/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3 | RCC_APB2Periph_GPIOB, ENABLE); // timer3 & GPIOB clocks - i expect it should be 60 MHZ since its 2xAPB1 clk, which is HCLK /2
/* setup GPIO for LEDs */
GPIO_InitStructure.GPIO_Pin = green | red ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//input pull up
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_SetBits(GPIOA, green); // just turn on the red LED
GPIO_SetBits(GPIOA, red); // just turn on the green Led
/* setup some GPIOs for logic analyzing */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//input pull up
GPIO_Init(GPIOB, &GPIO_InitStructure);
TIM_TimeBaseStructure.TIM_Prescaler = 1;
TIM_TimeBaseStructure.TIM_Period = 1;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =6;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 6;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_Cmd(TIM3, ENABLE); // Start the Timer
}
void TIM3_IRQHandler()
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
GPIO_ToggleBits(GPIOB, GPIO_Pin_2);
}
}
2015-09-14 04:49 AM
Do you set FLASH wait states adequately?
JW2015-09-14 06:44 AM