STM32F0xx Standard Peripherals Firmware Library: main.c Source File

STM32F0xx Standard Peripherals Library

STM32F0xx_StdPeriph_Examples/Lib_DEBUG/Lib_DEBUG_Example/main.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    Lib_DEBUG/Lib_DEBUG_Example/main.c 
00004   * @author  MCD Application Team
00005   * @version V1.4.0
00006   * @date    24-July-2014
00007   * @brief   Main program body
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
00012   *
00013   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00014   * You may not use this file except in compliance with the License.
00015   * You may obtain a copy of the License at:
00016   *
00017   *        http://www.st.com/software_license_agreement_liberty_v2
00018   *
00019   * Unless required by applicable law or agreed to in writing, software 
00020   * distributed under the License is distributed on an "AS IS" BASIS, 
00021   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00022   * See the License for the specific language governing permissions and
00023   * limitations under the License.
00024   *
00025   ******************************************************************************
00026   */
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "main.h"
00030 
00031 /** @addtogroup STM32F0xx_StdPeriph_Examples
00032   * @{
00033   */
00034 
00035 /** @addtogroup Lib_DEBUG_Example
00036   * @{
00037   */
00038 
00039 /* Private typedef -----------------------------------------------------------*/
00040 /* Private define ------------------------------------------------------------*/
00041 /* Private macro -------------------------------------------------------------*/
00042 /* Private variables ---------------------------------------------------------*/
00043 USART_InitTypeDef USART_InitStructure;
00044 
00045 /* Private function prototypes -----------------------------------------------*/
00046 #ifdef __GNUC__
00047  /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
00048     set to 'Yes') calls __io_putchar() */
00049  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
00050 #else
00051  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
00052 #endif /* __GNUC__ */
00053 
00054 /* Private functions ---------------------------------------------------------*/
00055 
00056 /**
00057   * @brief  Main program.
00058   * @param  None
00059   * @retval None
00060   */
00061 int main(void)
00062 {
00063   /*!< At this stage the microcontroller clock setting is already configured, 
00064        this is done through SystemInit() function which is called from startup
00065        file (startup_stm32f0xx.s) before to branch to application main.
00066        To reconfigure the default setting of SystemInit() function, refer to
00067        system_stm32f0xx.c file
00068      */ 
00069   GPIO_InitTypeDef GPIOA_InitStructure;
00070 
00071   /* USARTx configured as follow:
00072         - BaudRate = 115200 baud  
00073         - Word Length = 8 Bits
00074         - One Stop Bit
00075         - No parity
00076         - Hardware flow control disabled (RTS and CTS signals)
00077         - Receive and transmit enabled
00078   */
00079   USART_InitStructure.USART_BaudRate = 115200;
00080   USART_InitStructure.USART_WordLength = USART_WordLength_8b;
00081   USART_InitStructure.USART_StopBits = USART_StopBits_1;
00082   USART_InitStructure.USART_Parity = USART_Parity_No;
00083   USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
00084   USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
00085 
00086   STM_EVAL_COMInit(COM1, &USART_InitStructure);
00087   
00088   /* Initialize all peripherals pointers */
00089   IP_Debug();
00090   
00091   printf("\r\n STM32F0xx Firmware Library compiled with FULL ASSERT function... \n\r");
00092   printf("...Run-time checking enabled  \n\r");
00093 
00094   /* Simulate wrong parameter passed to library function ---------------------*/
00095   /* To enable SPI1 clock, RCC_APB2PeriphClockCmd function must be used and
00096      not RCC_APB1PeriphClockCmd */
00097   RCC_APB1PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
00098   
00099   /* Some member of GPIOA_InitStructure structure are not initialized */
00100   GPIOA_InitStructure.GPIO_Pin = GPIO_Pin_6;
00101   GPIOA_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
00102   /*GPIOA_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;*/
00103   GPIOA_InitStructure.GPIO_OType = GPIO_OType_PP;
00104   GPIOA_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; 
00105   GPIO_Init(GPIOA, &GPIOA_InitStructure);
00106   /* Infinite loop */
00107   while (1)
00108   {
00109   }
00110 }
00111 
00112 /**
00113   * @brief  Retargets the C library printf function to the USART.
00114   * @param  None
00115   * @retval None
00116   */
00117 PUTCHAR_PROTOTYPE
00118 {
00119   /* Place your implementation of fputc here */
00120   /* e.g. write a character to the USART */
00121   USART_SendData(EVAL_COM1, (uint8_t) ch);
00122 
00123   /* Loop until the end of transmission */
00124   while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
00125   {}
00126 
00127   return ch;
00128 }
00129 
00130 #ifdef  USE_FULL_ASSERT
00131 
00132 /**
00133   * @brief  Reports the name of the source file and the source line number
00134   *         where the assert_param error has occurred.
00135   * @param  file: pointer to the source file name
00136   * @param  line: assert_param error line source number
00137   * @retval None
00138   */
00139 void assert_failed(uint8_t* file, uint32_t line)
00140 { 
00141   /* User can add his own implementation to report the file name and line number */
00142 
00143   printf("\n\r Wrong parameter value detected on\r\n");
00144   printf("       file  %s\r\n", file);
00145   printf("       line  %d\r\n", line);
00146     
00147   /* Infinite loop */
00148   /* while (1)
00149   {
00150   } */
00151 }
00152 #endif
00153 
00154 /**
00155   * @}
00156   */
00157 
00158 /**
00159   * @}
00160   */
00161 
00162 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM32L1xx Standard Peripherals Library: Footer

 

 

 For complete documentation on STM32 Microcontrollers visit www.st.com/STM32