Merge pull request #93 from zyp/master
[fw/stlink] / example / stm32f4 / Projects / IO_Toggle / main.c
1 /**
2   ******************************************************************************
3   * @file    IO_Toggle/main.c 
4   * @author  MCD Application Team
5   * @version V1.0.0
6   * @date    19-September-2011
7   * @brief   Main program body
8   ******************************************************************************
9   * @attention
10   *
11   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17   *
18   * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
19   ******************************************************************************  
20   */ 
21 /* Includes ------------------------------------------------------------------*/
22 #include "stm32f4_discovery.h"
23 #include "stm32f4xx_conf.h"
24
25 /** @addtogroup STM32F4_Discovery_Peripheral_Examples
26   * @{
27   */
28
29 /** @addtogroup IO_Toggle
30   * @{
31   */ 
32
33 /* Private typedef -----------------------------------------------------------*/
34 GPIO_InitTypeDef  GPIO_InitStructure;
35
36 /* Private define ------------------------------------------------------------*/
37 /* Private macro -------------------------------------------------------------*/
38 /* Private variables ---------------------------------------------------------*/
39 /* Private function prototypes -----------------------------------------------*/
40 void Delay(__IO uint32_t nCount);
41 /* Private functions ---------------------------------------------------------*/
42
43 /**
44   * @brief  Main program
45   * @param  None
46   * @retval None
47   */
48 int main(void)
49 {
50   /*!< At this stage the microcontroller clock setting is already configured, 
51        this is done through SystemInit() function which is called from startup
52        file (startup_stm32f4xx.s) before to branch to application main.
53        To reconfigure the default setting of SystemInit() function, refer to
54         system_stm32f4xx.c file
55      */
56
57   /* GPIOD Periph clock enable */
58   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
59
60   /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
61   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;
62   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
63   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
64   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
65   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
66   GPIO_Init(GPIOD, &GPIO_InitStructure);
67
68   while (1)
69   {
70     /* PD12 to be toggled */
71     GPIO_SetBits(GPIOD, GPIO_Pin_12);
72     
73     /* Insert delay */
74     Delay(0x3FFFFF);
75     
76     /* PD13 to be toggled */
77     GPIO_SetBits(GPIOD, GPIO_Pin_13);
78     
79     /* Insert delay */
80     Delay(0x3FFFFF);
81   
82     /* PD14 to be toggled */
83     GPIO_SetBits(GPIOD, GPIO_Pin_14);
84     
85     /* Insert delay */
86     Delay(0x3FFFFF);
87     
88     /* PD15 to be toggled */
89     GPIO_SetBits(GPIOD, GPIO_Pin_15);
90     
91     /* Insert delay */
92     Delay(0x7FFFFF);
93     
94     GPIO_ResetBits(GPIOD, GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
95     
96     /* Insert delay */
97     Delay(0xFFFFFF);
98   }
99 }
100
101 /**
102   * @brief  Delay Function.
103   * @param  nCount:specifies the Delay time length.
104   * @retval None
105   */
106 void Delay(__IO uint32_t nCount)
107 {
108   while(nCount--)
109   {
110   }
111 }
112
113 #ifdef  USE_FULL_ASSERT
114
115 /**
116   * @brief  Reports the name of the source file and the source line number
117   *         where the assert_param error has occurred.
118   * @param  file: pointer to the source file name
119   * @param  line: assert_param error line source number
120   * @retval None
121   */
122 void assert_failed(uint8_t* file, uint32_t line)
123
124   /* User can add his own implementation to report the file name and line number,
125      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
126
127   /* Infinite loop */
128   while (1)
129   {
130   }
131 }
132 #endif
133
134 /**
135   * @}
136   */ 
137
138 /**
139   * @}
140   */ 
141
142 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/