comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/USART/MultiProcessor/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 USART/MultiProcessor/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 "platform_config.h"
25
26 /** @addtogroup STM32F10x_StdPeriph_Examples
27 * @{
28 */
29
30 /** @addtogroup USART_MultiProcessor
31 * @{
32 */
33
34 /* Private typedef -----------------------------------------------------------*/
35 /* Private define ------------------------------------------------------------*/
36 /* Private macro -------------------------------------------------------------*/
37 /* Private variables ---------------------------------------------------------*/
38 USART_InitTypeDef USART_InitStructure;
39
40 /* Private function prototypes -----------------------------------------------*/
41 void RCC_Configuration(void);
42 void GPIO_Configuration(void);
43 void Delay(__IO uint32_t nCount);
44
45 /* Private functions ---------------------------------------------------------*/
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 /* System Clocks Configuration */
61 RCC_Configuration();
62
63 /* Configure the GPIO ports */
64 GPIO_Configuration();
65
66 /* Initialize Leds, Wakeup and Key Buttons mounted on STM3210X-EVAL board */
67 STM_EVAL_LEDInit(LED1);
68 STM_EVAL_LEDInit(LED2);
69 STM_EVAL_LEDInit(LED3);
70 STM_EVAL_LEDInit(LED4);
71 STM_EVAL_PBInit(BUTTON_WAKEUP, BUTTON_MODE_EXTI);
72 STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);
73
74 /* USARTy and USARTz configuration -------------------------------------------*/
75 /* USARTy and USARTz configured as follow:
76 - BaudRate = 9600 baud
77 - Word Length = 9 Bits
78 - One Stop Bit
79 - No parity
80 - Hardware flow control disabled (RTS and CTS signals)
81 - Receive and transmit enabled
82 */
83 USART_InitStructure.USART_BaudRate = 9600;
84 USART_InitStructure.USART_WordLength = USART_WordLength_9b;
85 USART_InitStructure.USART_StopBits = USART_StopBits_1;
86 USART_InitStructure.USART_Parity = USART_Parity_No;
87 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
88 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
89
90 /* Configure USARTy */
91 USART_Init(USARTy, &USART_InitStructure);
92 /* Configure USARTz */
93 USART_Init(USARTz, &USART_InitStructure);
94
95 /* Enable the USARTy */
96 USART_Cmd(USARTy, ENABLE);
97 /* Enable the USARTz */
98 USART_Cmd(USARTz, ENABLE);
99
100 /* Set the USARTy Address */
101 USART_SetAddress(USARTy, 0x1);
102 /* Set the USARTz Address */
103 USART_SetAddress(USARTz, 0x2);
104
105 /* Select the USARTz WakeUp Method */
106 USART_WakeUpConfig(USARTz, USART_WakeUp_AddressMark);
107
108 while (1)
109 {
110 /* Send one byte from USARTy to USARTz */
111 USART_SendData(USARTy, 0x33);
112
113 /* Wait while USART1 TXE = 0 */
114 while(USART_GetFlagStatus(USARTz, USART_FLAG_TXE) == RESET)
115 {
116 }
117
118 if(USART_GetFlagStatus(USARTz, USART_FLAG_RXNE) != RESET)
119 {
120 if(USART_ReceiveData(USARTz) == 0x33)
121 {
122 STM_EVAL_LEDToggle(LED1);
123 Delay(0x5FFFF);
124 STM_EVAL_LEDToggle(LED2);
125 Delay(0x5FFFF);
126 STM_EVAL_LEDToggle(LED3);
127 Delay(0x5FFFF);
128 STM_EVAL_LEDToggle(LED4);
129 Delay(0x5FFFF);
130 }
131 }
132 }
133 }
134
135 /**
136 * @brief Configures the different system clocks.
137 * @param None
138 * @retval None
139 */
140 void RCC_Configuration(void)
141 {
142 /* Enable GPIO clock */
143 RCC_APB2PeriphClockCmd(USARTy_GPIO_CLK | USARTz_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE);
144
145 #ifndef USE_STM3210C_EVAL
146 /* Enable USARTy Clock */
147 RCC_APB2PeriphClockCmd(USARTy_CLK, ENABLE);
148 #else
149 /* Enable USARTy Clock */
150 RCC_APB1PeriphClockCmd(USARTy_CLK, ENABLE);
151 #endif
152 /* Enable USARTz Clock */
153 RCC_APB1PeriphClockCmd(USARTz_CLK, ENABLE);
154 }
155
156 /**
157 * @brief Configures the different GPIO ports.
158 * @param None
159 * @retval None
160 */
161 void GPIO_Configuration(void)
162 {
163 GPIO_InitTypeDef GPIO_InitStructure;
164
165 #ifdef USE_STM3210C_EVAL
166 /* Enable the USART3 Pins Software Remapping */
167 GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE);
168
169 /* Enable the USART2 Pins Software Remapping */
170 GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
171 #elif defined(USE_STM3210B_EVAL) || defined(USE_STM32100B_EVAL)
172 /* Enable the USART2 Pins Software Remapping */
173 GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
174 #endif
175
176 /* Configure USARTy Rx as input floating */
177 GPIO_InitStructure.GPIO_Pin = USARTy_RxPin;
178 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
179 GPIO_Init(USARTy_GPIO, &GPIO_InitStructure);
180
181 /* Configure USARTz Rx as input floating */
182 GPIO_InitStructure.GPIO_Pin = USARTz_RxPin;
183 GPIO_Init(USARTz_GPIO, &GPIO_InitStructure);
184
185 /* Configure USARTy Tx as alternate function push-pull */
186 GPIO_InitStructure.GPIO_Pin = USARTy_TxPin;
187 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
188 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
189 GPIO_Init(USARTy_GPIO, &GPIO_InitStructure);
190
191 /* Configure USARTz Tx as alternate function push-pull */
192 GPIO_InitStructure.GPIO_Pin = USARTz_TxPin;
193 GPIO_Init(USARTz_GPIO, &GPIO_InitStructure);
194 }
195
196 /**
197 * @brief Inserts a delay time.
198 * @param nCount: specifies the delay time length.
199 * @retval None
200 */
201 void Delay(__IO uint32_t nCount)
202 {
203 /* Decrement nCount value */
204 for(; nCount != 0; nCount--);
205 }
206
207 #ifdef USE_FULL_ASSERT
208
209 /**
210 * @brief Reports the name of the source file and the source line number
211 * where the assert_param error has occurred.
212 * @param file: pointer to the source file name
213 * @param line: assert_param error line source number
214 * @retval None
215 */
216 void assert_failed(uint8_t* file, uint32_t line)
217 {
218 /* User can add his own implementation to report the file name and line number,
219 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
220
221 /* Infinite loop */
222 while (1)
223 {
224 }
225 }
226
227 #endif
228
229 /**
230 * @}
231 */
232
233 /**
234 * @}
235 */
236
237 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/