comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Template/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 Project/STM32F10x_StdPeriph_Template/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 #include <stdio.h>
26
27 #ifdef USE_STM32100B_EVAL
28 #include "stm32100b_eval_lcd.h"
29 #elif defined USE_STM3210B_EVAL
30 #include "stm3210b_eval_lcd.h"
31 #elif defined USE_STM3210E_EVAL
32 #include "stm3210e_eval_lcd.h"
33 #elif defined USE_STM3210C_EVAL
34 #include "stm3210c_eval_lcd.h"
35 #elif defined USE_STM32100E_EVAL
36 #include "stm32100e_eval_lcd.h"
37 #endif
38
39 /** @addtogroup STM32F10x_StdPeriph_Template
40 * @{
41 */
42
43 /* Private typedef -----------------------------------------------------------*/
44 /* Private define ------------------------------------------------------------*/
45 #ifdef USE_STM32100B_EVAL
46 #define MESSAGE1 "STM32 MD Value Line "
47 #define MESSAGE2 " Device running on "
48 #define MESSAGE3 " STM32100B-EVAL "
49 #elif defined (USE_STM3210B_EVAL)
50 #define MESSAGE1 "STM32 Medium Density"
51 #define MESSAGE2 " Device running on "
52 #define MESSAGE3 " STM3210B-EVAL "
53 #elif defined (STM32F10X_XL) && defined (USE_STM3210E_EVAL)
54 #define MESSAGE1 " STM32 XL Density "
55 #define MESSAGE2 " Device running on "
56 #define MESSAGE3 " STM3210E-EVAL "
57 #elif defined (USE_STM3210E_EVAL)
58 #define MESSAGE1 " STM32 High Density "
59 #define MESSAGE2 " Device running on "
60 #define MESSAGE3 " STM3210E-EVAL "
61 #elif defined (USE_STM3210C_EVAL)
62 #define MESSAGE1 " STM32 Connectivity "
63 #define MESSAGE2 " Line Device running"
64 #define MESSAGE3 " on STM3210C-EVAL "
65 #elif defined (USE_STM32100E_EVAL)
66 #define MESSAGE1 "STM32 HD Value Line "
67 #define MESSAGE2 " Device running on "
68 #define MESSAGE3 " STM32100E-EVAL "
69 #endif
70
71 /* Private macro -------------------------------------------------------------*/
72 /* Private variables ---------------------------------------------------------*/
73 USART_InitTypeDef USART_InitStructure;
74
75 /* Private function prototypes -----------------------------------------------*/
76 #ifdef __GNUC__
77 /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
78 set to 'Yes') calls __io_putchar() */
79 #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
80 #else
81 #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
82 #endif /* __GNUC__ */
83
84 /* Private functions ---------------------------------------------------------*/
85
86 /**
87 * @brief Main program.
88 * @param None
89 * @retval None
90 */
91 int main(void)
92 {
93 /*!< At this stage the microcontroller clock setting is already configured,
94 this is done through SystemInit() function which is called from startup
95 file (startup_stm32f10x_xx.s) before to branch to application main.
96 To reconfigure the default setting of SystemInit() function, refer to
97 system_stm32f10x.c file
98 */
99
100 /* Initialize LEDs, Key Button, LCD and COM port(USART) available on
101 STM3210X-EVAL board ******************************************************/
102 STM_EVAL_LEDInit(LED1);
103 STM_EVAL_LEDInit(LED2);
104 STM_EVAL_LEDInit(LED3);
105 STM_EVAL_LEDInit(LED4);
106
107 /* USARTx configured as follow:
108 - BaudRate = 115200 baud
109 - Word Length = 8 Bits
110 - One Stop Bit
111 - No parity
112 - Hardware flow control disabled (RTS and CTS signals)
113 - Receive and transmit enabled
114 */
115 USART_InitStructure.USART_BaudRate = 115200;
116 USART_InitStructure.USART_WordLength = USART_WordLength_8b;
117 USART_InitStructure.USART_StopBits = USART_StopBits_1;
118 USART_InitStructure.USART_Parity = USART_Parity_No;
119 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
120 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
121
122 STM_EVAL_COMInit(COM1, &USART_InitStructure);
123
124 /* Initialize the LCD */
125 #ifdef USE_STM32100B_EVAL
126 STM32100B_LCD_Init();
127 #elif defined (USE_STM3210B_EVAL)
128 STM3210B_LCD_Init();
129 #elif defined (USE_STM3210E_EVAL)
130 STM3210E_LCD_Init();
131 #elif defined (USE_STM3210C_EVAL)
132 STM3210C_LCD_Init();
133 #elif defined (USE_STM32100E_EVAL)
134 STM32100E_LCD_Init();
135 #endif
136
137 /* Display message on STM3210X-EVAL LCD *************************************/
138 /* Clear the LCD */
139 LCD_Clear(LCD_COLOR_WHITE);
140
141 /* Set the LCD Back Color */
142 LCD_SetBackColor(LCD_COLOR_BLUE);
143 /* Set the LCD Text Color */
144 LCD_SetTextColor(LCD_COLOR_WHITE);
145 LCD_DisplayStringLine(LCD_LINE_0, (uint8_t *)MESSAGE1);
146 LCD_DisplayStringLine(LCD_LINE_1, (uint8_t *)MESSAGE2);
147 LCD_DisplayStringLine(LCD_LINE_2, (uint8_t *)MESSAGE3);
148
149 /* Retarget the C library printf function to the USARTx, can be USART1 or USART2
150 depending on the EVAL board you are using ********************************/
151 printf("\n\r %s", MESSAGE1);
152 printf(" %s", MESSAGE2);
153 printf(" %s\n\r", MESSAGE3);
154
155 /* Turn on leds available on STM3210X-EVAL **********************************/
156 STM_EVAL_LEDOn(LED1);
157 STM_EVAL_LEDOn(LED2);
158 STM_EVAL_LEDOn(LED3);
159 STM_EVAL_LEDOn(LED4);
160
161 /* Add your application code here
162 */
163
164 /* Infinite loop */
165 while (1)
166 {
167 }
168 }
169
170 /**
171 * @brief Retargets the C library printf function to the USART.
172 * @param None
173 * @retval None
174 */
175 PUTCHAR_PROTOTYPE
176 {
177 /* Place your implementation of fputc here */
178 /* e.g. write a character to the USART */
179 USART_SendData(EVAL_COM1, (uint8_t) ch);
180
181 /* Loop until the end of transmission */
182 while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
183 {}
184
185 return ch;
186 }
187
188 #ifdef USE_FULL_ASSERT
189
190 /**
191 * @brief Reports the name of the source file and the source line number
192 * where the assert_param error has occurred.
193 * @param file: pointer to the source file name
194 * @param line: assert_param error line source number
195 * @retval None
196 */
197 void assert_failed(uint8_t* file, uint32_t line)
198 {
199 /* User can add his own implementation to report the file name and line number,
200 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
201
202 /* Infinite loop */
203 while (1)
204 {
205 }
206 }
207 #endif
208
209 /**
210 * @}
211 */
212
213
214 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/