1 | /**
|
2 | ******************************************************************************
|
3 | * @file ADC/ADC_RegularConversion_DMA/Src/main.c
|
4 | * @author MCD Application Team
|
5 | * @brief This example describes how to use the DMA to transfer
|
6 | * continuously converted data.
|
7 | ******************************************************************************
|
8 | * @attention
|
9 | *
|
10 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
|
11 | *
|
12 | * Redistribution and use in source and binary forms, with or without modification,
|
13 | * are permitted provided that the following conditions are met:
|
14 | * 1. Redistributions of source code must retain the above copyright notice,
|
15 | * this list of conditions and the following disclaimer.
|
16 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
17 | * this list of conditions and the following disclaimer in the documentation
|
18 | * and/or other materials provided with the distribution.
|
19 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
|
20 | * may be used to endorse or promote products derived from this software
|
21 | * without specific prior written permission.
|
22 | *
|
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
29 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
31 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
33 | *
|
34 | ******************************************************************************
|
35 | */
|
36 |
|
37 | /* Includes ------------------------------------------------------------------*/
|
38 | #include "main.h"
|
39 | #include "stm32f7xx.h"
|
40 | #include "stm32746g_discovery.h"
|
41 | #include "stm32746g_discovery_lcd.h"
|
42 |
|
43 | /** @addtogroup STM32F7xx_HAL_Examples
|
44 | * @{
|
45 | */
|
46 |
|
47 | /** @addtogroup ADC_RegularConversion_DMA
|
48 | * @{
|
49 | */
|
50 |
|
51 | /* Private typedef -----------------------------------------------------------*/
|
52 | /* Private define ------------------------------------------------------------*/
|
53 | /* Private macro -------------------------------------------------------------*/
|
54 | /* Private variables ---------------------------------------------------------*/
|
55 | /* ADC handler declaration */
|
56 | ADC_HandleTypeDef AdcHandle;
|
57 |
|
58 | /* Variable used to get converted value */
|
59 | __IO uint16_t uhADCxConvertedValue = 0;
|
60 |
|
61 | /* Private function prototypes -----------------------------------------------*/
|
62 | static void SystemClock_Config(void);
|
63 | static void Error_Handler(void);
|
64 | static void MPU_Config(void);
|
65 | static void CPU_CACHE_Enable(void);
|
66 |
|
67 | /* Private functions ---------------------------------------------------------*/
|
68 |
|
69 | #define LCD_FRAME_BUFFER SDRAM_DEVICE_ADDR
|
70 | #define RGB565_BYTE_PER_PIXEL 2
|
71 | #define ARBG8888_BYTE_PER_PIXEL 4
|
72 |
|
73 | /**
|
74 | * @brief Main program.
|
75 | * @param None
|
76 | * @retval None
|
77 | */
|
78 | int main(void)
|
79 | {
|
80 | ADC_ChannelConfTypeDef sConfig;
|
81 |
|
82 | MPU_Config();
|
83 | CPU_CACHE_Enable();
|
84 | HAL_Init();
|
85 | SystemClock_Config();
|
86 |
|
87 | // Set up the LCD
|
88 | BSP_LCD_Init();
|
89 | BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FRAME_BUFFER);
|
90 | BSP_LCD_SetLayerVisible(LTDC_ACTIVE_LAYER, ENABLE);
|
91 | BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER);
|
92 | BSP_LCD_Clear(LCD_COLOR_BLACK);
|
93 | BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
|
94 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
|
95 | BSP_LCD_DisplayOn();
|
96 |
|
97 |
|
98 | /*##-1- Configure the ADC peripheral #######################################*/
|
99 | AdcHandle.Instance = ADCx;
|
100 | AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV4;
|
101 | AdcHandle.Init.Resolution = ADC_RESOLUTION_12B;
|
102 | AdcHandle.Init.ScanConvMode = DISABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
|
103 | AdcHandle.Init.ContinuousConvMode = ENABLE; /* Continuous mode enabled to have continuous conversion */
|
104 | AdcHandle.Init.DiscontinuousConvMode = DISABLE; /* Parameter discarded because sequencer is disabled */
|
105 | AdcHandle.Init.NbrOfDiscConversion = 0;
|
106 | AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Conversion start trigged at each external event */
|
107 | AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1;
|
108 | AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
109 | AdcHandle.Init.NbrOfConversion = 1;
|
110 | AdcHandle.Init.DMAContinuousRequests = ENABLE;
|
111 | AdcHandle.Init.EOCSelection = DISABLE;
|
112 |
|
113 | if (HAL_ADC_Init(&AdcHandle) != HAL_OK)
|
114 | {
|
115 | /* ADC initialization Error */
|
116 | Error_Handler();
|
117 | }
|
118 |
|
119 | /*##-2- Configure ADC regular channel ######################################*/
|
120 | sConfig.Channel = ADC_CHANNEL_0;
|
121 | sConfig.Rank = 1;
|
122 | sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
|
123 | sConfig.Offset = 0;
|
124 |
|
125 | if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK)
|
126 | {
|
127 | /* Channel Configuration Error */
|
128 | Error_Handler();
|
129 | }
|
130 |
|
131 | /*##-3- Start the conversion process #######################################*/
|
132 | //HAL_ADC_Start_DMA(&AdcHandle, (uint32_t*)&uhADCxConvertedValue, 1);
|
133 | HAL_ADC_Start(&AdcHandle);
|
134 |
|
135 | /* Infinite loop*/
|
136 | while (1)
|
137 | {
|
138 | uint8_t value = AdcHandle.State;
|
139 | //uint32_t *pointer = value;
|
140 |
|
141 | char buffer[30];
|
142 | sprintf(buffer, "HELLO WORLD!");
|
143 | BSP_LCD_DisplayStringAtLine(0, (uint32_t *) value);
|
144 | }
|
145 | }
|
146 |
|
147 | /**
|
148 | * @brief System Clock Configuration
|
149 | * The system Clock is configured as follow :
|
150 | * System Clock source = PLL (HSE)
|
151 | * SYSCLK(Hz) = 216000000
|
152 | * HCLK(Hz) = 216000000
|
153 | * AHB Prescaler = 1
|
154 | * APB1 Prescaler = 4
|
155 | * APB2 Prescaler = 2
|
156 | * HSE Frequency(Hz) = 25000000
|
157 | * PLL_M = 25
|
158 | * PLL_N = 432
|
159 | * PLL_P = 2
|
160 | * PLL_Q = 9
|
161 | * VDD(V) = 3.3
|
162 | * Main regulator output voltage = Scale1 mode
|
163 | * Flash Latency(WS) = 7
|
164 | * @param None
|
165 | * @retval None
|
166 | */
|
167 | void SystemClock_Config(void)
|
168 | {
|
169 | RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
170 | RCC_OscInitTypeDef RCC_OscInitStruct;
|
171 | HAL_StatusTypeDef ret = HAL_OK;
|
172 |
|
173 | /* Enable HSE Oscillator and activate PLL with HSE as source */
|
174 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
175 | RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
176 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
177 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
178 | RCC_OscInitStruct.PLL.PLLM = 25;
|
179 | RCC_OscInitStruct.PLL.PLLN = 432;
|
180 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
181 | RCC_OscInitStruct.PLL.PLLQ = 9;
|
182 |
|
183 | ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
184 | if(ret != HAL_OK)
|
185 | {
|
186 | while(1) { ; }
|
187 | }
|
188 |
|
189 | /* Activate the OverDrive to reach the 216 MHz Frequency */
|
190 | ret = HAL_PWREx_EnableOverDrive();
|
191 | if(ret != HAL_OK)
|
192 | {
|
193 | while(1) { ; }
|
194 | }
|
195 |
|
196 | /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
|
197 | RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
|
198 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
199 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
200 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
|
201 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
202 |
|
203 | ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7);
|
204 | if(ret != HAL_OK)
|
205 | {
|
206 | while(1) { ; }
|
207 | }
|
208 | }
|
209 |
|
210 | /**
|
211 | * @brief This function is executed in case of error occurrence.
|
212 | * @param None
|
213 | * @retval None
|
214 | */
|
215 | static void Error_Handler(void)
|
216 | {
|
217 | while (1)
|
218 | {
|
219 | /* LED1 blinks */
|
220 | BSP_LED_Toggle(LED1);
|
221 | HAL_Delay(20);
|
222 | }
|
223 | }
|
224 |
|
225 | static void MPU_Config(void)
|
226 | {
|
227 | MPU_Region_InitTypeDef MPU_InitStruct;
|
228 |
|
229 | /* Disable the MPU */
|
230 | HAL_MPU_Disable();
|
231 |
|
232 | /* Configure the MPU attributes as WT for SRAM */
|
233 | MPU_InitStruct.Enable = MPU_REGION_ENABLE;
|
234 | MPU_InitStruct.BaseAddress = 0x20010000;
|
235 | MPU_InitStruct.Size = MPU_REGION_SIZE_256KB;
|
236 | MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
|
237 | MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
|
238 | MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
|
239 | MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
|
240 | MPU_InitStruct.Number = MPU_REGION_NUMBER0;
|
241 | MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
|
242 | MPU_InitStruct.SubRegionDisable = 0x00;
|
243 | MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
|
244 |
|
245 | HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
246 |
|
247 | /* Enable the MPU */
|
248 | HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
|
249 | }
|
250 |
|
251 | /**
|
252 | * @brief Conversion complete callback in non blocking mode
|
253 | * @param AdcHandle : AdcHandle handle
|
254 | * @note This example shows a simple way to report end of conversion, and
|
255 | * you can add your own implementation.
|
256 | * @retval None
|
257 | */
|
258 | void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* AdcHandle)
|
259 | {
|
260 | /* Turn LED1 on: Transfer process is correct */
|
261 | BSP_LED_On(LED1);
|
262 | }
|
263 |
|
264 | /**
|
265 | * @brief CPU L1-Cache enable.
|
266 | * @param None
|
267 | * @retval None
|
268 | */
|
269 | static void CPU_CACHE_Enable(void)
|
270 | {
|
271 | /* Enable I-Cache */
|
272 | SCB_EnableICache();
|
273 |
|
274 | /* Enable D-Cache */
|
275 | SCB_EnableDCache();
|
276 | }
|
277 |
|
278 | #ifdef USE_FULL_ASSERT
|
279 | /**
|
280 | * @brief Reports the name of the source file and the source line number
|
281 | * where the assert_param error has occurred.
|
282 | * @param file: pointer to the source file name
|
283 | * @param line: assert_param error line source number
|
284 | * @retval None
|
285 | */
|
286 | void assert_failed(uint8_t *file, uint32_t line)
|
287 | {
|
288 | /* User can add his own implementation to report the file name and line number,
|
289 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
290 |
|
291 | /* Infinite loop */
|
292 | while (1)
|
293 | {
|
294 | }
|
295 | }
|
296 | #endif
|
297 |
|
298 | /**
|
299 | * @}
|
300 | */
|
301 |
|
302 | /**
|
303 | * @}
|
304 | */
|
305 |
|
306 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|