STM32F10x_StdPeriph_Examples/NVIC/IRQ_Channels/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    NVIC/IRQ_Channels/main.c 
00004   * @author  MCD Application Team
00005   * @version V3.4.0
00006   * @date    10/15/2010
00007   * @brief   Main program body
00008   ******************************************************************************
00009   * @copy
00010   *
00011   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00012   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00013   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00014   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00015   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00016   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00017   *
00018   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00019   */ 
00020 
00021 /* Includes ------------------------------------------------------------------*/
00022 #include "stm32f10x.h"
00023 #include "stm32_eval.h"
00024 
00025 /** @addtogroup STM32F10x_StdPeriph_Examples
00026   * @{
00027   */
00028 
00029 /** @addtogroup NVIC_IRQ_Channels
00030   * @{
00031   */ 
00032 
00033 /* Private typedef -----------------------------------------------------------*/
00034 /* Private define ------------------------------------------------------------*/
00035 /* Private macro -------------------------------------------------------------*/
00036 /* Private variables ---------------------------------------------------------*/
00037 NVIC_InitTypeDef NVIC_InitStructure;
00038 
00039 /* Private function prototypes -----------------------------------------------*/
00040 void RCC_Configuration(void);
00041 void TIM_Configuration(void);
00042 
00043 /* Private functions ---------------------------------------------------------*/
00044 
00045 /**
00046   * @brief   Main program.
00047   * @param  None
00048   * @retval None
00049   */
00050 int main(void)
00051 {
00052   /*!< At this stage the microcontroller clock setting is already configured, 
00053        this is done through SystemInit() function which is called from startup
00054        file (startup_stm32f10x_xx.s) before to branch to application main.
00055        To reconfigure the default setting of SystemInit() function, refer to
00056        system_stm32f10x.c file
00057      */  
00058        
00059   /* Configure the system clocks */
00060   RCC_Configuration();
00061 
00062   /* Initialize Leds mounted on STM3210X-EVAL board */
00063   STM_EVAL_LEDInit(LED1);
00064   STM_EVAL_LEDInit(LED2);
00065   STM_EVAL_LEDInit(LED3);
00066   STM_EVAL_LEDInit(LED4);
00067 
00068   /* Configure TIMs */
00069   TIM_Configuration();
00070        
00071   /* Configure two bits for preemption priority */
00072   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
00073   
00074   /* Enable the TIM2 Interrupt */
00075   NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
00076   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
00077   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
00078   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00079   NVIC_Init(&NVIC_InitStructure);
00080   
00081   /* Enable the TIM3 Interrupt */
00082   NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
00083   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
00084   NVIC_Init(&NVIC_InitStructure);
00085  
00086   /* Enable the TIM4 Interrupt */
00087   NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
00088   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
00089   NVIC_Init(&NVIC_InitStructure); 
00090     
00091   while (1)
00092   {     
00093   }
00094 }
00095 
00096 /**
00097   * @brief  Configures the different system clocks
00098   * @param  None
00099   * @retval None
00100   */
00101 void RCC_Configuration(void)
00102 {
00103   /* Enable TIM2, TIM3 and TIM4 clocks */
00104   RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3 |
00105                          RCC_APB1Periph_TIM4, ENABLE);
00106 }
00107 
00108 /**
00109   * @brief  Configures the used Timers.
00110   * @param  None
00111   * @retval None
00112   */
00113 void TIM_Configuration(void)
00114 { 
00115   TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
00116   TIM_OCInitTypeDef  TIM_OCInitStructure;
00117 
00118   /* TIM2 configuration */
00119   TIM_TimeBaseStructure.TIM_Period = 0x4AF;          
00120   TIM_TimeBaseStructure.TIM_Prescaler = ((SystemCoreClock/1200) - 1);       
00121   TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;    
00122   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  
00123   TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x0000;
00124   TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
00125   
00126   TIM_OCStructInit(&TIM_OCInitStructure);
00127   /* Output Compare Timing Mode configuration: Channel1 */
00128   TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
00129   TIM_OCInitStructure.TIM_Pulse = 0x0;  
00130   TIM_OC1Init(TIM2, &TIM_OCInitStructure);
00131   
00132   /* TIM3 configuration */
00133   TIM_TimeBaseStructure.TIM_Period = 0x95F;
00134           
00135   TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
00136   /* Output Compare Timing Mode configuration: Channel1 */
00137   TIM_OC1Init(TIM3, &TIM_OCInitStructure);
00138   
00139   /* TIM4 configuration */
00140   TIM_TimeBaseStructure.TIM_Period = 0xE0F;  
00141         
00142   TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
00143   /* Output Compare Timing Mode configuration: Channel1 */
00144   TIM_OC1Init(TIM4, &TIM_OCInitStructure);
00145 
00146   /* TIM2 enable counter */
00147   TIM_Cmd(TIM2, ENABLE);
00148   /* TIM3 enable counter */
00149   TIM_Cmd(TIM3, ENABLE);
00150   /* TIM4 enable counter */
00151   TIM_Cmd(TIM4, ENABLE);
00152 
00153   /* Immediate load of TIM2 Precaler value */
00154   TIM_PrescalerConfig(TIM2, ((SystemCoreClock/1200) - 1), TIM_PSCReloadMode_Immediate);
00155   /* Immediate load of TIM3 Precaler value */  
00156   TIM_PrescalerConfig(TIM3, ((SystemCoreClock/1200) - 1), TIM_PSCReloadMode_Immediate);
00157   /* Immediate load of TIM4 Precaler value */
00158   TIM_PrescalerConfig(TIM4, ((SystemCoreClock/1200) - 1), TIM_PSCReloadMode_Immediate);
00159 
00160   /* Clear TIM2 update pending flag */
00161   TIM_ClearFlag(TIM2, TIM_FLAG_Update);
00162   /* Clear TIM3 update pending flag */
00163   TIM_ClearFlag(TIM3, TIM_FLAG_Update);
00164   /* Clear TIM4 update pending flag */
00165   TIM_ClearFlag(TIM4, TIM_FLAG_Update);
00166 
00167   /* Enable TIM2 Update interrupt */
00168   TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
00169   /* Enable TIM3 Update interrupt */
00170   TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
00171   /* Enable TIM4 Update interrupt */
00172   TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
00173 }
00174 
00175 #ifdef  USE_FULL_ASSERT
00176 /**
00177   * @brief  Reports the name of the source file and the source line number
00178   *         where the assert_param error has occurred.
00179   * @param  file: pointer to the source file name
00180   * @param  line: assert_param error line source number
00181   * @retval None
00182   */
00183 void assert_failed(uint8_t* file, uint32_t line)
00184 { 
00185   /* User can add his own implementation to report the file name and line number,
00186      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00187 
00188   /* Infinite loop */
00189   while (1)
00190   {
00191   }
00192 }
00193 #endif
00194 
00195 /**
00196   * @}
00197   */
00198 
00199 /**
00200   * @}
00201   */
00202 
00203 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32