Rev 2 | Rev 4 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | /* USER CODE BEGIN Header */ |
2 | /** |
||
3 | ****************************************************************************** |
||
4 | * File Name : stm32f0xx_hal_msp.c |
||
5 | * Description : This file provides code for the MSP Initialization |
||
6 | * and de-Initialization codes. |
||
7 | ****************************************************************************** |
||
8 | * @attention |
||
9 | * |
||
10 | * <h2><center>© Copyright (c) 2020 STMicroelectronics. |
||
11 | * All rights reserved.</center></h2> |
||
12 | * |
||
13 | * This software component is licensed by ST under BSD 3-Clause license, |
||
14 | * the "License"; You may not use this file except in compliance with the |
||
15 | * License. You may obtain a copy of the License at: |
||
16 | * opensource.org/licenses/BSD-3-Clause |
||
17 | * |
||
18 | ****************************************************************************** |
||
19 | */ |
||
20 | /* USER CODE END Header */ |
||
21 | |||
22 | /* Includes ------------------------------------------------------------------*/ |
||
23 | #include "main.h" |
||
24 | /* USER CODE BEGIN Includes */ |
||
25 | |||
26 | /* USER CODE END Includes */ |
||
27 | extern DMA_HandleTypeDef hdma_adc; |
||
28 | |||
3 | mjames | 29 | extern DMA_HandleTypeDef hdma_spi1_tx; |
30 | |||
2 | mjames | 31 | /* Private typedef -----------------------------------------------------------*/ |
32 | /* USER CODE BEGIN TD */ |
||
33 | |||
34 | /* USER CODE END TD */ |
||
35 | |||
36 | /* Private define ------------------------------------------------------------*/ |
||
37 | /* USER CODE BEGIN Define */ |
||
38 | |||
39 | /* USER CODE END Define */ |
||
40 | |||
41 | /* Private macro -------------------------------------------------------------*/ |
||
42 | /* USER CODE BEGIN Macro */ |
||
43 | |||
44 | /* USER CODE END Macro */ |
||
45 | |||
46 | /* Private variables ---------------------------------------------------------*/ |
||
47 | /* USER CODE BEGIN PV */ |
||
48 | |||
49 | /* USER CODE END PV */ |
||
50 | |||
51 | /* Private function prototypes -----------------------------------------------*/ |
||
52 | /* USER CODE BEGIN PFP */ |
||
53 | |||
54 | /* USER CODE END PFP */ |
||
55 | |||
56 | /* External functions --------------------------------------------------------*/ |
||
57 | /* USER CODE BEGIN ExternalFunctions */ |
||
58 | |||
59 | /* USER CODE END ExternalFunctions */ |
||
60 | |||
61 | /* USER CODE BEGIN 0 */ |
||
62 | |||
63 | /* USER CODE END 0 */ |
||
64 | /** |
||
65 | * Initializes the Global MSP. |
||
66 | */ |
||
67 | void HAL_MspInit(void) |
||
68 | { |
||
69 | /* USER CODE BEGIN MspInit 0 */ |
||
70 | |||
71 | /* USER CODE END MspInit 0 */ |
||
72 | |||
73 | __HAL_RCC_SYSCFG_CLK_ENABLE(); |
||
74 | __HAL_RCC_PWR_CLK_ENABLE(); |
||
75 | |||
76 | /* System interrupt init*/ |
||
77 | |||
78 | /* USER CODE BEGIN MspInit 1 */ |
||
79 | |||
80 | /* USER CODE END MspInit 1 */ |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @brief ADC MSP Initialization |
||
85 | * This function configures the hardware resources used in this example |
||
86 | * @param hadc: ADC handle pointer |
||
87 | * @retval None |
||
88 | */ |
||
89 | void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) |
||
90 | { |
||
91 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
||
92 | if(hadc->Instance==ADC1) |
||
93 | { |
||
94 | /* USER CODE BEGIN ADC1_MspInit 0 */ |
||
95 | |||
96 | /* USER CODE END ADC1_MspInit 0 */ |
||
97 | /* Peripheral clock enable */ |
||
98 | __HAL_RCC_ADC1_CLK_ENABLE(); |
||
3 | mjames | 99 | |
2 | mjames | 100 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
3 | mjames | 101 | /**ADC GPIO Configuration |
102 | PA0 ------> ADC_IN0 |
||
2 | mjames | 103 | */ |
104 | GPIO_InitStruct.Pin = GPIO_PIN_0; |
||
105 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
||
106 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
107 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||
108 | |||
109 | /* ADC1 DMA Init */ |
||
110 | /* ADC Init */ |
||
111 | hdma_adc.Instance = DMA1_Channel1; |
||
112 | hdma_adc.Init.Direction = DMA_PERIPH_TO_MEMORY; |
||
113 | hdma_adc.Init.PeriphInc = DMA_PINC_DISABLE; |
||
114 | hdma_adc.Init.MemInc = DMA_MINC_ENABLE; |
||
115 | hdma_adc.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; |
||
116 | hdma_adc.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; |
||
117 | hdma_adc.Init.Mode = DMA_CIRCULAR; |
||
118 | hdma_adc.Init.Priority = DMA_PRIORITY_LOW; |
||
119 | if (HAL_DMA_Init(&hdma_adc) != HAL_OK) |
||
120 | { |
||
121 | Error_Handler(); |
||
122 | } |
||
123 | |||
124 | __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc); |
||
125 | |||
126 | /* USER CODE BEGIN ADC1_MspInit 1 */ |
||
127 | |||
128 | /* USER CODE END ADC1_MspInit 1 */ |
||
129 | } |
||
130 | |||
131 | } |
||
132 | |||
133 | /** |
||
134 | * @brief ADC MSP De-Initialization |
||
135 | * This function freeze the hardware resources used in this example |
||
136 | * @param hadc: ADC handle pointer |
||
137 | * @retval None |
||
138 | */ |
||
139 | void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc) |
||
140 | { |
||
141 | if(hadc->Instance==ADC1) |
||
142 | { |
||
143 | /* USER CODE BEGIN ADC1_MspDeInit 0 */ |
||
144 | |||
145 | /* USER CODE END ADC1_MspDeInit 0 */ |
||
146 | /* Peripheral clock disable */ |
||
147 | __HAL_RCC_ADC1_CLK_DISABLE(); |
||
3 | mjames | 148 | |
149 | /**ADC GPIO Configuration |
||
150 | PA0 ------> ADC_IN0 |
||
2 | mjames | 151 | */ |
152 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0); |
||
153 | |||
154 | /* ADC1 DMA DeInit */ |
||
155 | HAL_DMA_DeInit(hadc->DMA_Handle); |
||
156 | /* USER CODE BEGIN ADC1_MspDeInit 1 */ |
||
157 | |||
158 | /* USER CODE END ADC1_MspDeInit 1 */ |
||
159 | } |
||
160 | |||
161 | } |
||
162 | |||
163 | /** |
||
3 | mjames | 164 | * @brief SPI MSP Initialization |
165 | * This function configures the hardware resources used in this example |
||
166 | * @param hspi: SPI handle pointer |
||
167 | * @retval None |
||
168 | */ |
||
169 | void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) |
||
170 | { |
||
171 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
||
172 | if(hspi->Instance==SPI1) |
||
173 | { |
||
174 | /* USER CODE BEGIN SPI1_MspInit 0 */ |
||
175 | |||
176 | /* USER CODE END SPI1_MspInit 0 */ |
||
177 | /* Peripheral clock enable */ |
||
178 | __HAL_RCC_SPI1_CLK_ENABLE(); |
||
179 | |||
180 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
||
181 | /**SPI1 GPIO Configuration |
||
182 | PA5 ------> SPI1_SCK |
||
183 | PA7 ------> SPI1_MOSI |
||
184 | */ |
||
185 | GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_7; |
||
186 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
||
187 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
188 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; |
||
189 | GPIO_InitStruct.Alternate = GPIO_AF0_SPI1; |
||
190 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||
191 | |||
192 | /* SPI1 DMA Init */ |
||
193 | /* SPI1_TX Init */ |
||
194 | hdma_spi1_tx.Instance = DMA1_Channel3; |
||
195 | hdma_spi1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; |
||
196 | hdma_spi1_tx.Init.PeriphInc = DMA_PINC_DISABLE; |
||
197 | hdma_spi1_tx.Init.MemInc = DMA_MINC_ENABLE; |
||
198 | hdma_spi1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; |
||
199 | hdma_spi1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; |
||
200 | hdma_spi1_tx.Init.Mode = DMA_NORMAL; |
||
201 | hdma_spi1_tx.Init.Priority = DMA_PRIORITY_LOW; |
||
202 | if (HAL_DMA_Init(&hdma_spi1_tx) != HAL_OK) |
||
203 | { |
||
204 | Error_Handler(); |
||
205 | } |
||
206 | |||
207 | __HAL_LINKDMA(hspi,hdmatx,hdma_spi1_tx); |
||
208 | |||
209 | /* USER CODE BEGIN SPI1_MspInit 1 */ |
||
210 | |||
211 | /* USER CODE END SPI1_MspInit 1 */ |
||
212 | } |
||
213 | |||
214 | } |
||
215 | |||
216 | /** |
||
217 | * @brief SPI MSP De-Initialization |
||
218 | * This function freeze the hardware resources used in this example |
||
219 | * @param hspi: SPI handle pointer |
||
220 | * @retval None |
||
221 | */ |
||
222 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) |
||
223 | { |
||
224 | if(hspi->Instance==SPI1) |
||
225 | { |
||
226 | /* USER CODE BEGIN SPI1_MspDeInit 0 */ |
||
227 | |||
228 | /* USER CODE END SPI1_MspDeInit 0 */ |
||
229 | /* Peripheral clock disable */ |
||
230 | __HAL_RCC_SPI1_CLK_DISABLE(); |
||
231 | |||
232 | /**SPI1 GPIO Configuration |
||
233 | PA5 ------> SPI1_SCK |
||
234 | PA7 ------> SPI1_MOSI |
||
235 | */ |
||
236 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_7); |
||
237 | |||
238 | /* SPI1 DMA DeInit */ |
||
239 | HAL_DMA_DeInit(hspi->hdmatx); |
||
240 | /* USER CODE BEGIN SPI1_MspDeInit 1 */ |
||
241 | |||
242 | /* USER CODE END SPI1_MspDeInit 1 */ |
||
243 | } |
||
244 | |||
245 | } |
||
246 | |||
247 | /** |
||
2 | mjames | 248 | * @brief TIM_Base MSP Initialization |
249 | * This function configures the hardware resources used in this example |
||
250 | * @param htim_base: TIM_Base handle pointer |
||
251 | * @retval None |
||
252 | */ |
||
253 | void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) |
||
254 | { |
||
255 | if(htim_base->Instance==TIM1) |
||
256 | { |
||
257 | /* USER CODE BEGIN TIM1_MspInit 0 */ |
||
258 | |||
259 | /* USER CODE END TIM1_MspInit 0 */ |
||
260 | /* Peripheral clock enable */ |
||
261 | __HAL_RCC_TIM1_CLK_ENABLE(); |
||
262 | /* USER CODE BEGIN TIM1_MspInit 1 */ |
||
263 | |||
264 | /* USER CODE END TIM1_MspInit 1 */ |
||
265 | } |
||
266 | else if(htim_base->Instance==TIM3) |
||
267 | { |
||
268 | /* USER CODE BEGIN TIM3_MspInit 0 */ |
||
269 | |||
270 | /* USER CODE END TIM3_MspInit 0 */ |
||
271 | /* Peripheral clock enable */ |
||
272 | __HAL_RCC_TIM3_CLK_ENABLE(); |
||
273 | /* USER CODE BEGIN TIM3_MspInit 1 */ |
||
274 | |||
275 | /* USER CODE END TIM3_MspInit 1 */ |
||
276 | } |
||
277 | |||
278 | } |
||
279 | |||
280 | /** |
||
281 | * @brief TIM_Base MSP De-Initialization |
||
282 | * This function freeze the hardware resources used in this example |
||
283 | * @param htim_base: TIM_Base handle pointer |
||
284 | * @retval None |
||
285 | */ |
||
286 | void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base) |
||
287 | { |
||
288 | if(htim_base->Instance==TIM1) |
||
289 | { |
||
290 | /* USER CODE BEGIN TIM1_MspDeInit 0 */ |
||
291 | |||
292 | /* USER CODE END TIM1_MspDeInit 0 */ |
||
293 | /* Peripheral clock disable */ |
||
294 | __HAL_RCC_TIM1_CLK_DISABLE(); |
||
295 | /* USER CODE BEGIN TIM1_MspDeInit 1 */ |
||
296 | |||
297 | /* USER CODE END TIM1_MspDeInit 1 */ |
||
298 | } |
||
299 | else if(htim_base->Instance==TIM3) |
||
300 | { |
||
301 | /* USER CODE BEGIN TIM3_MspDeInit 0 */ |
||
302 | |||
303 | /* USER CODE END TIM3_MspDeInit 0 */ |
||
304 | /* Peripheral clock disable */ |
||
305 | __HAL_RCC_TIM3_CLK_DISABLE(); |
||
306 | /* USER CODE BEGIN TIM3_MspDeInit 1 */ |
||
307 | |||
308 | /* USER CODE END TIM3_MspDeInit 1 */ |
||
309 | } |
||
310 | |||
311 | } |
||
312 | |||
313 | /** |
||
314 | * @brief UART MSP Initialization |
||
315 | * This function configures the hardware resources used in this example |
||
316 | * @param huart: UART handle pointer |
||
317 | * @retval None |
||
318 | */ |
||
319 | void HAL_UART_MspInit(UART_HandleTypeDef* huart) |
||
320 | { |
||
321 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
||
322 | if(huart->Instance==USART1) |
||
323 | { |
||
324 | /* USER CODE BEGIN USART1_MspInit 0 */ |
||
325 | |||
326 | /* USER CODE END USART1_MspInit 0 */ |
||
327 | /* Peripheral clock enable */ |
||
328 | __HAL_RCC_USART1_CLK_ENABLE(); |
||
3 | mjames | 329 | |
2 | mjames | 330 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
3 | mjames | 331 | /**USART1 GPIO Configuration |
2 | mjames | 332 | PA2 ------> USART1_TX |
3 | mjames | 333 | PA3 ------> USART1_RX |
2 | mjames | 334 | */ |
335 | GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3; |
||
336 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
||
337 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
338 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; |
||
339 | GPIO_InitStruct.Alternate = GPIO_AF1_USART1; |
||
340 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||
341 | |||
342 | /* USER CODE BEGIN USART1_MspInit 1 */ |
||
343 | |||
344 | /* USER CODE END USART1_MspInit 1 */ |
||
345 | } |
||
346 | |||
347 | } |
||
348 | |||
349 | /** |
||
350 | * @brief UART MSP De-Initialization |
||
351 | * This function freeze the hardware resources used in this example |
||
352 | * @param huart: UART handle pointer |
||
353 | * @retval None |
||
354 | */ |
||
355 | void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) |
||
356 | { |
||
357 | if(huart->Instance==USART1) |
||
358 | { |
||
359 | /* USER CODE BEGIN USART1_MspDeInit 0 */ |
||
360 | |||
361 | /* USER CODE END USART1_MspDeInit 0 */ |
||
362 | /* Peripheral clock disable */ |
||
363 | __HAL_RCC_USART1_CLK_DISABLE(); |
||
3 | mjames | 364 | |
365 | /**USART1 GPIO Configuration |
||
2 | mjames | 366 | PA2 ------> USART1_TX |
3 | mjames | 367 | PA3 ------> USART1_RX |
2 | mjames | 368 | */ |
369 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); |
||
370 | |||
371 | /* USER CODE BEGIN USART1_MspDeInit 1 */ |
||
372 | |||
373 | /* USER CODE END USART1_MspDeInit 1 */ |
||
374 | } |
||
375 | |||
376 | } |
||
377 | |||
378 | /* USER CODE BEGIN 1 */ |
||
379 | |||
380 | /* USER CODE END 1 */ |
||
381 | |||
382 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |