Rev 7 | Rev 9 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | /** |
2 | ****************************************************************************** |
||
3 | * File Name : main.c |
||
4 | * Description : Main program body |
||
5 | ****************************************************************************** |
||
6 | * |
||
7 | * COPYRIGHT(c) 2016 STMicroelectronics |
||
8 | * |
||
9 | * Redistribution and use in source and binary forms, with or without modification, |
||
10 | * are permitted provided that the following conditions are met: |
||
11 | * 1. Redistributions of source code must retain the above copyright notice, |
||
12 | * this list of conditions and the following disclaimer. |
||
13 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
||
14 | * this list of conditions and the following disclaimer in the documentation |
||
15 | * and/or other materials provided with the distribution. |
||
16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
||
17 | * may be used to endorse or promote products derived from this software |
||
18 | * without specific prior written permission. |
||
19 | * |
||
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
||
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
||
26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||
27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
||
28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
30 | * |
||
31 | ****************************************************************************** |
||
32 | */ |
||
33 | /* Includes ------------------------------------------------------------------*/ |
||
34 | #include "stm32l1xx_hal.h" |
||
35 | |||
36 | /* USER CODE BEGIN Includes */ |
||
7 | mjames | 37 | #include "serial.h" |
2 | mjames | 38 | /* USER CODE END Includes */ |
39 | |||
40 | /* Private variables ---------------------------------------------------------*/ |
||
41 | ADC_HandleTypeDef hadc; |
||
6 | mjames | 42 | DMA_HandleTypeDef hdma_adc; |
2 | mjames | 43 | |
44 | SPI_HandleTypeDef hspi1; |
||
45 | |||
46 | TIM_HandleTypeDef htim2; |
||
47 | TIM_HandleTypeDef htim6; |
||
48 | |||
49 | UART_HandleTypeDef huart1; |
||
6 | mjames | 50 | UART_HandleTypeDef huart2; |
2 | mjames | 51 | |
52 | /* USER CODE BEGIN PV */ |
||
53 | /* Private variables ---------------------------------------------------------*/ |
||
8 | mjames | 54 | char TimerFlag = 0; |
2 | mjames | 55 | |
8 | mjames | 56 | char NoSerialInCTR = 0; // Missing characters coming in on USART1 |
57 | char NoSerialIn = 0; |
||
58 | |||
59 | // storage for ADC |
||
60 | long ADC_samples[6]; |
||
61 | |||
2 | mjames | 62 | /* USER CODE END PV */ |
63 | |||
64 | /* Private function prototypes -----------------------------------------------*/ |
||
65 | void SystemClock_Config(void); |
||
66 | void Error_Handler(void); |
||
67 | static void MX_GPIO_Init(void); |
||
6 | mjames | 68 | static void MX_DMA_Init(void); |
2 | mjames | 69 | static void MX_ADC_Init(void); |
70 | static void MX_SPI1_Init(void); |
||
71 | static void MX_TIM2_Init(void); |
||
72 | static void MX_TIM6_Init(void); |
||
73 | static void MX_USART1_UART_Init(void); |
||
6 | mjames | 74 | static void MX_USART2_UART_Init(void); |
2 | mjames | 75 | |
76 | void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); |
||
77 | |||
78 | |||
79 | /* USER CODE BEGIN PFP */ |
||
80 | /* Private function prototypes -----------------------------------------------*/ |
||
81 | |||
7 | mjames | 82 | |
83 | void ConfigureDMA(void) |
||
84 | { |
||
85 | hdma_adc.Instance = DMA1_Channel1; |
||
86 | hdma_adc.Init.Direction = DMA_PERIPH_TO_MEMORY; |
||
87 | hdma_adc.Init.PeriphInc = DMA_PINC_DISABLE; |
||
88 | hdma_adc.Init.MemInc = DMA_MINC_ENABLE; |
||
89 | hdma_adc.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; |
||
90 | hdma_adc.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; |
||
91 | hdma_adc.Init.Mode = DMA_CIRCULAR; // make the DMA loop automatically |
||
92 | hdma_adc.Init.Priority = DMA_PRIORITY_LOW; |
||
93 | HAL_DMA_Init(&hdma_adc); |
||
94 | __HAL_LINKDMA(&hadc, DMA_Handle, hdma_adc); |
||
95 | |||
96 | } |
||
97 | |||
2 | mjames | 98 | /* USER CODE END PFP */ |
99 | |||
100 | /* USER CODE BEGIN 0 */ |
||
101 | |||
102 | /* USER CODE END 0 */ |
||
103 | |||
104 | int main(void) |
||
105 | { |
||
106 | |||
107 | /* USER CODE BEGIN 1 */ |
||
108 | |||
109 | /* USER CODE END 1 */ |
||
110 | |||
111 | /* MCU Configuration----------------------------------------------------------*/ |
||
112 | |||
113 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
||
114 | HAL_Init(); |
||
115 | |||
116 | /* Configure the system clock */ |
||
117 | SystemClock_Config(); |
||
118 | |||
119 | /* Initialize all configured peripherals */ |
||
120 | MX_GPIO_Init(); |
||
6 | mjames | 121 | MX_DMA_Init(); |
2 | mjames | 122 | MX_ADC_Init(); |
123 | MX_SPI1_Init(); |
||
124 | MX_TIM2_Init(); |
||
125 | MX_TIM6_Init(); |
||
126 | MX_USART1_UART_Init(); |
||
6 | mjames | 127 | MX_USART2_UART_Init(); |
2 | mjames | 128 | |
129 | /* USER CODE BEGIN 2 */ |
||
130 | |||
7 | mjames | 131 | __HAL_RCC_SPI1_CLK_ENABLE() ; // Temp sensor port |
132 | __HAL_RCC_USART1_CLK_ENABLE() ; // PLX comms port |
||
133 | __HAL_RCC_USART2_CLK_ENABLE() ; // Debug comms port |
||
134 | |||
135 | __HAL_RCC_ADC1_CLK_ENABLE(); // enable the ADC |
||
136 | |||
137 | |||
8 | mjames | 138 | __HAL_RCC_TIM6_CLK_ENABLE(); |
139 | |||
7 | mjames | 140 | ConfigureDMA(); |
141 | // HAL_ADC_Start_DMA(&g_AdcHandle, g_ADCBuffer, ADC_BUFFER_LENGTH); |
||
142 | |||
143 | /* setup the USART control blocks */ |
||
144 | init_usart_ctl(&uc1, huart1.Instance); |
||
145 | init_usart_ctl(&uc2, huart2.Instance); |
||
146 | |||
147 | EnableSerialRxInterrupt(&uc1); |
||
148 | EnableSerialRxInterrupt(&uc2); |
||
149 | |||
8 | mjames | 150 | HAL_TIM_Base_Start_IT(&htim6); |
151 | |||
7 | mjames | 152 | PutCharSerial(&uc2,'A'); |
153 | |||
2 | mjames | 154 | /* USER CODE END 2 */ |
155 | |||
156 | /* Infinite loop */ |
||
157 | /* USER CODE BEGIN WHILE */ |
||
158 | while (1) |
||
159 | { |
||
160 | /* USER CODE END WHILE */ |
||
161 | |||
162 | /* USER CODE BEGIN 3 */ |
||
163 | |||
164 | } |
||
165 | /* USER CODE END 3 */ |
||
166 | |||
167 | } |
||
168 | |||
169 | /** System Clock Configuration |
||
170 | */ |
||
171 | void SystemClock_Config(void) |
||
172 | { |
||
173 | |||
174 | RCC_OscInitTypeDef RCC_OscInitStruct; |
||
175 | RCC_ClkInitTypeDef RCC_ClkInitStruct; |
||
176 | |||
177 | __HAL_RCC_PWR_CLK_ENABLE(); |
||
178 | |||
179 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
||
180 | |||
181 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; |
||
182 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
||
183 | RCC_OscInitStruct.HSICalibrationValue = 16; |
||
184 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
||
185 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; |
||
186 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6; |
||
187 | RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3; |
||
188 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
||
189 | { |
||
190 | Error_Handler(); |
||
191 | } |
||
192 | |||
193 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
||
194 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
||
195 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
||
196 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
||
197 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; |
||
198 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
||
199 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) |
||
200 | { |
||
201 | Error_Handler(); |
||
202 | } |
||
203 | |||
204 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); |
||
205 | |||
206 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
||
207 | |||
208 | /* SysTick_IRQn interrupt configuration */ |
||
209 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
||
210 | } |
||
211 | |||
212 | /* ADC init function */ |
||
213 | static void MX_ADC_Init(void) |
||
214 | { |
||
215 | |||
216 | ADC_ChannelConfTypeDef sConfig; |
||
217 | |||
218 | /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) |
||
219 | */ |
||
220 | hadc.Instance = ADC1; |
||
221 | hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; |
||
222 | hadc.Init.Resolution = ADC_RESOLUTION_12B; |
||
223 | hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT; |
||
224 | hadc.Init.ScanConvMode = ADC_SCAN_ENABLE; |
||
225 | hadc.Init.EOCSelection = ADC_EOC_SEQ_CONV; |
||
226 | hadc.Init.LowPowerAutoWait = ADC_AUTOWAIT_DISABLE; |
||
227 | hadc.Init.LowPowerAutoPowerOff = ADC_AUTOPOWEROFF_DISABLE; |
||
228 | hadc.Init.ChannelsBank = ADC_CHANNELS_BANK_A; |
||
229 | hadc.Init.ContinuousConvMode = DISABLE; |
||
230 | hadc.Init.NbrOfConversion = 6; |
||
231 | hadc.Init.DiscontinuousConvMode = DISABLE; |
||
232 | hadc.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T6_TRGO; |
||
233 | hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING; |
||
234 | hadc.Init.DMAContinuousRequests = DISABLE; |
||
235 | if (HAL_ADC_Init(&hadc) != HAL_OK) |
||
236 | { |
||
237 | Error_Handler(); |
||
238 | } |
||
239 | |||
240 | /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
||
241 | */ |
||
6 | mjames | 242 | sConfig.Channel = ADC_CHANNEL_10; |
2 | mjames | 243 | sConfig.Rank = 1; |
244 | sConfig.SamplingTime = ADC_SAMPLETIME_4CYCLES; |
||
245 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
||
246 | { |
||
247 | Error_Handler(); |
||
248 | } |
||
249 | |||
250 | /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
||
251 | */ |
||
6 | mjames | 252 | sConfig.Channel = ADC_CHANNEL_11; |
2 | mjames | 253 | sConfig.Rank = 2; |
254 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
||
255 | { |
||
256 | Error_Handler(); |
||
257 | } |
||
258 | |||
259 | /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
||
260 | */ |
||
6 | mjames | 261 | sConfig.Channel = ADC_CHANNEL_12; |
2 | mjames | 262 | sConfig.Rank = 3; |
263 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
||
264 | { |
||
265 | Error_Handler(); |
||
266 | } |
||
267 | |||
268 | /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
||
269 | */ |
||
6 | mjames | 270 | sConfig.Channel = ADC_CHANNEL_13; |
2 | mjames | 271 | sConfig.Rank = 4; |
272 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
||
273 | { |
||
274 | Error_Handler(); |
||
275 | } |
||
276 | |||
277 | /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
||
278 | */ |
||
279 | sConfig.Channel = ADC_CHANNEL_TEMPSENSOR; |
||
280 | sConfig.Rank = 5; |
||
281 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
||
282 | { |
||
283 | Error_Handler(); |
||
284 | } |
||
285 | |||
286 | /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
||
287 | */ |
||
288 | sConfig.Channel = ADC_CHANNEL_VREFINT; |
||
289 | sConfig.Rank = 6; |
||
290 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
||
291 | { |
||
292 | Error_Handler(); |
||
293 | } |
||
294 | |||
295 | } |
||
296 | |||
297 | /* SPI1 init function */ |
||
298 | static void MX_SPI1_Init(void) |
||
299 | { |
||
300 | |||
301 | hspi1.Instance = SPI1; |
||
302 | hspi1.Init.Mode = SPI_MODE_MASTER; |
||
3 | mjames | 303 | hspi1.Init.Direction = SPI_DIRECTION_2LINES; |
2 | mjames | 304 | hspi1.Init.DataSize = SPI_DATASIZE_8BIT; |
305 | hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; |
||
306 | hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; |
||
307 | hspi1.Init.NSS = SPI_NSS_SOFT; |
||
308 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; |
||
309 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
||
310 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
||
311 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
||
312 | hspi1.Init.CRCPolynomial = 10; |
||
313 | if (HAL_SPI_Init(&hspi1) != HAL_OK) |
||
314 | { |
||
315 | Error_Handler(); |
||
316 | } |
||
317 | |||
318 | } |
||
319 | |||
320 | /* TIM2 init function */ |
||
321 | static void MX_TIM2_Init(void) |
||
322 | { |
||
323 | |||
324 | TIM_MasterConfigTypeDef sMasterConfig; |
||
325 | TIM_IC_InitTypeDef sConfigIC; |
||
326 | TIM_OC_InitTypeDef sConfigOC; |
||
327 | |||
328 | htim2.Instance = TIM2; |
||
329 | htim2.Init.Prescaler = 320; |
||
330 | htim2.Init.CounterMode = TIM_COUNTERMODE_UP; |
||
331 | htim2.Init.Period = 0; |
||
332 | htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
||
333 | if (HAL_TIM_IC_Init(&htim2) != HAL_OK) |
||
334 | { |
||
335 | Error_Handler(); |
||
336 | } |
||
337 | |||
338 | if (HAL_TIM_OC_Init(&htim2) != HAL_OK) |
||
339 | { |
||
340 | Error_Handler(); |
||
341 | } |
||
342 | |||
343 | if (HAL_TIM_PWM_Init(&htim2) != HAL_OK) |
||
344 | { |
||
345 | Error_Handler(); |
||
346 | } |
||
347 | |||
348 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; |
||
349 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
||
350 | if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) |
||
351 | { |
||
352 | Error_Handler(); |
||
353 | } |
||
354 | |||
355 | sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING; |
||
356 | sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI; |
||
357 | sConfigIC.ICPrescaler = TIM_ICPSC_DIV1; |
||
358 | sConfigIC.ICFilter = 0; |
||
359 | if (HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_1) != HAL_OK) |
||
360 | { |
||
361 | Error_Handler(); |
||
362 | } |
||
363 | |||
364 | if (HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_2) != HAL_OK) |
||
365 | { |
||
366 | Error_Handler(); |
||
367 | } |
||
368 | |||
369 | sConfigOC.OCMode = TIM_OCMODE_TIMING; |
||
370 | sConfigOC.Pulse = 0; |
||
371 | sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; |
||
372 | sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; |
||
373 | if (HAL_TIM_OC_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_3) != HAL_OK) |
||
374 | { |
||
375 | Error_Handler(); |
||
376 | } |
||
377 | |||
378 | sConfigOC.OCMode = TIM_OCMODE_PWM1; |
||
379 | if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4) != HAL_OK) |
||
380 | { |
||
381 | Error_Handler(); |
||
382 | } |
||
383 | |||
384 | HAL_TIM_MspPostInit(&htim2); |
||
385 | |||
386 | } |
||
387 | |||
388 | /* TIM6 init function */ |
||
389 | static void MX_TIM6_Init(void) |
||
390 | { |
||
391 | |||
392 | TIM_MasterConfigTypeDef sMasterConfig; |
||
393 | |||
394 | htim6.Instance = TIM6; |
||
395 | htim6.Init.Prescaler = 3200; |
||
396 | htim6.Init.CounterMode = TIM_COUNTERMODE_UP; |
||
397 | htim6.Init.Period = 1000; |
||
398 | if (HAL_TIM_Base_Init(&htim6) != HAL_OK) |
||
399 | { |
||
400 | Error_Handler(); |
||
401 | } |
||
402 | |||
403 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE; |
||
404 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
||
405 | if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK) |
||
406 | { |
||
407 | Error_Handler(); |
||
408 | } |
||
409 | |||
410 | } |
||
411 | |||
412 | /* USART1 init function */ |
||
413 | static void MX_USART1_UART_Init(void) |
||
414 | { |
||
415 | |||
416 | huart1.Instance = USART1; |
||
417 | huart1.Init.BaudRate = 19200; |
||
418 | huart1.Init.WordLength = UART_WORDLENGTH_8B; |
||
419 | huart1.Init.StopBits = UART_STOPBITS_1; |
||
420 | huart1.Init.Parity = UART_PARITY_NONE; |
||
421 | huart1.Init.Mode = UART_MODE_TX_RX; |
||
422 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
||
423 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; |
||
424 | if (HAL_UART_Init(&huart1) != HAL_OK) |
||
425 | { |
||
426 | Error_Handler(); |
||
427 | } |
||
428 | |||
429 | } |
||
430 | |||
6 | mjames | 431 | /* USART2 init function */ |
432 | static void MX_USART2_UART_Init(void) |
||
433 | { |
||
434 | |||
435 | huart2.Instance = USART2; |
||
436 | huart2.Init.BaudRate = 115200; |
||
437 | huart2.Init.WordLength = UART_WORDLENGTH_8B; |
||
438 | huart2.Init.StopBits = UART_STOPBITS_1; |
||
439 | huart2.Init.Parity = UART_PARITY_NONE; |
||
440 | huart2.Init.Mode = UART_MODE_TX_RX; |
||
441 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
||
442 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; |
||
443 | if (HAL_UART_Init(&huart2) != HAL_OK) |
||
444 | { |
||
445 | Error_Handler(); |
||
446 | } |
||
447 | |||
448 | } |
||
449 | |||
450 | /** |
||
451 | * Enable DMA controller clock |
||
452 | */ |
||
453 | static void MX_DMA_Init(void) |
||
454 | { |
||
455 | /* DMA controller clock enable */ |
||
456 | __HAL_RCC_DMA1_CLK_ENABLE(); |
||
457 | |||
458 | /* DMA interrupt init */ |
||
459 | /* DMA1_Channel1_IRQn interrupt configuration */ |
||
460 | HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0); |
||
461 | HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn); |
||
462 | |||
463 | } |
||
464 | |||
2 | mjames | 465 | /** Configure pins as |
466 | * Analog |
||
467 | * Input |
||
468 | * Output |
||
469 | * EVENT_OUT |
||
470 | * EXTI |
||
5 | mjames | 471 | * Free pins are configured automatically as Analog (this feature is enabled through |
472 | * the Code Generation settings) |
||
2 | mjames | 473 | */ |
474 | static void MX_GPIO_Init(void) |
||
475 | { |
||
476 | |||
477 | GPIO_InitTypeDef GPIO_InitStruct; |
||
478 | |||
479 | /* GPIO Ports Clock Enable */ |
||
5 | mjames | 480 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
481 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
||
2 | mjames | 482 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
483 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
||
5 | mjames | 484 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
2 | mjames | 485 | |
6 | mjames | 486 | /*Configure GPIO pins : PC13 PC14 PC15 PC6 |
5 | mjames | 487 | PC7 PC8 PC9 PC10 |
488 | PC11 PC12 */ |
||
6 | mjames | 489 | GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_6 |
5 | mjames | 490 | |GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10 |
491 | |GPIO_PIN_11|GPIO_PIN_12; |
||
492 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
||
493 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
494 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
||
2 | mjames | 495 | |
5 | mjames | 496 | /*Configure GPIO pins : PH0 PH1 */ |
497 | GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1; |
||
498 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
||
499 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
500 | HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); |
||
3 | mjames | 501 | |
6 | mjames | 502 | /*Configure GPIO pins : PA0 PA1 PA8 PA11 |
7 | mjames | 503 | PA12 */ |
6 | mjames | 504 | GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_8|GPIO_PIN_11 |
7 | mjames | 505 | |GPIO_PIN_12; |
6 | mjames | 506 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
507 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
508 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||
509 | |||
7 | mjames | 510 | /*Configure GPIO pin : LED_Blink_Pin */ |
511 | GPIO_InitStruct.Pin = LED_Blink_Pin; |
||
2 | mjames | 512 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
513 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
7 | mjames | 514 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
515 | HAL_GPIO_Init(LED_Blink_GPIO_Port, &GPIO_InitStruct); |
||
2 | mjames | 516 | |
3 | mjames | 517 | /*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin */ |
518 | GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI1CD_Pin; |
||
519 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
||
520 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
521 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
||
522 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
||
523 | |||
7 | mjames | 524 | /*Configure GPIO pins : SPI_RESET_Pin SPI_NS_Temp_Pin */ |
525 | GPIO_InitStruct.Pin = SPI_RESET_Pin|SPI_NS_Temp_Pin; |
||
3 | mjames | 526 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
527 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
528 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
||
7 | mjames | 529 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
3 | mjames | 530 | |
7 | mjames | 531 | /*Configure GPIO pins : PB2 PB12 PB13 PB14 |
532 | PB15 PB4 PB5 PB6 |
||
533 | PB7 PB8 PB9 */ |
||
534 | GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14 |
||
535 | |GPIO_PIN_15|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6 |
||
536 | |GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9; |
||
5 | mjames | 537 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
538 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
539 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
||
540 | |||
541 | /*Configure GPIO pin : PD2 */ |
||
542 | GPIO_InitStruct.Pin = GPIO_PIN_2; |
||
543 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
||
544 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
545 | HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); |
||
546 | |||
547 | /*Configure GPIO pin Output Level */ |
||
7 | mjames | 548 | HAL_GPIO_WritePin(LED_Blink_GPIO_Port, LED_Blink_Pin, GPIO_PIN_RESET); |
5 | mjames | 549 | |
550 | /*Configure GPIO pin Output Level */ |
||
7 | mjames | 551 | HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET); |
5 | mjames | 552 | |
553 | /*Configure GPIO pin Output Level */ |
||
7 | mjames | 554 | HAL_GPIO_WritePin(SPI1CD_GPIO_Port, SPI1CD_Pin, GPIO_PIN_RESET); |
555 | |||
556 | /*Configure GPIO pin Output Level */ |
||
5 | mjames | 557 | HAL_GPIO_WritePin(SPI_RESET_GPIO_Port, SPI_RESET_Pin, GPIO_PIN_RESET); |
558 | |||
7 | mjames | 559 | /*Configure GPIO pin Output Level */ |
560 | HAL_GPIO_WritePin(SPI_NS_Temp_GPIO_Port, SPI_NS_Temp_Pin, GPIO_PIN_SET); |
||
561 | |||
2 | mjames | 562 | } |
563 | |||
564 | /* USER CODE BEGIN 4 */ |
||
565 | |||
566 | /* USER CODE END 4 */ |
||
567 | |||
568 | /** |
||
569 | * @brief This function is executed in case of error occurrence. |
||
570 | * @param None |
||
571 | * @retval None |
||
572 | */ |
||
573 | void Error_Handler(void) |
||
574 | { |
||
575 | /* USER CODE BEGIN Error_Handler */ |
||
576 | /* User can add his own implementation to report the HAL error return state */ |
||
577 | while(1) |
||
578 | { |
||
579 | } |
||
580 | /* USER CODE END Error_Handler */ |
||
581 | } |
||
582 | |||
583 | #ifdef USE_FULL_ASSERT |
||
584 | |||
585 | /** |
||
586 | * @brief Reports the name of the source file and the source line number |
||
587 | * where the assert_param error has occurred. |
||
588 | * @param file: pointer to the source file name |
||
589 | * @param line: assert_param error line source number |
||
590 | * @retval None |
||
591 | */ |
||
592 | void assert_failed(uint8_t* file, uint32_t line) |
||
593 | { |
||
594 | /* USER CODE BEGIN 6 */ |
||
595 | /* User can add his own implementation to report the file name and line number, |
||
596 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
||
597 | /* USER CODE END 6 */ |
||
598 | |||
599 | } |
||
600 | |||
601 | #endif |
||
602 | |||
603 | /** |
||
604 | * @} |
||
605 | */ |
||
606 | |||
607 | /** |
||
608 | * @} |
||
609 | */ |
||
610 | |||
611 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |