STM32F0xx Standard Peripherals Firmware Library: main.c Source File

STM32F0xx Standard Peripherals Library

STM32F0xx_StdPeriph_Examples/SYSCFG/SYSCFG_PVD/main.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    SYSCFG/SYSCFG_PVD/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 SYSCFG_PVD
00036   * @{
00037   */
00038 
00039 /* Private typedef -----------------------------------------------------------*/
00040 /* Private define ------------------------------------------------------------*/
00041 /* Private macro -------------------------------------------------------------*/
00042 /* Private variables ---------------------------------------------------------*/
00043 /* Private function prototypes -----------------------------------------------*/
00044 /* Private functions ---------------------------------------------------------*/
00045 static void TIM_Config(void);
00046 
00047 /**
00048   * @brief  Main program.
00049   * @param  None
00050   * @retval None
00051   */
00052 int main(void)
00053 {
00054   /*!< At this stage the microcontroller clock setting is already configured, 
00055        this is done through SystemInit() function which is called from startup
00056        file (startup_stm32f0xx.s) before to branch to application main.
00057        To reconfigure the default setting of SystemInit() function, refer to
00058        system_stm32f0xx.c file
00059      */ 
00060   
00061   /* PWR clock enable */
00062   RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
00063   
00064   /* PVD configuration: Level 5 */
00065   PWR_PVDLevelConfig(PWR_PVDLevel_5);
00066   
00067   /* Enable the Power Voltage Detector(PVD) */
00068   PWR_PVDCmd(ENABLE);
00069 
00070   /* Enable SYSCFG clock */
00071   RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
00072   
00073   /* Connect PVD event with BKIN: when a PVD event (VDD lower than the threshold)
00074      is detected a break event is generated */
00075   SYSCFG_BreakConfig(SYSCFG_Break_PVD);
00076   
00077   /* TIM1 channels Configuration in PWM mode */
00078   TIM_Config();
00079 
00080   /* Wait till a PVD event is detected */
00081   while(PWR_GetFlagStatus(PWR_FLAG_PVDO) == RESET);
00082   
00083   /* Infinite loop */
00084   while (1)
00085   {
00086   }
00087 }
00088 
00089 /**
00090   * @brief  Configures TIM1: channels in PWM mode
00091   * @param  None
00092   * @retval None
00093   */
00094 static void TIM_Config(void)
00095 {
00096  
00097   TIM_BDTRInitTypeDef     TIM_BDTRInitStructure;
00098   TIM_OCInitTypeDef       TIM_OCInitStructure;
00099   TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
00100   GPIO_InitTypeDef        GPIO_InitStructure;
00101 
00102   /* GPIOA clock enable */
00103   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
00104 
00105   /* TIM1 channels pin configuration:
00106        TIM1_CH1 -> PA8
00107   */
00108   GPIO_StructInit(&GPIO_InitStructure);
00109   GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
00110   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00111   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
00112   GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
00113   GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_8;
00114   GPIO_Init(GPIOA, &GPIO_InitStructure);
00115 
00116   /* Enable Alternate function on PA8 to be controlled by TIM1 */
00117   GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_2);
00118 
00119   /* TIM1 clock enable */
00120   RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
00121 
00122   /* Time Base configuration */
00123   TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
00124   TIM_TimeBaseStructure.TIM_Prescaler = 0;
00125   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
00126   TIM_TimeBaseStructure.TIM_Period = 100;
00127   TIM_TimeBaseStructure.TIM_ClockDivision = 0;
00128   TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
00129   TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
00130 
00131   /* Channel 1 Configuration in PWM mode */
00132   TIM_OCStructInit(&TIM_OCInitStructure);
00133   TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
00134   TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
00135   TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
00136   TIM_OCInitStructure.TIM_Pulse = 50;
00137   TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
00138   TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
00139   TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
00140   TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
00141   TIM_OC1Init(TIM1, &TIM_OCInitStructure);
00142 
00143   /* Automatic Output enable, Break, dead time and lock configuration*/
00144   TIM_BDTRStructInit(&TIM_BDTRInitStructure);
00145   TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
00146   TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
00147   TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1;
00148   TIM_BDTRInitStructure.TIM_DeadTime = 11;
00149   TIM_BDTRInitStructure.TIM_Break = TIM_Break_Enable;
00150   TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
00151   TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
00152   TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);
00153 
00154   /* Main Output Enable */
00155   TIM_CtrlPWMOutputs(TIM1, ENABLE);
00156 
00157   /* TIM1 counter enable */
00158   TIM_Cmd(TIM1, ENABLE);
00159 }
00160 
00161 #ifdef  USE_FULL_ASSERT
00162 
00163 /**
00164   * @brief  Reports the name of the source file and the source line number
00165   *         where the assert_param error has occurred.
00166   * @param  file: pointer to the source file name
00167   * @param  line: assert_param error line source number
00168   * @retval None
00169   */
00170 void assert_failed(uint8_t* file, uint32_t line)
00171 { 
00172   /* User can add his own implementation to report the file name and line number,
00173      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00174 
00175   /* Infinite loop */
00176   while (1)
00177   {
00178   }
00179 }
00180 #endif
00181 
00182 /**
00183   * @}
00184   */
00185 
00186 /**
00187   * @}
00188   */
00189 
00190 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM32L1xx Standard Peripherals Library: Footer

 

 

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