STM32F10x_StdPeriph_Template/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    Project/STM32F10x_StdPeriph_Template/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 #include <stdio.h>
00025 
00026 #ifdef USE_STM32100B_EVAL
00027  #include "stm32100b_eval_lcd.h"
00028 #elif defined USE_STM3210B_EVAL
00029  #include "stm3210b_eval_lcd.h"
00030 #elif defined USE_STM3210E_EVAL
00031  #include "stm3210e_eval_lcd.h" 
00032 #elif defined USE_STM3210C_EVAL
00033  #include "stm3210c_eval_lcd.h"
00034 #elif defined USE_STM32100E_EVAL
00035  #include "stm32100e_eval_lcd.h"
00036 #endif
00037 
00038 /** @addtogroup STM32F10x_StdPeriph_Template
00039   * @{
00040   */
00041 
00042 /* Private typedef -----------------------------------------------------------*/
00043 /* Private define ------------------------------------------------------------*/
00044 #ifdef USE_STM32100B_EVAL
00045   #define MESSAGE1   "STM32 MD Value Line " 
00046   #define MESSAGE2   " Device running on  " 
00047   #define MESSAGE3   "  STM32100B-EVAL    " 
00048 #elif defined (USE_STM3210B_EVAL)
00049   #define MESSAGE1   "STM32 Medium Density" 
00050   #define MESSAGE2   " Device running on  " 
00051   #define MESSAGE3   "   STM3210B-EVAL    " 
00052 #elif defined (STM32F10X_XL) && defined (USE_STM3210E_EVAL)
00053   #define MESSAGE1   "  STM32 XL Density  " 
00054   #define MESSAGE2   " Device running on  " 
00055   #define MESSAGE3   "   STM3210E-EVAL    "
00056 #elif defined (USE_STM3210E_EVAL)
00057   #define MESSAGE1   " STM32 High Density " 
00058   #define MESSAGE2   " Device running on  " 
00059   #define MESSAGE3   "   STM3210E-EVAL    " 
00060 #elif defined (USE_STM3210C_EVAL)
00061   #define MESSAGE1   " STM32 Connectivity " 
00062   #define MESSAGE2   " Line Device running" 
00063   #define MESSAGE3   " on STM3210C-EVAL   "
00064 #elif defined (USE_STM32100E_EVAL)
00065   #define MESSAGE1   "STM32 HD Value Line " 
00066   #define MESSAGE2   " Device running on  " 
00067   #define MESSAGE3   "  STM32100E-EVAL    "   
00068 #endif
00069 
00070 /* Private macro -------------------------------------------------------------*/
00071 /* Private variables ---------------------------------------------------------*/
00072  USART_InitTypeDef USART_InitStructure;
00073 
00074 /* Private function prototypes -----------------------------------------------*/
00075 #ifdef __GNUC__
00076 /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
00077    set to 'Yes') calls __io_putchar() */
00078 #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
00079 #else
00080 #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
00081 #endif /* __GNUC__ */
00082 
00083 /* Private functions ---------------------------------------------------------*/
00084 
00085 /**
00086   * @brief  Main program.
00087   * @param  None
00088   * @retval None
00089   */
00090 int main(void)
00091 {
00092   /*!< At this stage the microcontroller clock setting is already configured, 
00093        this is done through SystemInit() function which is called from startup
00094        file (startup_stm32f10x_xx.s) before to branch to application main.
00095        To reconfigure the default setting of SystemInit() function, refer to
00096        system_stm32f10x.c file
00097      */     
00098 
00099   /* Initialize LEDs, Key Button, LCD and COM port(USART) available on
00100      STM3210X-EVAL board ******************************************************/
00101   STM_EVAL_LEDInit(LED1);
00102   STM_EVAL_LEDInit(LED2);
00103   STM_EVAL_LEDInit(LED3);
00104   STM_EVAL_LEDInit(LED4);
00105 
00106   /* USARTx configured as follow:
00107         - BaudRate = 115200 baud  
00108         - Word Length = 8 Bits
00109         - One Stop Bit
00110         - No parity
00111         - Hardware flow control disabled (RTS and CTS signals)
00112         - Receive and transmit enabled
00113   */
00114   USART_InitStructure.USART_BaudRate = 115200;
00115   USART_InitStructure.USART_WordLength = USART_WordLength_8b;
00116   USART_InitStructure.USART_StopBits = USART_StopBits_1;
00117   USART_InitStructure.USART_Parity = USART_Parity_No;
00118   USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
00119   USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
00120 
00121   STM_EVAL_COMInit(COM1, &USART_InitStructure);
00122 
00123   /* Initialize the LCD */
00124 #ifdef USE_STM32100B_EVAL
00125   STM32100B_LCD_Init();
00126 #elif defined (USE_STM3210B_EVAL)
00127   STM3210B_LCD_Init();
00128 #elif defined (USE_STM3210E_EVAL)
00129   STM3210E_LCD_Init();
00130 #elif defined (USE_STM3210C_EVAL)
00131   STM3210C_LCD_Init();
00132 #elif defined (USE_STM32100E_EVAL)
00133   STM32100E_LCD_Init();  
00134 #endif
00135 
00136   /* Display message on STM3210X-EVAL LCD *************************************/
00137   /* Clear the LCD */ 
00138   LCD_Clear(White);
00139 
00140   /* Set the LCD Back Color */
00141   LCD_SetBackColor(Blue);
00142   /* Set the LCD Text Color */
00143   LCD_SetTextColor(White);
00144   LCD_DisplayStringLine(Line0, MESSAGE1);
00145   LCD_DisplayStringLine(Line1, MESSAGE2);
00146   LCD_DisplayStringLine(Line2, MESSAGE3);
00147 
00148   /* Retarget the C library printf function to the USARTx, can be USART1 or USART2
00149      depending on the EVAL board you are using ********************************/
00150   printf("\n\r %s", MESSAGE1);
00151   printf(" %s", MESSAGE2);
00152   printf(" %s\n\r", MESSAGE3);
00153 
00154   /* Turn on leds available on STM3210X-EVAL **********************************/
00155   STM_EVAL_LEDOn(LED1);
00156   STM_EVAL_LEDOn(LED2);
00157   STM_EVAL_LEDOn(LED3);
00158   STM_EVAL_LEDOn(LED4);
00159 
00160   /* Add your application code here
00161      */
00162 
00163   /* Infinite loop */
00164   while (1)
00165   {
00166   }
00167 }
00168 
00169 /**
00170   * @brief  Retargets the C library printf function to the USART.
00171   * @param  None
00172   * @retval None
00173   */
00174 PUTCHAR_PROTOTYPE
00175 {
00176   /* Place your implementation of fputc here */
00177   /* e.g. write a character to the USART */
00178   USART_SendData(EVAL_COM1, (uint8_t) ch);
00179 
00180   /* Loop until the end of transmission */
00181   while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
00182   {}
00183 
00184   return ch;
00185 }
00186 
00187 #ifdef  USE_FULL_ASSERT
00188 
00189 /**
00190   * @brief  Reports the name of the source file and the source line number
00191   *   where the assert_param error has occurred.
00192   * @param  file: pointer to the source file name
00193   * @param  line: assert_param error line source number
00194   * @retval None
00195   */
00196 void assert_failed(uint8_t* file, uint32_t line)
00197 { 
00198   /* User can add his own implementation to report the file name and line number,
00199      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00200 
00201   /* Infinite loop */
00202   while (1)
00203   {
00204   }
00205 }
00206 #endif
00207 
00208 /**
00209   * @}
00210   */
00211 
00212 
00213 /******************* (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