STM32F0xx Standard Peripherals Firmware Library
|
STM32F0xx_StdPeriph_Examples/DMA/DMA_FLASHRAMTransfer/main.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file DMA/DMA_FLASHRAMTransfer/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>© 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 DMA_FLASHRAMTransfer 00036 * @{ 00037 */ 00038 00039 /* Private typedef -----------------------------------------------------------*/ 00040 typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus; 00041 00042 /* Private define ------------------------------------------------------------*/ 00043 #define BUFFER_SIZE 32 00044 00045 /* Private macro -------------------------------------------------------------*/ 00046 /* Private variables ---------------------------------------------------------*/ 00047 __IO uint32_t EndOfTransfer = 0; 00048 __IO TestStatus TransferStatus = FAILED; 00049 const uint32_t SrcBuffer[BUFFER_SIZE]= { 00050 0x01020304,0x05060708,0x090A0B0C,0x0D0E0F10, 00051 0x11121314,0x15161718,0x191A1B1C,0x1D1E1F20, 00052 0x21222324,0x25262728,0x292A2B2C,0x2D2E2F30, 00053 0x31323334,0x35363738,0x393A3B3C,0x3D3E3F40, 00054 0x41424344,0x45464748,0x494A4B4C,0x4D4E4F50, 00055 0x51525354,0x55565758,0x595A5B5C,0x5D5E5F60, 00056 0x61626364,0x65666768,0x696A6B6C,0x6D6E6F70, 00057 0x71727374,0x75767778,0x797A7B7C,0x7D7E7F80}; 00058 uint32_t DstBuffer[BUFFER_SIZE]; 00059 00060 /* Private function prototypes -----------------------------------------------*/ 00061 static void DMA_Config(void); 00062 static TestStatus Buffercmp(const uint32_t* pBuffer, uint32_t* pBuffer1, uint16_t BufferLength); 00063 /* Private functions ---------------------------------------------------------*/ 00064 00065 /** 00066 * @brief Main program. 00067 * @param None 00068 * @retval None 00069 */ 00070 int main(void) 00071 { 00072 /*!< At this stage the microcontroller clock setting is already configured, 00073 this is done through SystemInit() function which is called from startup 00074 file (startup_stm32f0xx.s) before to branch to application main. 00075 To reconfigure the default setting of SystemInit() function, refer to 00076 system_stm32f0xx.c file 00077 */ 00078 00079 /* DMA1 channel1 configuration ---------------------------------------------*/ 00080 DMA_Config(); 00081 00082 /* Wait the end of transmission */ 00083 while (EndOfTransfer == 0) 00084 { 00085 } 00086 00087 /* Check if the destination "DstBuffer" and source "SrcBuffer" buffers are equal */ 00088 TransferStatus = Buffercmp(SrcBuffer, DstBuffer, BUFFER_SIZE); 00089 /* TransferStatus = PASSED, destination and source buffers are the same */ 00090 /* TransferStatus = FAILED, destination and source buffers are different */ 00091 00092 while (1) 00093 { 00094 } 00095 } 00096 00097 /** 00098 * @brief Configures DMA1 channel3 to transfer data from FLASH to RAM 00099 * @param None 00100 * @retval None 00101 */ 00102 static void DMA_Config(void) 00103 { 00104 DMA_InitTypeDef DMA_InitStructure; 00105 NVIC_InitTypeDef NVIC_InitStructure; 00106 00107 /* Enable DMA1 clock */ 00108 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); 00109 DMA_DeInit(DMA1_Channel1); 00110 DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SrcBuffer; 00111 DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)DstBuffer; 00112 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; 00113 DMA_InitStructure.DMA_BufferSize = BUFFER_SIZE; 00114 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable; 00115 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; 00116 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; 00117 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; 00118 DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; 00119 DMA_InitStructure.DMA_Priority = DMA_Priority_High; 00120 DMA_InitStructure.DMA_M2M = DMA_M2M_Enable; 00121 DMA_Init(DMA1_Channel1, &DMA_InitStructure); 00122 00123 /* Enable DMA1 Channel1 Transfer Complete interrupt */ 00124 DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE); 00125 00126 /* Enable DMA1 channel1 IRQ Channel */ 00127 NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn; 00128 NVIC_InitStructure.NVIC_IRQChannelPriority = 0; 00129 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 00130 NVIC_Init(&NVIC_InitStructure); 00131 00132 /* Enable DMA1 Channel1 transfer */ 00133 DMA_Cmd(DMA1_Channel1, ENABLE); 00134 } 00135 00136 /** 00137 * @brief Compares two buffers. 00138 * @param pBuffer, pBuffer1: buffers to be compared. 00139 * @param BufferLength: buffer's length 00140 * @retval PASSED: pBuffer identical to pBuffer1 00141 * FAILED: pBuffer differs from pBuffer1 00142 */ 00143 static TestStatus Buffercmp(const uint32_t* pBuffer, uint32_t* pBuffer1, uint16_t BufferLength) 00144 { 00145 while(BufferLength--) 00146 { 00147 if(*pBuffer != *pBuffer1) 00148 { 00149 return FAILED; 00150 } 00151 pBuffer++; 00152 pBuffer1++; 00153 } 00154 00155 return PASSED; 00156 } 00157 00158 #ifdef USE_FULL_ASSERT 00159 00160 /** 00161 * @brief Reports the name of the source file and the source line number 00162 * where the assert_param error has occurred. 00163 * @param file: pointer to the source file name 00164 * @param line: assert_param error line source number 00165 * @retval None 00166 */ 00167 void assert_failed(uint8_t* file, uint32_t line) 00168 { 00169 /* User can add his own implementation to report the file name and line number, 00170 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 00171 00172 /* Infinite loop */ 00173 while (1) 00174 { 00175 } 00176 } 00177 #endif 00178 00179 /** 00180 * @} 00181 */ 00182 00183 /** 00184 * @} 00185 */ 00186 00187 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/