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