STM8S/A Standard Peripherals Firmware Library
|
STM8S_StdPeriph_Examples/CLK/CLK_ClockSecuritySystem/main.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file CLK_ClockSecuritySystem\main.c 00004 * @author MCD Application Team 00005 * @version V2.2.0 00006 * @date 30-September-2014 00007 * @brief This file contains the main function for the CLK CSS example. 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 "stm8s.h" 00030 #include "stm8s_eval.h" 00031 00032 /** 00033 * @addtogroup CLK_ClockSecuritySystem 00034 * @{ 00035 */ 00036 00037 /* Private typedef -----------------------------------------------------------*/ 00038 /* Private define ------------------------------------------------------------*/ 00039 /* Private macro -------------------------------------------------------------*/ 00040 /* Private variables ---------------------------------------------------------*/ 00041 /* Private function prototypes -----------------------------------------------*/ 00042 static void CLK_Config(void); 00043 static void GPIO_Config(void); 00044 void Delay(uint16_t nCount); 00045 /* Private functions ---------------------------------------------------------*/ 00046 00047 /** 00048 * @brief Main program. 00049 * @param None 00050 * @retval None 00051 */ 00052 void main(void) 00053 { 00054 uint16_t i = 0; 00055 00056 /* Init GPIO for LED */ 00057 GPIO_Config(); 00058 00059 /* CLK configuration --------------------------------------------*/ 00060 CLK_Config(); 00061 00062 while (1) 00063 { 00064 /* Toggle the LEDs */ 00065 STM_EVAL_LEDToggle(LED1); 00066 STM_EVAL_LEDToggle(LED2); 00067 STM_EVAL_LEDToggle(LED3); 00068 STM_EVAL_LEDToggle(LED4); 00069 for (i = 0; i < 2; i++) 00070 { 00071 Delay((uint16_t)60000); 00072 } 00073 } 00074 } 00075 00076 /** 00077 * @brief Configure system clock to use HSE as source clock and to enable the 00078 * Clock Security System (CSS) 00079 * @param None 00080 * @retval None 00081 */ 00082 static void CLK_Config(void) 00083 { 00084 ErrorStatus status = ERROR; 00085 00086 CLK_DeInit(); 00087 00088 status = CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, 00089 CLK_CURRENTCLOCKSTATE_DISABLE); 00090 00091 /*Enable CSS interrupt */ 00092 CLK_ITConfig(CLK_IT_CSSD, ENABLE); 00093 00094 /* Enable CCS */ 00095 CLK_ClockSecuritySystemEnable(); 00096 00097 /* Output Fcpu on CLK_CCO pin */ 00098 CLK_CCOConfig(CLK_OUTPUT_MASTER); 00099 00100 enableInterrupts(); 00101 } 00102 00103 /** 00104 * @brief Configure GPIO for LEDs available on the evaluation board 00105 * @param None 00106 * @retval None 00107 */ 00108 static void GPIO_Config(void) 00109 { 00110 /* Initialize LEDs mounted on STM8-128 EVAL board */ 00111 STM_EVAL_LEDInit(LED1); 00112 STM_EVAL_LEDInit(LED2); 00113 STM_EVAL_LEDInit(LED3); 00114 STM_EVAL_LEDInit(LED4); 00115 } 00116 00117 /** 00118 * @brief Delay. 00119 * @param nCount 00120 * @retval None 00121 */ 00122 void Delay(uint16_t nCount) 00123 { 00124 /* Decrement nCount value */ 00125 while (nCount != 0) 00126 { 00127 nCount--; 00128 } 00129 } 00130 00131 00132 #ifdef USE_FULL_ASSERT 00133 00134 /** 00135 * @brief Reports the name of the source file and the source line number 00136 * where the assert_param error has occurred. 00137 * @param file: pointer to the source file name 00138 * @param line: assert_param error line source number 00139 * @retval None 00140 */ 00141 void assert_failed(uint8_t* file, uint32_t line) 00142 { 00143 /* User can add his own implementation to report the file name and line number, 00144 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 00145 00146 /* Infinite loop */ 00147 while (1) 00148 { 00149 } 00150 } 00151 #endif 00152 00153 /** 00154 * @} 00155 */ 00156 00157 00158 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/