comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/GPIO/JTAG_Remap/main.c @ 0:c59513fd84fb

Initial commit of STM32 test code.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 03 Oct 2011 21:19:15 +1030
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c59513fd84fb
1 /**
2 ******************************************************************************
3 * @file GPIO/JTAG_Remap/main.c
4 * @author MCD Application Team
5 * @version V3.5.0
6 * @date 08-April-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
22 /* Includes ------------------------------------------------------------------*/
23 #include "stm32f10x.h"
24 #include "stm32_eval.h"
25
26 /** @addtogroup STM32F10x_StdPeriph_Examples
27 * @{
28 */
29
30 /** @addtogroup GPIO_JTAG_Remap
31 * @{
32 */
33
34 /* Private typedef -----------------------------------------------------------*/
35 /* Private define ------------------------------------------------------------*/
36 /* Private macro -------------------------------------------------------------*/
37 /* Private variables ---------------------------------------------------------*/
38 GPIO_InitTypeDef GPIO_InitStructure;
39
40 /* Private function prototypes -----------------------------------------------*/
41 void RCC_Configuration(void);
42 void Delay(__IO uint32_t nCount);
43
44 /* Private functions ---------------------------------------------------------*/
45
46 /**
47 * @brief Main program.
48 * @param None
49 * @retval None
50 */
51 int main(void)
52 {
53 /*!< At this stage the microcontroller clock setting is already configured,
54 this is done through SystemInit() function which is called from startup
55 file (startup_stm32f10x_xx.s) before to branch to application main.
56 To reconfigure the default setting of SystemInit() function, refer to
57 system_stm32f10x.c file
58 */
59
60 /* Configure the system clocks */
61 RCC_Configuration();
62
63 /* Initialize LEDs and Key Button mounted on STM3210X-EVAL board */
64 STM_EVAL_LEDInit(LED1);
65 STM_EVAL_LEDInit(LED2);
66
67 STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO);
68
69 /* Test if Key Button GPIO Pin level is low (Key push-button on Eval Board pressed) */
70 if (STM_EVAL_PBGetState(BUTTON_KEY) == 0x00)
71 { /* Key is pressed */
72
73 /* Turn on LED1 */
74 STM_EVAL_LEDOn(LED1);
75
76 /* Disable the Serial Wire Jtag Debug Port SWJ-DP */
77 GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
78
79 /* Configure PA.13 (JTMS/SWDAT), PA.14 (JTCK/SWCLK) and PA.15 (JTDI) as
80 output push-pull */
81 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
82 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
83 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
84 GPIO_Init(GPIOA, &GPIO_InitStructure);
85
86 /* Configure PB.03 (JTDO) and PB.04 (JTRST) as output push-pull */
87 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4;
88 GPIO_Init(GPIOB, &GPIO_InitStructure);
89
90 while (1)
91 {
92 /* Toggle JTMS/SWDAT pin */
93 GPIO_WriteBit(GPIOA, GPIO_Pin_13, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_13)));
94 /* Insert delay */
95 Delay(0x5FFFF);
96
97 /* Toggle JTCK/SWCLK pin */
98 GPIO_WriteBit(GPIOA, GPIO_Pin_14, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_14)));
99 /* Insert delay */
100 Delay(0x5FFFF);
101
102 /* Toggle JTDI pin */
103 GPIO_WriteBit(GPIOA, GPIO_Pin_15, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_15)));
104 /* Insert delay */
105 Delay(0x5FFFF);
106
107 /* Toggle JTDO pin */
108 GPIO_WriteBit(GPIOB, GPIO_Pin_3, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_3)));
109 /* Insert delay */
110 Delay(0x5FFFF);
111
112 /* Toggle JTRST pin */
113 GPIO_WriteBit(GPIOB, GPIO_Pin_4, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_4)));
114 /* Insert delay */
115 Delay(0x5FFFF);
116 }
117 }
118 else
119 {
120 /* Turn on LED2 */
121 STM_EVAL_LEDOn(LED2);
122
123 while (1)
124 {
125 }
126 }
127 }
128
129 /**
130 * @brief Configures the different system clocks.
131 * @param None
132 * @retval None
133 */
134 void RCC_Configuration(void)
135 {
136 /* Enable GPIOA, GPIOB, RCC_APB2Periph_GPIO_KEY_BUTTON and AFIO clocks */
137 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
138 RCC_APB2Periph_AFIO, ENABLE);
139 }
140
141 /**
142 * @brief Inserts a delay time.
143 * @param nCount: specifies the delay time length.
144 * @retval None
145 */
146 void Delay(__IO uint32_t nCount)
147 {
148 for(; nCount != 0; nCount--);
149 }
150
151 #ifdef USE_FULL_ASSERT
152
153 /**
154 * @brief Reports the name of the source file and the source line number
155 * where the assert_param error has occurred.
156 * @param file: pointer to the source file name
157 * @param line: assert_param error line source number
158 * @retval None
159 */
160 void assert_failed(uint8_t* file, uint32_t line)
161 {
162 /* User can add his own implementation to report the file name and line number,
163 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
164
165 /* Infinite loop */
166 while (1)
167 {
168 }
169 }
170
171 #endif
172
173 /**
174 * @}
175 */
176
177 /**
178 * @}
179 */
180
181 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/