STM32F10x_StdPeriph_Examples/NVIC/Priority/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    NVIC/Priority/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_Priority
00030   * @{
00031   */ 
00032 
00033 /* Private typedef -----------------------------------------------------------*/
00034 /* Private define ------------------------------------------------------------*/
00035 /* Private macro -------------------------------------------------------------*/
00036 /* Private variables ---------------------------------------------------------*/
00037 NVIC_InitTypeDef NVIC_InitStructure;
00038 bool PreemptionOccured = FALSE; 
00039 uint8_t PreemptionPriorityValue = 0; 
00040 
00041 /* Private function prototypes -----------------------------------------------*/
00042 void Delay(__IO uint32_t nCount);
00043 
00044 /* Private functions ---------------------------------------------------------*/
00045 
00046 /**
00047   * @brief   Main program.
00048   * @param  None
00049   * @retval None
00050   */
00051 int main(void)
00052 {
00053   /*!< At this stage the microcontroller clock setting is already configured, 
00054        this is done through SystemInit() function which is called from startup
00055        file (startup_stm32f10x_xx.s) before to branch to application main.
00056        To reconfigure the default setting of SystemInit() function, refer to
00057        system_stm32f10x.c file
00058      */     
00059        
00060   /* Initialize LED1..LED4, Key and Wakeup Buttons mounted on STM3210X-EVAL 
00061      board */       
00062   STM_EVAL_LEDInit(LED1);
00063   STM_EVAL_LEDInit(LED2);
00064   STM_EVAL_LEDInit(LED3);
00065   STM_EVAL_LEDInit(LED4);
00066   STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);
00067   STM_EVAL_PBInit(BUTTON_WAKEUP, BUTTON_MODE_EXTI); 
00068 
00069   /* Configure one bit for preemption priority */
00070   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
00071   
00072   /* Enable the WAKEUP_BUTTON_EXTI_IRQn Interrupt */
00073   NVIC_InitStructure.NVIC_IRQChannel = WAKEUP_BUTTON_EXTI_IRQn;
00074   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = PreemptionPriorityValue;
00075   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
00076   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00077   NVIC_Init(&NVIC_InitStructure);
00078   
00079   /* Enable the KEY_BUTTON_EXTI_IRQn Interrupt */
00080   NVIC_InitStructure.NVIC_IRQChannel = KEY_BUTTON_EXTI_IRQn;
00081   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
00082   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
00083   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00084   NVIC_Init(&NVIC_InitStructure);
00085   
00086   /* Configure the SysTick Handler Priority: Preemption priority and subpriority */
00087   NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), !PreemptionPriorityValue, 0));
00088     
00089   while (1)
00090   {
00091     if(PreemptionOccured != FALSE)
00092     {
00093       STM_EVAL_LEDToggle(LED1);
00094       Delay(0x5FFFF);
00095       STM_EVAL_LEDToggle(LED2);
00096       Delay(0x5FFFF);
00097       STM_EVAL_LEDToggle(LED3);
00098       Delay(0x5FFFF);
00099       STM_EVAL_LEDToggle(LED4);
00100       Delay(0x5FFFF); 
00101     }
00102   }
00103 }
00104 
00105 /**
00106   * @brief  Inserts a delay time.
00107   * @param  nCount: specifies the delay time length.
00108   * @retval None
00109   */
00110 void Delay(__IO uint32_t nCount)
00111 {
00112   for(; nCount != 0; nCount--);
00113 }
00114 
00115 #ifdef  USE_FULL_ASSERT
00116 /**
00117   * @brief  Reports the name of the source file and the source line number
00118   *         where the assert_param error has occurred.
00119   * @param  file: pointer to the source file name
00120   * @param  line: assert_param error line source number
00121   * @retval None
00122   */
00123 void assert_failed(uint8_t* file, uint32_t line)
00124 { 
00125   /* User can add his own implementation to report the file name and line number,
00126      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00127 
00128   /* Infinite loop */
00129   while (1)
00130   {
00131   }
00132 }
00133 #endif
00134 
00135 /**
00136   * @}
00137   */
00138 
00139 /**
00140   * @}
00141   */
00142 
00143 /******************* (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