STM32F10x_StdPeriph_Examples/NVIC/DMA_WFIMode/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    NVIC/DMA_WFIMode/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 
00025 /** @addtogroup STM32F10x_StdPeriph_Examples
00026   * @{
00027   */
00028 
00029 /** @addtogroup NVIC_DMA_WFIMode
00030   * @{
00031   */
00032 
00033 /* Private typedef -----------------------------------------------------------*/
00034 /* Private define ------------------------------------------------------------*/
00035 #ifdef USE_STM3210C_EVAL
00036 #define USARTy_DR_Address    0x40004404
00037 #define USARTy_DMA1_Channel  DMA1_Channel6
00038 #define USARTy_DMA1_IRQn     DMA1_Channel6_IRQn
00039 #else
00040 #define USARTy_DR_Address    0x40013804
00041 #define USARTy_DMA1_Channel  DMA1_Channel5
00042 #define USARTy_DMA1_IRQn     DMA1_Channel5_IRQn
00043 #endif
00044 
00045 /* Private macro -------------------------------------------------------------*/
00046 /* Private variables ---------------------------------------------------------*/
00047 NVIC_InitTypeDef  NVIC_InitStructure;
00048 USART_InitTypeDef  USART_InitStructure;
00049 DMA_InitTypeDef  DMA_InitStructure;
00050 __IO uint32_t LowPowerMode = 0;
00051 uint16_t DST_Buffer[10]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
00052 
00053 /* Private function prototypes -----------------------------------------------*/
00054 void RCC_Configuration(void);
00055 void DMA_Configuration(void);
00056 uint8_t Buffercmp16(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength);
00057 void Delay(__IO uint32_t nCount);
00058 
00059 /* Private functions ---------------------------------------------------------*/
00060 
00061 /**
00062   * @brief   Main program.
00063   * @param  None
00064   * @retval None
00065   */
00066 int main(void)
00067 {
00068   /*!< At this stage the microcontroller clock setting is already configured, 
00069        this is done through SystemInit() function which is called from startup
00070        file (startup_stm32f10x_xx.s) before to branch to application main.
00071        To reconfigure the default setting of SystemInit() function, refer to
00072        system_stm32f10x.c file
00073      */     
00074        
00075   /* Configure the system clocks */
00076   RCC_Configuration();
00077 
00078   /* Initialize Leds and Key Button mounted on STM3210X-EVAL board */       
00079   STM_EVAL_LEDInit(LED1);
00080   STM_EVAL_LEDInit(LED2);
00081   STM_EVAL_LEDInit(LED3);
00082   STM_EVAL_LEDInit(LED4);
00083   STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI); 
00084  
00085   /* Configures the DMA Channel */
00086   DMA_Configuration();
00087   
00088 /* EVAL_COM1 configuration ---------------------------------------------------*/
00089   /* EVAL_COM1 configured as follow:
00090         - BaudRate = 115200 baud  
00091         - Word Length = 8 Bits
00092         - One Stop Bit
00093         - No parity
00094         - Hardware flow control disabled (RTS and CTS signals)
00095         - Receive and transmit enabled
00096   */
00097   USART_InitStructure.USART_BaudRate = 115200;
00098   USART_InitStructure.USART_WordLength = USART_WordLength_8b;
00099   USART_InitStructure.USART_StopBits = USART_StopBits_1;
00100   USART_InitStructure.USART_Parity = USART_Parity_No;
00101   USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
00102   USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
00103 
00104   STM_EVAL_COMInit(COM1, &USART_InitStructure);
00105   USART_DMACmd(EVAL_COM1, USART_DMAReq_Rx, ENABLE);
00106   
00107   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
00108   
00109   /* Enable the USARTy_DMA1_IRQn Interrupt */
00110   NVIC_InitStructure.NVIC_IRQChannel = USARTy_DMA1_IRQn;
00111   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
00112   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
00113   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00114   NVIC_Init(&NVIC_InitStructure);
00115 
00116   /* Enable the EXTI9_5  Interrupt */
00117   NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
00118   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
00119   NVIC_Init(&NVIC_InitStructure);
00120     
00121   while (1)
00122   {
00123     if(LowPowerMode == 1)
00124     {
00125 
00126       STM_EVAL_LEDOff(LED2);
00127       STM_EVAL_LEDOff(LED3);
00128 
00129       /* Request to enter WFI mode */
00130       __WFI();
00131       LowPowerMode = 0;
00132     }
00133 
00134     Delay(0xFFFFF);
00135     STM_EVAL_LEDToggle(LED1);
00136   }
00137 }
00138 
00139 /**
00140   * @brief  Configures the different system clocks
00141   * @param  None
00142   * @retval None
00143   */
00144 void RCC_Configuration(void)
00145 { 
00146   /* DMA1 clock enable */
00147   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
00148 }
00149 
00150 /**
00151   * @brief  Configures the used DMA Channel.
00152   * @param  None
00153   * @retval None
00154   */
00155 void DMA_Configuration(void)
00156 {
00157   DMA_InitTypeDef  DMA_InitStructure;
00158 
00159   /* USARTy_DMA1_Channel Config */
00160   DMA_DeInit(USARTy_DMA1_Channel);
00161   DMA_InitStructure.DMA_PeripheralBaseAddr = USARTy_DR_Address;
00162   DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)DST_Buffer;
00163   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
00164   DMA_InitStructure.DMA_BufferSize = 10;
00165   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
00166   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
00167   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
00168   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
00169   DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
00170   DMA_InitStructure.DMA_Priority = DMA_Priority_High;
00171   DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
00172   DMA_Init(USARTy_DMA1_Channel, &DMA_InitStructure);
00173 
00174   /* Enable USARTy_DMA1_Channel Transfer complete interrupt */
00175   DMA_ITConfig(USARTy_DMA1_Channel, DMA_IT_TC, ENABLE);
00176   
00177   /* USARTy_DMA1_Channel enable */
00178   DMA_Cmd(USARTy_DMA1_Channel, ENABLE);
00179 }
00180 
00181 /**
00182   * @brief  Compares two buffers.
00183   * @param  pBuffer1, pBuffer2: buffers to be compared.
00184   * @param  BufferLength: buffer's length
00185   * @retval 0: pBuffer1 identical to pBuffer2
00186   *           1: pBuffer1 differs from pBuffer2
00187   */
00188 uint8_t Buffercmp16(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength)
00189 {
00190   while(BufferLength--)
00191   {
00192     if(*pBuffer1 != *pBuffer2)
00193     {
00194       return 1;
00195     }
00196 
00197     pBuffer1++;
00198     pBuffer2++;
00199   }
00200   return 0;
00201 }
00202 
00203 /**
00204   * @brief  Inserts a delay time.
00205   * @param  nCount: specifies the delay time length.
00206   * @retval None
00207   */
00208 void Delay(__IO uint32_t nCount)
00209 {
00210   for(; nCount != 0; nCount--);
00211 }
00212 
00213 #ifdef  USE_FULL_ASSERT
00214 /**
00215   * @brief  Reports the name of the source file and the source line number
00216   *         where the assert_param error has occurred.
00217   * @param  file: pointer to the source file name
00218   * @param  line: assert_param error line source number
00219   * @retval None
00220   */
00221 void assert_failed(uint8_t* file, uint32_t line)
00222 { 
00223   /* User can add his own implementation to report the file name and line number,
00224      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00225 
00226   /* Infinite loop */
00227   while (1)
00228   {
00229   }
00230 }
00231 #endif
00232 
00233 /**
00234   * @}
00235   */ 
00236 
00237 /**
00238   * @}
00239   */ 
00240 
00241 /******************* (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