comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/DMA/FLASH_RAM/main.c @ 0:c59513fd84fb

Initial commit of STM32 test code.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 03 Oct 2011 21:19:15 +1030
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c59513fd84fb
1 /**
2 ******************************************************************************
3 * @file DMA/FLASH_RAM/main.c
4 * @author MCD Application Team
5 * @version V3.5.0
6 * @date 08-April-2011
7 * @brief Main program body
8 ******************************************************************************
9 * @attention
10 *
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 *
18 * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
19 ******************************************************************************
20 */
21
22 /* Includes ------------------------------------------------------------------*/
23 #include "stm32f10x.h"
24
25 /** @addtogroup STM32F10x_StdPeriph_Examples
26 * @{
27 */
28
29 /** @addtogroup DMA_FLASH_RAM
30 * @{
31 */
32
33 /* Private typedef -----------------------------------------------------------*/
34 typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
35
36 /* Private define ------------------------------------------------------------*/
37 #define BufferSize 32
38
39 /* Private macro -------------------------------------------------------------*/
40 /* Private variables ---------------------------------------------------------*/
41 DMA_InitTypeDef DMA_InitStructure;
42 __IO uint32_t CurrDataCounterBegin = 0;
43 __IO uint32_t CurrDataCounterEnd = 0x01; /* This variable should not be initialized to 0 */
44
45 TestStatus TransferStatus = FAILED;
46 const uint32_t SRC_Const_Buffer[BufferSize]= {
47 0x01020304,0x05060708,0x090A0B0C,0x0D0E0F10,
48 0x11121314,0x15161718,0x191A1B1C,0x1D1E1F20,
49 0x21222324,0x25262728,0x292A2B2C,0x2D2E2F30,
50 0x31323334,0x35363738,0x393A3B3C,0x3D3E3F40,
51 0x41424344,0x45464748,0x494A4B4C,0x4D4E4F50,
52 0x51525354,0x55565758,0x595A5B5C,0x5D5E5F60,
53 0x61626364,0x65666768,0x696A6B6C,0x6D6E6F70,
54 0x71727374,0x75767778,0x797A7B7C,0x7D7E7F80};
55 uint32_t DST_Buffer[BufferSize];
56
57 /* Private function prototypes -----------------------------------------------*/
58 void RCC_Configuration(void);
59 void NVIC_Configuration(void);
60 TestStatus Buffercmp(const uint32_t* pBuffer, uint32_t* pBuffer1, uint16_t BufferLength);
61
62 /* Private functions ---------------------------------------------------------*/
63
64 /**
65 * @brief Main program
66 * @param None
67 * @retval None
68 */
69 int main(void)
70 {
71 /*!< At this stage the microcontroller clock setting is already configured,
72 this is done through SystemInit() function which is called from startup
73 file (startup_stm32f10x_xx.s) before to branch to application main.
74 To reconfigure the default setting of SystemInit() function, refer to
75 system_stm32f10x.c file
76 */
77
78 /* System Clocks Configuration */
79 RCC_Configuration();
80
81 /* NVIC configuration */
82 NVIC_Configuration();
83
84 /* DMA1 channel6 configuration */
85 DMA_DeInit(DMA1_Channel6);
86 DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SRC_Const_Buffer;
87 DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)DST_Buffer;
88 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
89 DMA_InitStructure.DMA_BufferSize = BufferSize;
90 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;
91 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
92 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
93 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
94 DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
95 DMA_InitStructure.DMA_Priority = DMA_Priority_High;
96 DMA_InitStructure.DMA_M2M = DMA_M2M_Enable;
97 DMA_Init(DMA1_Channel6, &DMA_InitStructure);
98
99 /* Enable DMA1 Channel6 Transfer Complete interrupt */
100 DMA_ITConfig(DMA1_Channel6, DMA_IT_TC, ENABLE);
101
102 /* Get Current Data Counter value before transfer begins */
103 CurrDataCounterBegin = DMA_GetCurrDataCounter(DMA1_Channel6);
104
105 /* Enable DMA1 Channel6 transfer */
106 DMA_Cmd(DMA1_Channel6, ENABLE);
107
108 /* Wait the end of transmission */
109 while (CurrDataCounterEnd != 0)
110 {
111 }
112
113 /* Check if the transmitted and received data are equal */
114 TransferStatus = Buffercmp(SRC_Const_Buffer, DST_Buffer, BufferSize);
115 /* TransferStatus = PASSED, if the transmitted and received data
116 are the same */
117 /* TransferStatus = FAILED, if the transmitted and received data
118 are different */
119
120 while (1)
121 {
122 }
123 }
124
125 /**
126 * @brief Configures the different system clocks.
127 * @param None
128 * @retval None
129 */
130 void RCC_Configuration(void)
131 {
132 /* Enable peripheral clocks ------------------------------------------------*/
133 /* Enable DMA1 clock */
134 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
135 }
136
137 /**
138 * @brief Configure the nested vectored interrupt controller.
139 * @param None
140 * @retval None
141 */
142 void NVIC_Configuration(void)
143 {
144 NVIC_InitTypeDef NVIC_InitStructure;
145
146 /* Enable DMA1 channel6 IRQ Channel */
147 NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel6_IRQn;
148 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
149 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
150 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
151 NVIC_Init(&NVIC_InitStructure);
152 }
153
154 /**
155 * @brief Compares two buffers.
156 * @param pBuffer, pBuffer1: buffers to be compared.
157 * @param BufferLength: buffer's length
158 * @retval PASSED: pBuffer identical to pBuffer1
159 * FAILED: pBuffer differs from pBuffer1
160 */
161 TestStatus Buffercmp(const uint32_t* pBuffer, uint32_t* pBuffer1, uint16_t BufferLength)
162 {
163 while(BufferLength--)
164 {
165 if(*pBuffer != *pBuffer1)
166 {
167 return FAILED;
168 }
169
170 pBuffer++;
171 pBuffer1++;
172 }
173
174 return PASSED;
175 }
176
177 #ifdef USE_FULL_ASSERT
178
179 /**
180 * @brief Reports the name of the source file and the source line number
181 * where the assert_param error has occurred.
182 * @param file: pointer to the source file name
183 * @param line: assert_param error line source number
184 * @retval None
185 */
186 void assert_failed(uint8_t* file, uint32_t line)
187 {
188 /* User can add his own implementation to report the file name and line number,
189 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
190
191 /* Infinite loop */
192 while (1)
193 {
194 }
195 }
196
197 #endif
198 /**
199 * @}
200 */
201
202 /**
203 * @}
204 */
205
206 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/