STM32F10x_StdPeriph_Examples/USART/Printf/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    USART/Printf/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 /** @addtogroup STM32F10x_StdPeriph_Examples
00027   * @{
00028   */
00029 
00030 /** @addtogroup USART_Printf
00031   * @{
00032   */ 
00033 
00034 /* Private typedef -----------------------------------------------------------*/
00035 /* Private define ------------------------------------------------------------*/
00036 /* Private macro -------------------------------------------------------------*/
00037 /* Private variables ---------------------------------------------------------*/
00038 USART_InitTypeDef USART_InitStructure;
00039 
00040 /* Private function prototypes -----------------------------------------------*/
00041 
00042 #ifdef __GNUC__
00043   /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
00044      set to 'Yes') calls __io_putchar() */
00045   #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
00046 #else
00047   #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
00048 #endif /* __GNUC__ */
00049   
00050 /* Private functions ---------------------------------------------------------*/
00051 
00052 /**
00053   * @brief  Main program
00054   * @param  None
00055   * @retval None
00056   */
00057 int main(void)
00058 {
00059   /*!< At this stage the microcontroller clock setting is already configured, 
00060        this is done through SystemInit() function which is called from startup
00061        file (startup_stm32f10x_xx.s) before to branch to application main.
00062        To reconfigure the default setting of SystemInit() function, refer to
00063        system_stm32f10x.c file
00064      */     
00065        
00066   /* USARTx configured as follow:
00067         - BaudRate = 115200 baud  
00068         - Word Length = 8 Bits
00069         - One Stop Bit
00070         - No parity
00071         - Hardware flow control disabled (RTS and CTS signals)
00072         - Receive and transmit enabled
00073   */
00074   USART_InitStructure.USART_BaudRate = 115200;
00075   USART_InitStructure.USART_WordLength = USART_WordLength_8b;
00076   USART_InitStructure.USART_StopBits = USART_StopBits_1;
00077   USART_InitStructure.USART_Parity = USART_Parity_No;
00078   USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
00079   USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
00080 
00081   STM_EVAL_COMInit(COM1, &USART_InitStructure);
00082 
00083   /* Output a message on Hyperterminal using printf function */
00084   printf("\n\rUSART Printf Example: retarget the C library printf function to the USART\n\r");
00085 
00086   while (1)
00087   {
00088   }
00089 }
00090 
00091 /**
00092   * @brief  Retargets the C library printf function to the USART.
00093   * @param  None
00094   * @retval None
00095   */
00096 PUTCHAR_PROTOTYPE
00097 {
00098   /* Place your implementation of fputc here */
00099   /* e.g. write a character to the USART */
00100   USART_SendData(EVAL_COM1, (uint8_t) ch);
00101 
00102   /* Loop until the end of transmission */
00103   while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
00104   {}
00105 
00106   return ch;
00107 }
00108 
00109 #ifdef  USE_FULL_ASSERT
00110 
00111 /**
00112   * @brief  Reports the name of the source file and the source line number
00113   *         where the assert_param error has occurred.
00114   * @param  file: pointer to the source file name
00115   * @param  line: assert_param error line source number
00116   * @retval None
00117   */
00118 void assert_failed(uint8_t* file, uint32_t line)
00119 { 
00120   /* User can add his own implementation to report the file name and line number,
00121      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00122 
00123   /* Infinite loop */
00124   while (1)
00125   {
00126   }
00127 }
00128 #endif
00129 
00130 /**
00131   * @}
00132   */ 
00133 
00134 /**
00135   * @}
00136   */ 
00137 
00138 /******************* (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