STM32F0xx Standard Peripherals Firmware Library
|
STM32F0xx_StdPeriph_Examples/RCC/RCC_Example/main.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file RCC/RCC_Example/main.c 00004 * @author MCD Application Team 00005 * @version V1.4.0 00006 * @date 24-July-2014 00007 * @brief Main program body 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> 00012 * 00013 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00014 * You may not use this file except in compliance with the License. 00015 * You may obtain a copy of the License at: 00016 * 00017 * http://www.st.com/software_license_agreement_liberty_v2 00018 * 00019 * Unless required by applicable law or agreed to in writing, software 00020 * distributed under the License is distributed on an "AS IS" BASIS, 00021 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00022 * See the License for the specific language governing permissions and 00023 * limitations under the License. 00024 * 00025 ****************************************************************************** 00026 */ 00027 00028 /* Includes ------------------------------------------------------------------*/ 00029 #include "main.h" 00030 00031 /** @addtogroup STM32F0xx_StdPeriph_Examples 00032 * @{ 00033 */ 00034 00035 /** @addtogroup RCC_Example 00036 * @{ 00037 */ 00038 00039 /* Private typedef -----------------------------------------------------------*/ 00040 /* Private define ------------------------------------------------------------*/ 00041 /* Private macro -------------------------------------------------------------*/ 00042 /* Private variables ---------------------------------------------------------*/ 00043 /* Private function prototypes -----------------------------------------------*/ 00044 /* Private functions ---------------------------------------------------------*/ 00045 00046 /** 00047 * @brief Main program. 00048 * @param None 00049 * @retval None 00050 */ 00051 int main(void) 00052 { 00053 GPIO_InitTypeDef GPIO_InitStructure; 00054 NVIC_InitTypeDef NVIC_InitStructure; 00055 RCC_ClocksTypeDef RCC_ClockFreq; 00056 00057 /*!< At this stage the microcontroller clock setting is already configured, 00058 this is done through SystemInit() function which is called from startup 00059 file (startup_stm32f0xx.s) before to branch to application main. 00060 To reconfigure the default setting of SystemInit() function, refer to 00061 system_stm32f0xx.c file 00062 */ 00063 00064 /* Initialize Leds mounted on STM32072B-EVAL*/ 00065 STM_EVAL_LEDInit(LED3); 00066 STM_EVAL_LEDInit(LED4); 00067 00068 /* Turn on LED3 and LED4 */ 00069 STM_EVAL_LEDOn(LED3); 00070 STM_EVAL_LEDOn(LED4); 00071 00072 /* This function fills the RCC_ClockFreq structure with the current 00073 frequencies of different on chip clocks (for debug purpose) **************/ 00074 RCC_GetClocksFreq(&RCC_ClockFreq); 00075 00076 /* Enable Clock Security System(CSS): this will generate an NMI exception 00077 when HSE clock fails *****************************************************/ 00078 RCC_ClockSecuritySystemCmd(ENABLE); 00079 00080 /* Enable and configure RCC global IRQ channel, will be used to manage HSE ready 00081 and PLL ready interrupts. 00082 These interrupts are enabled in stm32f0xx_it.c file **********************/ 00083 #ifdef USE_STM320518_EVAL 00084 NVIC_InitStructure.NVIC_IRQChannel = RCC_IRQn; 00085 #else 00086 NVIC_InitStructure.NVIC_IRQChannel = RCC_CRS_IRQn; 00087 #endif /* USE_STM320518_EVAL */ 00088 NVIC_InitStructure.NVIC_IRQChannelPriority = 0; 00089 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 00090 NVIC_Init(&NVIC_InitStructure); 00091 00092 /* Output HSE clock on MCO1 pin(PA8) ****************************************/ 00093 /* Enable the GPIOA Clock */ 00094 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); 00095 00096 /* MCO pin configuration: PA8 */ 00097 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; 00098 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 00099 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; 00100 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; 00101 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; 00102 GPIO_Init(GPIOA, &GPIO_InitStructure); 00103 00104 GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_0); 00105 00106 /* Output System Clock on MCO pin */ 00107 #ifdef USE_STM320518_EVAL 00108 RCC_MCOConfig(RCC_MCOSource_SYSCLK); 00109 #else 00110 RCC_MCOConfig(RCC_MCOSource_SYSCLK, RCC_MCOPrescaler_1); 00111 #endif /* USE_STM320518_EVAL */ 00112 00113 while (1) 00114 { 00115 /* Toggle LED4 */ 00116 STM_EVAL_LEDToggle(LED4); 00117 00118 /* Insert a delay */ 00119 Delay(0x4FFFF); 00120 00121 /* Toggle LED3 */ 00122 STM_EVAL_LEDToggle(LED3); 00123 00124 /* Insert a delay */ 00125 Delay(0x3FFFF); 00126 } 00127 } 00128 00129 /** 00130 * @brief Inserts a delay time. 00131 * @param nCount: specifies the delay time length. 00132 * @retval None 00133 */ 00134 void Delay(__IO uint32_t nCount) 00135 { 00136 /* Decrement nCount value */ 00137 while (nCount != 0) 00138 { 00139 nCount--; 00140 } 00141 } 00142 00143 #ifdef USE_FULL_ASSERT 00144 00145 /** 00146 * @brief Reports the name of the source file and the source line number 00147 * where the assert_param error has occurred. 00148 * @param file: pointer to the source file name 00149 * @param line: assert_param error line source number 00150 * @retval None 00151 */ 00152 void assert_failed(uint8_t* file, uint32_t line) 00153 { 00154 /* User can add his own implementation to report the file name and line number, 00155 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 00156 00157 /* Infinite loop */ 00158 while (1) 00159 { 00160 } 00161 } 00162 #endif 00163 00164 /** 00165 * @} 00166 */ 00167 00168 /** 00169 * @} 00170 */ 00171 00172 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/