STM32F10x_StdPeriph_Examples/DMA/FLASH_RAM/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    DMA/FLASH_RAM/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 
00024 /** @addtogroup STM32F10x_StdPeriph_Examples
00025   * @{
00026   */
00027 
00028 /** @addtogroup DMA_FLASH_RAM
00029   * @{
00030   */ 
00031 
00032 /* Private typedef -----------------------------------------------------------*/
00033 typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
00034 
00035 /* Private define ------------------------------------------------------------*/
00036 #define BufferSize  32
00037 
00038 /* Private macro -------------------------------------------------------------*/
00039 /* Private variables ---------------------------------------------------------*/
00040 DMA_InitTypeDef  DMA_InitStructure;
00041 __IO uint32_t CurrDataCounterBegin = 0;
00042 __IO uint32_t CurrDataCounterEnd = 0x01; /* This variable should not be initialized to 0 */
00043 
00044 TestStatus TransferStatus = FAILED;
00045 const uint32_t SRC_Const_Buffer[BufferSize]= {
00046                                     0x01020304,0x05060708,0x090A0B0C,0x0D0E0F10,
00047                                     0x11121314,0x15161718,0x191A1B1C,0x1D1E1F20,
00048                                     0x21222324,0x25262728,0x292A2B2C,0x2D2E2F30,
00049                                     0x31323334,0x35363738,0x393A3B3C,0x3D3E3F40,
00050                                     0x41424344,0x45464748,0x494A4B4C,0x4D4E4F50,
00051                                     0x51525354,0x55565758,0x595A5B5C,0x5D5E5F60,
00052                                     0x61626364,0x65666768,0x696A6B6C,0x6D6E6F70,
00053                                     0x71727374,0x75767778,0x797A7B7C,0x7D7E7F80};
00054 uint32_t DST_Buffer[BufferSize];
00055 
00056 /* Private function prototypes -----------------------------------------------*/
00057 void RCC_Configuration(void);
00058 void NVIC_Configuration(void);
00059 TestStatus Buffercmp(const uint32_t* pBuffer, uint32_t* pBuffer1, uint16_t BufferLength);
00060     
00061 /* Private functions ---------------------------------------------------------*/
00062 
00063 /**
00064   * @brief  Main program
00065   * @param  None
00066   * @retval None
00067   */
00068 int main(void)
00069 {
00070   /*!< At this stage the microcontroller clock setting is already configured, 
00071        this is done through SystemInit() function which is called from startup
00072        file (startup_stm32f10x_xx.s) before to branch to application main.
00073        To reconfigure the default setting of SystemInit() function, refer to
00074        system_stm32f10x.c file
00075      */     
00076        
00077   /* System Clocks Configuration */
00078   RCC_Configuration();
00079        
00080   /* NVIC configuration */
00081   NVIC_Configuration();
00082 
00083   /* DMA1 channel6 configuration */
00084   DMA_DeInit(DMA1_Channel6);
00085   DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SRC_Const_Buffer;
00086   DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)DST_Buffer;
00087   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
00088   DMA_InitStructure.DMA_BufferSize = BufferSize;
00089   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;
00090   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
00091   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
00092   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
00093   DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
00094   DMA_InitStructure.DMA_Priority = DMA_Priority_High;
00095   DMA_InitStructure.DMA_M2M = DMA_M2M_Enable;
00096   DMA_Init(DMA1_Channel6, &DMA_InitStructure);
00097 
00098   /* Enable DMA1 Channel6 Transfer Complete interrupt */
00099   DMA_ITConfig(DMA1_Channel6, DMA_IT_TC, ENABLE);
00100 
00101   /* Get Current Data Counter value before transfer begins */
00102   CurrDataCounterBegin = DMA_GetCurrDataCounter(DMA1_Channel6);
00103 
00104   /* Enable DMA1 Channel6 transfer */
00105   DMA_Cmd(DMA1_Channel6, ENABLE);
00106 
00107   /* Wait the end of transmission */
00108   while (CurrDataCounterEnd != 0)
00109   {
00110   }
00111   
00112   /* Check if the transmitted and received data are equal */
00113   TransferStatus = Buffercmp(SRC_Const_Buffer, DST_Buffer, BufferSize);
00114   /* TransferStatus = PASSED, if the transmitted and received data 
00115      are the same */
00116   /* TransferStatus = FAILED, if the transmitted and received data 
00117      are different */
00118 
00119   while (1)
00120   {
00121   }
00122 }
00123 
00124 /**
00125   * @brief  Configures the different system clocks.
00126   * @param  None
00127   * @retval None
00128   */
00129 void RCC_Configuration(void)
00130 {
00131   /* Enable peripheral clocks ------------------------------------------------*/
00132   /* Enable DMA1 clock */
00133   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
00134 }
00135 
00136 /**
00137   * @brief  Configure the nested vectored interrupt controller.
00138   * @param  None
00139   * @retval None
00140   */
00141 void NVIC_Configuration(void)
00142 {
00143   NVIC_InitTypeDef NVIC_InitStructure;
00144   
00145   /* Enable DMA1 channel6 IRQ Channel */
00146   NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel6_IRQn;
00147   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
00148   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
00149   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00150   NVIC_Init(&NVIC_InitStructure);
00151 }
00152 
00153 /**
00154   * @brief  Compares two buffers.
00155   * @param  pBuffer, pBuffer1: buffers to be compared.
00156   * @param  BufferLength: buffer's length
00157   * @retval PASSED: pBuffer identical to pBuffer1
00158   *   FAILED: pBuffer differs from pBuffer1
00159   */
00160 TestStatus Buffercmp(const uint32_t* pBuffer, uint32_t* pBuffer1, uint16_t BufferLength)
00161 {
00162   while(BufferLength--)
00163   {
00164     if(*pBuffer != *pBuffer1)
00165     {
00166       return FAILED;
00167     }
00168     
00169     pBuffer++;
00170     pBuffer1++;
00171   }
00172 
00173   return PASSED;  
00174 }
00175 
00176 #ifdef  USE_FULL_ASSERT
00177 /**
00178   * @brief  Reports the name of the source file and the source line number
00179   *         where the assert_param error has occurred.
00180   * @param  file: pointer to the source file name
00181   * @param  line: assert_param error line source number
00182   * @retval None
00183   */
00184 void assert_failed(uint8_t* file, uint32_t line)
00185 { 
00186   /* User can add his own implementation to report the file name and line number,
00187      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00188 
00189   /* Infinite loop */
00190   while (1)
00191   {
00192   }
00193 }
00194 #endif
00195 /**
00196   * @}
00197   */ 
00198 
00199 /**
00200   * @}
00201   */ 
00202 
00203 /******************* (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