STM32F10x_StdPeriph_Examples/GPIO/IOToggle/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    GPIO/IOToggle/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 GPIO_IOToggle
00030   * @{
00031   */
00032 
00033 /* Private typedef -----------------------------------------------------------*/
00034 /* Private define ------------------------------------------------------------*/
00035 /* Private macro -------------------------------------------------------------*/
00036 /* Private variables ---------------------------------------------------------*/
00037 GPIO_InitTypeDef GPIO_InitStructure;
00038 
00039 /* Private function prototypes -----------------------------------------------*/
00040 void Delay(__IO uint32_t nCount);
00041 
00042 /* Private functions ---------------------------------------------------------*/
00043 
00044 /**
00045   * @brief  Main program.
00046   * @param  None
00047   * @retval None
00048   */
00049 int main(void)
00050 {
00051   /*!< At this stage the microcontroller clock setting is already configured, 
00052        this is done through SystemInit() function which is called from startup
00053        file (startup_stm32f10x_xx.s) before to branch to application main.
00054        To reconfigure the default setting of SystemInit() function, refer to
00055        system_stm32f10x.c file
00056      */     
00057        
00058   /* Configure all unused GPIO port pins in Analog Input mode (floating input
00059      trigger OFF), this will reduce the power consumption and increase the device
00060      immunity against EMI/EMC *************************************************/
00061   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
00062                          RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
00063                          RCC_APB2Periph_GPIOE, ENABLE);
00064 
00065   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
00066   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
00067   GPIO_Init(GPIOA, &GPIO_InitStructure);
00068   GPIO_Init(GPIOB, &GPIO_InitStructure);
00069   GPIO_Init(GPIOC, &GPIO_InitStructure);
00070   GPIO_Init(GPIOD, &GPIO_InitStructure);
00071   GPIO_Init(GPIOE, &GPIO_InitStructure);
00072 
00073   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
00074                          RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
00075                          RCC_APB2Periph_GPIOE, DISABLE);  
00076 #if defined USE_STM3210E_EVAL || defined USE_STM32100E_EVAL
00077   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG, ENABLE);
00078 
00079   GPIO_Init(GPIOF, &GPIO_InitStructure);
00080   GPIO_Init(GPIOG, &GPIO_InitStructure);
00081   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG, DISABLE);
00082 #endif /* USE_STM3210E_EVAL */
00083 
00084   /* Initialize Leds mounted on STM3210X-EVAL board */
00085   STM_EVAL_LEDInit(LED1);
00086   STM_EVAL_LEDInit(LED2);
00087   STM_EVAL_LEDInit(LED3);
00088   STM_EVAL_LEDInit(LED4);
00089 
00090   while (1)
00091   {
00092     /* Turn on LD1 */
00093     STM_EVAL_LEDOn(LED1);
00094     /* Insert delay */
00095     Delay(0xAFFFF);
00096 
00097     /* Turn on LD2 and LD3 */
00098     STM_EVAL_LEDOn(LED2);
00099     STM_EVAL_LEDOn(LED3);
00100     /* Turn off LD1 */
00101     STM_EVAL_LEDOff(LED1);
00102     /* Insert delay */
00103     Delay(0xAFFFF);
00104 
00105     /* Turn on LD4 */
00106     STM_EVAL_LEDOn(LED4);
00107     /* Turn off LD2 and LD3 */
00108     STM_EVAL_LEDOff(LED2);
00109     STM_EVAL_LEDOff(LED3);
00110     /* Insert delay */
00111     Delay(0xAFFFF);
00112 
00113     /* Turn off LD4 */
00114     STM_EVAL_LEDOff(LED4);
00115   }
00116 }
00117 
00118 /**
00119   * @brief  Inserts a delay time.
00120   * @param  nCount: specifies the delay time length.
00121   * @retval None
00122   */
00123 void Delay(__IO uint32_t nCount)
00124 {
00125   for(; nCount != 0; nCount--);
00126 }
00127 
00128 #ifdef  USE_FULL_ASSERT
00129 /**
00130   * @brief  Reports the name of the source file and the source line number
00131   *         where the assert_param error has occurred.
00132   * @param  file: pointer to the source file name
00133   * @param  line: assert_param error line source number
00134   * @retval None
00135   */
00136 void assert_failed(uint8_t* file, uint32_t line)
00137 { 
00138   /* User can add his own implementation to report the file name and line number,
00139      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00140 
00141   /* Infinite loop */
00142   while (1)
00143   {
00144   }
00145 }
00146 #endif
00147 
00148 /**
00149   * @}
00150   */
00151 
00152 /**
00153   * @}
00154   */
00155 
00156 /******************* (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