STM32F10x_StdPeriph_Examples/USART/MultiProcessor/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    USART/MultiProcessor/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 "platform_config.h"
00024 
00025 /** @addtogroup STM32F10x_StdPeriph_Examples
00026   * @{
00027   */
00028 
00029 /** @addtogroup USART_MultiProcessor
00030   * @{
00031   */ 
00032 
00033 /* Private typedef -----------------------------------------------------------*/
00034 /* Private define ------------------------------------------------------------*/
00035 /* Private macro -------------------------------------------------------------*/
00036 /* Private variables ---------------------------------------------------------*/
00037 USART_InitTypeDef USART_InitStructure;
00038 
00039 /* Private function prototypes -----------------------------------------------*/
00040 void RCC_Configuration(void);
00041 void GPIO_Configuration(void);
00042 void Delay(__IO uint32_t nCount);
00043 
00044 /* Private functions ---------------------------------------------------------*/
00045 /**
00046   * @brief   Main program
00047   * @param  None
00048   * @retval None
00049   */
00050 int main(void)
00051 {
00052   /*!< At this stage the microcontroller clock setting is already configured, 
00053        this is done through SystemInit() function which is called from startup
00054        file (startup_stm32f10x_xx.s) before to branch to application main.
00055        To reconfigure the default setting of SystemInit() function, refer to
00056        system_stm32f10x.c file
00057      */     
00058        
00059   /* System Clocks Configuration */
00060   RCC_Configuration();
00061        
00062   /* Configure the GPIO ports */
00063   GPIO_Configuration();
00064 
00065   /* Initialize Leds, Wakeup and Key Buttons mounted on STM3210X-EVAL board */ 
00066   STM_EVAL_LEDInit(LED1);
00067   STM_EVAL_LEDInit(LED2);
00068   STM_EVAL_LEDInit(LED3);
00069   STM_EVAL_LEDInit(LED4);
00070   STM_EVAL_PBInit(BUTTON_WAKEUP, BUTTON_MODE_EXTI);          
00071   STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);  
00072 
00073 /* USARTy and USARTz configuration -------------------------------------------*/
00074   /* USARTy and USARTz configured as follow:
00075         - BaudRate = 9600 baud  
00076         - Word Length = 9 Bits
00077         - One Stop Bit
00078         - No parity
00079         - Hardware flow control disabled (RTS and CTS signals)
00080         - Receive and transmit enabled
00081   */
00082   USART_InitStructure.USART_BaudRate = 9600;
00083   USART_InitStructure.USART_WordLength = USART_WordLength_9b;
00084   USART_InitStructure.USART_StopBits = USART_StopBits_1;
00085   USART_InitStructure.USART_Parity = USART_Parity_No;
00086   USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
00087   USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
00088   
00089   /* Configure USARTy */
00090   USART_Init(USARTy, &USART_InitStructure);
00091   /* Configure USARTz */
00092   USART_Init(USARTz, &USART_InitStructure);
00093   
00094   /* Enable the USARTy */
00095   USART_Cmd(USARTy, ENABLE);
00096   /* Enable the USARTz */
00097   USART_Cmd(USARTz, ENABLE);
00098 
00099   /* Set the USARTy Address */
00100   USART_SetAddress(USARTy, 0x1);
00101   /* Set the USARTz Address */
00102   USART_SetAddress(USARTz, 0x2);
00103 
00104   /* Select the USARTz WakeUp Method */
00105   USART_WakeUpConfig(USARTz, USART_WakeUp_AddressMark);
00106   
00107   while (1)
00108   {
00109     /* Send one byte from USARTy to USARTz */
00110     USART_SendData(USARTy, 0x33);
00111     
00112     /* Wait while USART1 TXE = 0 */
00113     while(USART_GetFlagStatus(USARTz, USART_FLAG_TXE) == RESET)
00114     {
00115     }
00116     
00117     if(USART_GetFlagStatus(USARTz, USART_FLAG_RXNE) != RESET)
00118     {
00119       if(USART_ReceiveData(USARTz) == 0x33)
00120       {
00121         STM_EVAL_LEDToggle(LED1);
00122         Delay(0x5FFFF);
00123         STM_EVAL_LEDToggle(LED2);
00124         Delay(0x5FFFF);
00125         STM_EVAL_LEDToggle(LED3);
00126         Delay(0x5FFFF);
00127         STM_EVAL_LEDToggle(LED4);
00128         Delay(0x5FFFF);
00129       }
00130     }
00131   }
00132 }
00133 
00134 /**
00135   * @brief  Configures the different system clocks.
00136   * @param  None
00137   * @retval None
00138   */
00139 void RCC_Configuration(void)
00140 {
00141   /* Enable GPIO clock */
00142   RCC_APB2PeriphClockCmd(USARTy_GPIO_CLK | USARTz_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE);
00143 
00144 #ifndef USE_STM3210C_EVAL
00145   /* Enable USARTy Clock */
00146   RCC_APB2PeriphClockCmd(USARTy_CLK, ENABLE); 
00147 #else
00148   /* Enable USARTy Clock */
00149   RCC_APB1PeriphClockCmd(USARTy_CLK, ENABLE); 
00150 #endif
00151   /* Enable USARTz Clock */
00152   RCC_APB1PeriphClockCmd(USARTz_CLK, ENABLE);  
00153 }
00154 
00155 /**
00156   * @brief  Configures the different GPIO ports.
00157   * @param  None
00158   * @retval None
00159   */
00160 void GPIO_Configuration(void)
00161 {
00162   GPIO_InitTypeDef GPIO_InitStructure;
00163 
00164 #ifdef USE_STM3210C_EVAL
00165   /* Enable the USART3 Pins Software Remapping */
00166   GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE);
00167   
00168   /* Enable the USART2 Pins Software Remapping */
00169   GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);  
00170 #elif defined(USE_STM3210B_EVAL) || defined(USE_STM32100B_EVAL)
00171   /* Enable the USART2 Pins Software Remapping */
00172   GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
00173 #endif
00174 
00175   /* Configure USARTy Rx as input floating */
00176   GPIO_InitStructure.GPIO_Pin = USARTy_RxPin;
00177   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00178   GPIO_Init(USARTy_GPIO, &GPIO_InitStructure);
00179   
00180   /* Configure USARTz Rx as input floating */
00181   GPIO_InitStructure.GPIO_Pin = USARTz_RxPin;
00182   GPIO_Init(USARTz_GPIO, &GPIO_InitStructure);  
00183   
00184   /* Configure USARTy Tx as alternate function push-pull */
00185   GPIO_InitStructure.GPIO_Pin = USARTy_TxPin;
00186   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00187   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
00188   GPIO_Init(USARTy_GPIO, &GPIO_InitStructure);
00189 
00190   /* Configure USARTz Tx as alternate function push-pull */
00191   GPIO_InitStructure.GPIO_Pin = USARTz_TxPin;
00192   GPIO_Init(USARTz_GPIO, &GPIO_InitStructure);  
00193 }
00194 
00195 /**
00196   * @brief  Inserts a delay time.
00197   * @param  nCount: specifies the delay time length.
00198   * @retval None
00199   */
00200 void Delay(__IO uint32_t nCount)
00201 {
00202   /* Decrement nCount value */
00203   for(; nCount != 0; nCount--);
00204 }
00205 
00206 #ifdef  USE_FULL_ASSERT
00207 
00208 /**
00209   * @brief  Reports the name of the source file and the source line number
00210   *         where the assert_param error has occurred.
00211   * @param  file: pointer to the source file name
00212   * @param  line: assert_param error line source number
00213   * @retval None
00214   */
00215 void assert_failed(uint8_t* file, uint32_t line)
00216 { 
00217   /* User can add his own implementation to report the file name and line number,
00218      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00219 
00220   /* Infinite loop */
00221   while (1)
00222   {
00223   }
00224 }
00225 #endif
00226 
00227 /**
00228   * @}
00229   */ 
00230 
00231 /**
00232   * @}
00233   */ 
00234 
00235 /******************* (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