STM8S/A Standard Peripherals Firmware Library: main.c Source File

STM8S/A

STM8S_StdPeriph_Examples/CLK/CLK_MaxSpeed/main.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    CLK_MaxSpeed\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 Maximum Speed 
00008   *          configuration example.
00009   ******************************************************************************
00010   * @attention
00011   *
00012   * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
00013   *
00014   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00015   * You may not use this file except in compliance with the License.
00016   * You may obtain a copy of the License at:
00017   *
00018   *        http://www.st.com/software_license_agreement_liberty_v2
00019   *
00020   * Unless required by applicable law or agreed to in writing, software 
00021   * distributed under the License is distributed on an "AS IS" BASIS, 
00022   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00023   * See the License for the specific language governing permissions and
00024   * limitations under the License.
00025   *
00026   ******************************************************************************
00027   */ 
00028 
00029 /* Includes ------------------------------------------------------------------*/
00030 #include "stm8s.h"
00031 #include "stm8s_eval.h"
00032 
00033 /**
00034   * @addtogroup CLK_MaxSpeed
00035   * @{
00036   */
00037 
00038 /* Private typedef -----------------------------------------------------------*/
00039 /* Private define ------------------------------------------------------------*/
00040 /* Private macro -------------------------------------------------------------*/
00041 /* Private variables ---------------------------------------------------------*/
00042 /* Public functions ----------------------------------------------------------*/
00043 /* Global variables ----------------------------------------------------------*/
00044 bool ButtonPressed = FALSE;
00045 /* Private function prototypes -----------------------------------------------*/
00046 static void GPIO_Config(void);
00047 static void CLK_Config(void);
00048 /* Private functions ---------------------------------------------------------*/
00049 
00050 /**
00051   * @brief  Main program.
00052   * @param  None
00053   * @retval None
00054   */
00055 void main(void)
00056 {
00057     /* GPIO Configuration  -----------------------------------------*/
00058     GPIO_Config();  
00059     
00060     /* Clock configuration -----------------------------------------*/
00061     CLK_Config();    
00062     
00063     while (1)
00064     {
00065     }
00066 }
00067 
00068 /**
00069   * @brief  Configure GPIO for button available on the evaluation board
00070   * @param  None
00071   * @retval None
00072   */
00073 static void GPIO_Config(void)
00074 {
00075   /* Configure GPIO used to drive KEY button */
00076     STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);
00077     
00078     /* Enable general interrupts */
00079     enableInterrupts();    
00080 }
00081 
00082 /**
00083   * @brief  Configure system clock to run at Maximum clock speed and output the 
00084   *         system clock on CCO pin
00085   * @param  None
00086   * @retval None
00087   */
00088 static void CLK_Config(void)
00089 {
00090     ErrorStatus status = FALSE;
00091 
00092     CLK_DeInit();
00093 
00094     /* Configure the Fcpu to DIV1*/
00095     CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
00096     
00097     /* Configure the HSI prescaler to the optimal value */
00098     CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
00099 
00100     /* Output Fcpu on CLK_CCO pin */
00101     CLK_CCOConfig(CLK_OUTPUT_CPU);
00102         
00103     /* Configure the system clock to use HSE clock source and to run at 24Mhz */
00104     status = CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
00105     
00106     while (ButtonPressed == FALSE)
00107     {
00108     }
00109     /* Configure the system clock to use HSI clock source and to run at 16Mhz */
00110     status = CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
00111 }
00112 
00113 #ifdef USE_FULL_ASSERT
00114 
00115 /**
00116   * @brief  Reports the name of the source file and the source line number
00117   *   where the assert_param error has occurred.
00118   * @param file: pointer to the source file name
00119   * @param line: assert_param error line source number
00120   * @retval None
00121   */
00122 void assert_failed(uint8_t* file, uint32_t line)
00123 { 
00124   /* User can add his own implementation to report the file name and line number,
00125      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00126 
00127   /* Infinite loop */
00128   while (1)
00129   {
00130   }
00131 }
00132 #endif
00133 
00134 /**
00135   * @}
00136   */
00137 
00138 
00139 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM8 Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM8 8-bit Microcontrollers platform visit www.st.com