#include #define LED2 GPIO_Pin_9 /* Pin 9 */ #define LED_Port GPIOB /* PORTB */ GPIO_InitTypeDef GPIO_InitStructure; ErrorStatus HSEStartUpStatus; /* Private function prototypes -----------------------------------------------*/ void RCC_Configuration(void); void NVIC_Configuration(void); void GPIO_Configuration(void); void Delay (uint32_t cas) { for( ;cas>0;cas--) { asm("nop"); } } /******************************************************************************* * Function Name : main * Description : Main program. * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { /* Configure the system clocks */ RCC_Configuration(); /* NVIC Configuration */ NVIC_Configuration(); /* GPIO configuration */ GPIO_Configuration(); /*--------------------------------------------------------------------------------------------*/ while(1) { GPIO_WriteBit(LED_Port, LED2, Bit_RESET); Delay(500000); GPIO_WriteBit(LED_Port, LED2, Bit_SET); Delay(500000); /*---------------------------------------------------------------------------------------------*/ } } /******************************************************************************* * Function Name : RCC_Configuration * Description : Configures the different system clocks. * Input : None * Output : None * Return : None *******************************************************************************/ void RCC_Configuration(void) { /* RCC system reset(for debug purpose) */ RCC_DeInit(); /* Enable HSE - externí krystal 8MHz */ RCC_HSEConfig(RCC_HSE_ON); /* Wait till HSE is ready - cekání na stabilizaci oscilátoru*/ HSEStartUpStatus = RCC_WaitForHSEStartUp(); if(HSEStartUpStatus == SUCCESS) /* HSE OK*/ { /* HCLK = SYSCLK AHB = 72MHz */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK/2 APB2 = 72MHz/2 = 36MHz */ RCC_PCLK2Config(RCC_HCLK_Div2); /* PCLK1 = HCLK/2 APB1 = 72MHz/2 = 36MHz */ RCC_PCLK1Config(RCC_HCLK_Div2); /* ADCCLK = PCLK2/2 casovani pro ADprevod */ RCC_ADCCLKConfig(RCC_PCLK2_Div4); // ADCCLK = 36MHz/4 = 9MHz /* Flash 2 wait state */ FLASH_SetLatency(FLASH_Latency_2); /* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); /* PLLCLK = (8MHz/1)* 9 = 72MHz */ RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_9); /* Enable PLL */ RCC_PLLCmd(ENABLE); /* 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){} } /* Enable GPOIA, Enable GPOIB, Enable GPOIC */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB , ENABLE); } /******************************************************************************* * Function Name : GPIO_Configuration * Description : Configures the different GPIO ports. * Input : None * Output : None * Return : None *******************************************************************************/ void GPIO_Configuration(void) { //GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE); /* Configure as output push-pull */ /*LED on board*/ GPIO_InitStructure.GPIO_Pin = LED2; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(LED_Port, &GPIO_InitStructure); } /******************************************************************************* * Function Name : NVIC_Configuration * Description : Configures Vector Table base location. * Input : None * Output : None * Return : None *******************************************************************************/ void NVIC_Configuration(void) { #ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif } /******************************* END ******************************************/