STM32F0xx Standard Peripherals Firmware Library: main.c Source File

STM32F0xx Standard Peripherals Library

STM32F0xx_StdPeriph_Examples/SysTick/SysTick_Example/main.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    SysTick/SysTick_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>&copy; 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 SysTick_Example
00036   * @{
00037   */ 
00038 
00039 /* Private typedef -----------------------------------------------------------*/
00040 /* Private define ------------------------------------------------------------*/
00041 /* Private macro -------------------------------------------------------------*/
00042 /* Private variables ---------------------------------------------------------*/
00043 GPIO_InitTypeDef GPIO_InitStructure;
00044 static __IO uint32_t TimingDelay;
00045 
00046 /* Private function prototypes -----------------------------------------------*/
00047 void Delay(__IO uint32_t nTime);
00048 
00049 /* Private functions ---------------------------------------------------------*/
00050 
00051 /**
00052   * @brief   Main program
00053   * @param  None
00054   * @retval None
00055   */
00056 int main(void)
00057 {
00058   /*!< At this stage the microcontroller clock setting is already configured, 
00059        this is done through SystemInit() function which is called from startup
00060        file (startup_stm32f0xx.s) before to branch to application main.
00061        To reconfigure the default setting of SystemInit() function, refer to
00062        system_stm32f0xx.c file
00063      */     
00064        
00065   /* Initialize Leds mounted on STM320518-EVAL board */
00066   STM_EVAL_LEDInit(LED1);
00067   STM_EVAL_LEDInit(LED2);
00068   STM_EVAL_LEDInit(LED3);
00069   STM_EVAL_LEDInit(LED4);
00070 
00071   /* Turn on LED1 and LED3 */
00072   STM_EVAL_LEDOn(LED1);
00073   STM_EVAL_LEDOn(LED3);
00074 
00075   /* Setup SysTick Timer for 1 msec interrupts.
00076      ------------------------------------------
00077     1. The SysTick_Config() function is a CMSIS function which configure:
00078        - The SysTick Reload register with value passed as function parameter.
00079        - Configure the SysTick IRQ priority to the lowest value (0x0F).
00080        - Reset the SysTick Counter register.
00081        - Configure the SysTick Counter clock source to be Core Clock Source (HCLK).
00082        - Enable the SysTick Interrupt.
00083        - Start the SysTick Counter.
00084     
00085     2. You can change the SysTick Clock source to be HCLK_Div8 by calling the
00086        SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8) just after the
00087        SysTick_Config() function call. The SysTick_CLKSourceConfig() is defined
00088        inside the misc.c file.
00089 
00090     3. You can change the SysTick IRQ priority by calling the
00091        NVIC_SetPriority(SysTick_IRQn,...) just after the SysTick_Config() function 
00092        call. The NVIC_SetPriority() is defined inside the core_cm0.h file.
00093 
00094     4. To adjust the SysTick time base, use the following formula:
00095                             
00096          Reload Value = SysTick Counter Clock (Hz) x  Desired Time base (s)
00097     
00098        - Reload Value is the parameter to be passed for SysTick_Config() function
00099        - Reload Value should not exceed 0xFFFFFF
00100    */
00101   if (SysTick_Config(SystemCoreClock / 1000))
00102   { 
00103     /* Capture error */ 
00104     while (1);
00105   }
00106 
00107   while (1)
00108   {
00109     /* Toggle LED2 and LED4 */
00110     STM_EVAL_LEDToggle(LED2);
00111     STM_EVAL_LEDToggle(LED4);
00112 
00113     /* Insert 50 ms delay */
00114     Delay(50);
00115 
00116     /* Toggle LED1 and LED3 */
00117     STM_EVAL_LEDToggle(LED1);
00118     STM_EVAL_LEDToggle(LED3);
00119 
00120     /* Insert 100 ms delay */
00121     Delay(100);
00122   }
00123 }
00124 
00125 /**
00126   * @brief  Inserts a delay time.
00127   * @param  nTime: specifies the delay time length, in milliseconds.
00128   * @retval None
00129   */
00130 void Delay(__IO uint32_t nTime)
00131 { 
00132   TimingDelay = nTime;
00133 
00134   while(TimingDelay != 0);
00135 }
00136 
00137 /**
00138   * @brief  Decrements the TimingDelay variable.
00139   * @param  None
00140   * @retval None
00141   */
00142 void TimingDelay_Decrement(void)
00143 {
00144   if (TimingDelay != 0x00)
00145   { 
00146     TimingDelay--;
00147   }
00148 }
00149 
00150 #ifdef  USE_FULL_ASSERT
00151 
00152 /**
00153   * @brief  Reports the name of the source file and the source line number
00154   *         where the assert_param error has occurred.
00155   * @param  file: pointer to the source file name
00156   * @param  line: assert_param error line source number
00157   * @retval None
00158   */
00159 void assert_failed(uint8_t* file, uint32_t line)
00160 { 
00161   /* User can add his own implementation to report the file name and line number,
00162      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00163 
00164   /* Infinite loop */
00165   while (1)
00166   {
00167   }
00168 }
00169 #endif
00170 
00171 /**
00172   * @}
00173   */ 
00174 
00175 /**
00176   * @}
00177   */ 
00178 
00179 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM32L1xx Standard Peripherals Library: Footer

 

 

 For complete documentation on STM32 Microcontrollers visit www.st.com/STM32