/** * @brief Configures the System clock frequency, HCLK, PCLK2 and PCLK1 * prescalers. * @param None * @retval None */ void SetSysClock(void) { /* The System clock configuration functions defined below assume that: - For Low, Medium and High density devices an external 8MHz crystal is used to drive the System clock. - For Connectivity line devices an external 25MHz crystal is used to drive the System clock. If you are using different crystal you have to adapt those functions accordingly.*/ #if defined SYSCLK_HSE SetSysClockToHSE(); #elif defined SYSCLK_FREQ_24MHz SetSysClockTo24(); #elif defined SYSCLK_FREQ_36MHz SetSysClockTo36(); #elif defined SYSCLK_FREQ_48MHz SetSysClockTo48(); #elif defined SYSCLK_FREQ_56MHz SetSysClockTo56(); #elif defined SYSCLK_FREQ_72MHz SetSysClockTo72(); #endif /* If none of the define above is enabled, the HSI is used as System clock source (default after reset) */ }
/** * @brief Configures the System clock frequency, HCLK, PCLK2 and PCLK1 * prescalers. * @param None. * @arg None. * @note : None. * @retval value: None. */ static void SetSysClock(void) { #ifdef SYSCLK_FREQ_HSE SetSysClockToHSE(); #elif defined SYSCLK_FREQ_20MHz SetSysClockTo20(); #elif defined SYSCLK_FREQ_36MHz SetSysClockTo36(); #elif defined SYSCLK_FREQ_48MHz SetSysClockTo48(); #elif defined SYSCLK_FREQ_56MHz SetSysClockTo56(); #elif defined SYSCLK_FREQ_72MHz SetSysClockTo72(); #endif /*!< If none of the define above is enabled, the HSI is used as System clock source (default after reset) */ }
/** * @brief Setup STM32 system (clocks, Ethernet, GPIO, NVIC) and STM3210C-EVAL resources. * @param None * @retval None */ void System_Setup(void) { /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ /* Set HSION bit */ RCC->CR |= (uint32_t)0x00000001; /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ RCC->CFGR &= (uint32_t)0xF0FF0000; /* Reset HSEON, CSSON and PLLON bits */ RCC->CR &= (uint32_t)0xFEF6FFFF; /* Reset HSEBYP bit */ RCC->CR &= (uint32_t)0xFFFBFFFF; /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ RCC->CFGR &= (uint32_t)0xFF80FFFF; /* Reset PLL2ON and PLL3ON bits */ RCC->CR &= (uint32_t)0xEBFFFFFF; /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x00FF0000; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000; SetSysClockTo72(); //SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ RCC_ClocksTypeDef RCC_Clocks; /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* Enable USART2 clock */ //RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); /* Enable ETHERNET clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ETH_MAC | RCC_AHBPeriph_ETH_MAC_Tx | RCC_AHBPeriph_ETH_MAC_Rx, ENABLE); /* Enable GPIOs and ADC1 clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE); /* Configure the GPIO ports */ GPIO_Configuration(); #ifdef USE_LCD /* Initialize the STM3210C-EVAL's LCD */ STM3210C_LCD_Init(); #endif // /* Initialize STM3210C-EVAL's LEDs */ // STM_EVAL_LEDInit(LED1); // STM_EVAL_LEDInit(LED2); // STM_EVAL_LEDInit(LED3); // STM_EVAL_LEDInit(LED4); // // /* Turn on leds available on STM3210X-EVAL */ // STM_EVAL_LEDOn(LED1); // STM_EVAL_LEDOn(LED2); // STM_EVAL_LEDOn(LED3); // STM_EVAL_LEDOn(LED4); #ifdef USE_LCD /* Clear the LCD */ LCD_Clear(Black); /* Set the LCD Back Color */ LCD_SetBackColor(Black); /* Set the LCD Text Color */ LCD_SetTextColor(White); /* Display message on the LCD*/ LCD_DisplayStringLine(Line0, MESSAGE1); LCD_DisplayStringLine(Line1, MESSAGE2); LCD_DisplayStringLine(Line2, MESSAGE3); LCD_DisplayStringLine(Line3, MESSAGE4); #endif /* SystTick configuration: an interrupt every 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); /* Configure the Key button */ //STM_EVAL_PBInit(Button_KEY, Mode_GPIO); }