Rev 2 | Rev 4 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 3 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* USER CODE BEGIN Header */ |
1 | /* USER CODE BEGIN Header */ |
2 | /** |
2 | /** |
3 | ****************************************************************************** |
3 | ****************************************************************************** |
4 | * @file : main.c |
4 | * @file : main.c |
5 | * @brief : Main program body |
5 | * @brief : Main program body |
6 | ****************************************************************************** |
6 | ****************************************************************************** |
7 | * @attention |
7 | * @attention |
8 | * |
8 | * |
9 | * <h2><center>© Copyright (c) 2020 STMicroelectronics. |
9 | * <h2><center>© Copyright (c) 2020 STMicroelectronics. |
10 | * All rights reserved.</center></h2> |
10 | * All rights reserved.</center></h2> |
11 | * |
11 | * |
12 | * This software component is licensed by ST under BSD 3-Clause license, |
12 | * This software component is licensed by ST under BSD 3-Clause license, |
13 | * the "License"; You may not use this file except in compliance with the |
13 | * the "License"; You may not use this file except in compliance with the |
14 | * License. You may obtain a copy of the License at: |
14 | * License. You may obtain a copy of the License at: |
15 | * opensource.org/licenses/BSD-3-Clause |
15 | * opensource.org/licenses/BSD-3-Clause |
16 | * |
16 | * |
17 | ****************************************************************************** |
17 | ****************************************************************************** |
18 | */ |
18 | */ |
19 | /* USER CODE END Header */ |
19 | /* USER CODE END Header */ |
20 | 20 | ||
21 | /* Includes ------------------------------------------------------------------*/ |
21 | /* Includes ------------------------------------------------------------------*/ |
22 | #include "main.h" |
22 | #include "main.h" |
23 | 23 | ||
Line 42... | Line 42... | ||
42 | 42 | ||
43 | /* Private variables ---------------------------------------------------------*/ |
43 | /* Private variables ---------------------------------------------------------*/ |
44 | ADC_HandleTypeDef hadc; |
44 | ADC_HandleTypeDef hadc; |
45 | DMA_HandleTypeDef hdma_adc; |
45 | DMA_HandleTypeDef hdma_adc; |
46 | 46 | ||
- | 47 | SPI_HandleTypeDef hspi1; |
|
- | 48 | DMA_HandleTypeDef hdma_spi1_tx; |
|
- | 49 | ||
47 | TIM_HandleTypeDef htim1; |
50 | TIM_HandleTypeDef htim1; |
48 | TIM_HandleTypeDef htim3; |
51 | TIM_HandleTypeDef htim3; |
49 | 52 | ||
50 | UART_HandleTypeDef huart1; |
53 | UART_HandleTypeDef huart1; |
51 | 54 | ||
52 | /* USER CODE BEGIN PV */ |
55 | /* USER CODE BEGIN PV */ |
53 | #define NUM_SAMPLES 8 |
56 | #define NUM_SAMPLES 8 |
54 | uint32_t ADC_Samples [ NUM_SAMPLES ]; |
57 | uint32_t ADC_Samples[NUM_SAMPLES]; |
55 | 58 | ||
- | 59 | #define NUM_SPI_BYTES 20 |
|
- | 60 | uint8_t SPI_Buffer[NUM_SPI_BYTES]; |
|
56 | 61 | ||
57 | /* USER CODE END PV */ |
62 | /* USER CODE END PV */ |
58 | 63 | ||
59 | /* Private function prototypes -----------------------------------------------*/ |
64 | /* Private function prototypes -----------------------------------------------*/ |
60 | void SystemClock_Config(void); |
65 | void SystemClock_Config(void); |
Line 62... | Line 67... | ||
62 | static void MX_DMA_Init(void); |
67 | static void MX_DMA_Init(void); |
63 | static void MX_ADC_Init(void); |
68 | static void MX_ADC_Init(void); |
64 | static void MX_TIM1_Init(void); |
69 | static void MX_TIM1_Init(void); |
65 | static void MX_USART1_UART_Init(void); |
70 | static void MX_USART1_UART_Init(void); |
66 | static void MX_TIM3_Init(void); |
71 | static void MX_TIM3_Init(void); |
- | 72 | static void MX_SPI1_Init(void); |
|
67 | /* USER CODE BEGIN PFP */ |
73 | /* USER CODE BEGIN PFP */ |
68 | 74 | ||
69 | /* USER CODE END PFP */ |
75 | /* USER CODE END PFP */ |
70 | 76 | ||
71 | /* Private user code ---------------------------------------------------------*/ |
77 | /* Private user code ---------------------------------------------------------*/ |
72 | /* USER CODE BEGIN 0 */ |
78 | /* USER CODE BEGIN 0 */ |
73 | 79 | ||
74 | void setDrive1(uint8_t bit) { |
80 | void setDrive1(uint8_t bit) { |
75 | if (bit) { |
81 | if (bit) { |
76 | HAL_GPIO_WritePin(step1P_GPIO_Port, step1P_Pin,GPIO_PIN_SET); |
82 | HAL_GPIO_WritePin(step1P_GPIO_Port, step1P_Pin, GPIO_PIN_SET); |
77 | HAL_GPIO_WritePin(step1N_GPIO_Port, step1N_Pin,GPIO_PIN_RESET); |
83 | HAL_GPIO_WritePin(step1N_GPIO_Port, step1N_Pin, GPIO_PIN_RESET); |
78 | } else { |
84 | } else { |
79 | HAL_GPIO_WritePin(step1P_GPIO_Port, step1P_Pin,GPIO_PIN_RESET); |
85 | HAL_GPIO_WritePin(step1P_GPIO_Port, step1P_Pin, GPIO_PIN_RESET); |
80 | HAL_GPIO_WritePin(step1N_GPIO_Port,step1N_Pin,GPIO_PIN_SET); |
86 | HAL_GPIO_WritePin(step1N_GPIO_Port, step1N_Pin, GPIO_PIN_SET); |
81 | } |
87 | } |
82 | } |
88 | } |
83 | 89 | ||
84 | void setDrive2(uint8_t bit) { |
90 | void setDrive2(uint8_t bit) { |
85 | if (bit) { |
91 | if (bit) { |
86 | HAL_GPIO_WritePin(step2P_GPIO_Port, step2P_Pin,GPIO_PIN_SET); |
92 | HAL_GPIO_WritePin(step2P_GPIO_Port, step2P_Pin, GPIO_PIN_SET); |
87 | HAL_GPIO_WritePin(step2N_GPIO_Port, step2N_Pin,GPIO_PIN_RESET); |
93 | HAL_GPIO_WritePin(step2N_GPIO_Port, step2N_Pin, GPIO_PIN_RESET); |
88 | } else { |
94 | } else { |
89 | HAL_GPIO_WritePin(step2P_GPIO_Port, step2P_Pin,GPIO_PIN_RESET); |
95 | HAL_GPIO_WritePin(step2P_GPIO_Port, step2P_Pin, GPIO_PIN_RESET); |
90 | HAL_GPIO_WritePin(step2N_GPIO_Port,step2N_Pin,GPIO_PIN_SET); |
96 | HAL_GPIO_WritePin(step2N_GPIO_Port, step2N_Pin, GPIO_PIN_SET); |
91 | } |
97 | } |
92 | } |
98 | } |
93 | 99 | ||
94 | - | ||
95 | // |
100 | // |
96 | int count = 0; |
101 | int count = 0; |
97 | int origin = 0; |
102 | int origin = 0; |
98 | 103 | ||
99 | void moveGauge(int target) |
104 | void moveGauge(int target) { |
100 | { |
- | |
101 | 105 | ||
102 | unsigned const fast = 3; |
106 | unsigned const fast = 10; |
103 | unsigned const slow = 20; |
107 | unsigned const slow = 30; |
104 | unsigned const range = slow - fast; |
108 | unsigned const range = slow - fast; |
105 | unsigned del = fast; |
109 | unsigned del = fast; |
106 | int step = 1; |
110 | int step = 1; |
107 | while (count != target) { |
111 | while (count != target) { |
108 | 112 | ||
109 | // use bit mask, so it works for negative count values .. |
113 | // use bit mask, so it works for negative count values .. |
110 | switch (count & 3) { |
114 | switch (count & 3) { |
111 | case 0: |
115 | case 0: |
112 | setDrive1(1); |
116 | setDrive1(0); |
113 | setDrive2(0); |
117 | setDrive2(1); |
114 | break; |
118 | break; |
115 | case 1: |
119 | case 1: |
116 | setDrive1(1); |
120 | setDrive1(1); |
117 | setDrive2(1); |
121 | setDrive2(1); |
118 | break; |
122 | break; |
119 | case 2: |
123 | case 2: |
120 | setDrive1(0); |
124 | setDrive1(1); |
121 | setDrive2(1); |
125 | setDrive2(0); |
122 | break; |
126 | break; |
123 | case 3: |
127 | case 3: |
124 | setDrive1(0); |
128 | setDrive1(0); |
125 | setDrive2(0); |
129 | setDrive2(0); |
126 | break; |
130 | break; |
Line 158... | Line 162... | ||
158 | } |
162 | } |
159 | 163 | ||
160 | } |
164 | } |
161 | 165 | ||
162 | // move gauge back to zero position |
166 | // move gauge back to zero position |
163 | void resetGauge() |
167 | void resetGauge() { |
164 | { |
- | |
165 | moveGauge(-600); |
168 | moveGauge(-600); |
166 | count=0; |
169 | count = 0; |
167 | origin = 0; |
170 | origin = 0; |
168 | } |
171 | } |
169 | 172 | ||
170 | /* USER CODE END 0 */ |
173 | /* USER CODE END 0 */ |
171 | 174 | ||
Line 178... | Line 181... | ||
178 | /* USER CODE BEGIN 1 */ |
181 | /* USER CODE BEGIN 1 */ |
179 | // half degree step 315 degree movement |
182 | // half degree step 315 degree movement |
180 | #define GAUGE_MAX 315*2 |
183 | #define GAUGE_MAX 315*2 |
181 | #define GAUGE_MIN 0 |
184 | #define GAUGE_MIN 0 |
182 | 185 | ||
183 | - | ||
184 | /* USER CODE END 1 */ |
186 | /* USER CODE END 1 */ |
185 | - | ||
186 | 187 | ||
187 | /* MCU Configuration--------------------------------------------------------*/ |
188 | /* MCU Configuration--------------------------------------------------------*/ |
188 | 189 | ||
189 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
190 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
190 | HAL_Init(); |
191 | HAL_Init(); |
Line 205... | Line 206... | ||
205 | MX_DMA_Init(); |
206 | MX_DMA_Init(); |
206 | MX_ADC_Init(); |
207 | MX_ADC_Init(); |
207 | MX_TIM1_Init(); |
208 | MX_TIM1_Init(); |
208 | MX_USART1_UART_Init(); |
209 | MX_USART1_UART_Init(); |
209 | MX_TIM3_Init(); |
210 | MX_TIM3_Init(); |
- | 211 | MX_SPI1_Init(); |
|
210 | /* USER CODE BEGIN 2 */ |
212 | /* USER CODE BEGIN 2 */ |
211 | 213 | ||
- | 214 | int i; |
|
- | 215 | for (i = 0; i < NUM_SAMPLES; i++) |
|
- | 216 | ADC_Samples[i] = 0; |
|
212 | 217 | ||
213 | int i; |
- | |
214 | for (i=0 ; i< NUM_SAMPLES; i++) |
- | |
215 | ADC_Samples[i] =0; |
- | |
216 | - | ||
217 | HAL_ADC_MspInit(&hadc); |
218 | HAL_ADC_MspInit(&hadc); |
218 | - | ||
219 | HAL_ADC_Start_DMA(&hadc, ADC_Samples, NUM_SAMPLES); |
- | |
220 | HAL_ADC_Start_IT(&hadc); |
- | |
221 | - | ||
222 | // timer 3 triggers the ADC |
- | |
223 | HAL_TIM_Base_MspInit(&htim3); |
- | |
224 | HAL_TIM_Base_Start_IT(&htim3); |
- | |
225 | - | ||
226 | resetGauge(); |
- | |
227 | 219 | ||
- | 220 | HAL_ADC_Start_DMA(&hadc, ADC_Samples, NUM_SAMPLES); |
|
228 | 221 | ||
- | 222 | HAL_ADC_Start_IT(&hadc); |
|
229 | 223 | ||
- | 224 | // timer 3 triggers the ADC |
|
- | 225 | HAL_TIM_Base_MspInit(&htim3); |
|
- | 226 | HAL_TIM_Base_Start_IT(&htim3); |
|
230 | 227 | ||
- | 228 | resetGauge(); |
|
231 | 229 | ||
232 | /* USER CODE END 2 */ |
230 | /* USER CODE END 2 */ |
233 | - | ||
234 | - | ||
235 | 231 | ||
236 | /* Infinite loop */ |
232 | /* Infinite loop */ |
237 | /* USER CODE BEGIN WHILE */ |
233 | /* USER CODE BEGIN WHILE */ |
238 | while (1) |
234 | while (1) { |
239 | { |
235 | |
- | 236 | HAL_SPI_Transmit_DMA(&hspi1, SPI_Buffer, NUM_SPI_BYTES); |
|
- | 237 | ||
- | 238 | HAL_Delay(10); |
|
- | 239 | ||
240 | /* USER CODE END WHILE */ |
240 | /* USER CODE END WHILE */ |
241 | 241 | ||
242 | /* USER CODE BEGIN 3 */ |
242 | /* USER CODE BEGIN 3 */ |
243 | } |
243 | } |
244 | /* USER CODE END 3 */ |
244 | /* USER CODE END 3 */ |
245 | } |
245 | } |
246 | 246 | ||
247 | /** |
247 | /** |
248 | * @brief System Clock Configuration |
248 | * @brief System Clock Configuration |
Line 252... | Line 252... | ||
252 | { |
252 | { |
253 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
253 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
254 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
254 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
255 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; |
255 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; |
256 | 256 | ||
257 | /** Initializes the CPU, AHB and APB busses clocks |
257 | /** Initializes the CPU, AHB and APB busses clocks |
258 | */ |
258 | */ |
259 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14; |
259 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14; |
260 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
260 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
261 | RCC_OscInitStruct.HSI14State = RCC_HSI14_ON; |
261 | RCC_OscInitStruct.HSI14State = RCC_HSI14_ON; |
262 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; |
262 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; |
Line 267... | Line 267... | ||
267 | RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1; |
267 | RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1; |
268 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
268 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
269 | { |
269 | { |
270 | Error_Handler(); |
270 | Error_Handler(); |
271 | } |
271 | } |
272 | /** Initializes the CPU, AHB and APB busses clocks |
272 | /** Initializes the CPU, AHB and APB busses clocks |
273 | */ |
273 | */ |
274 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
274 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
275 | |RCC_CLOCKTYPE_PCLK1; |
275 | |RCC_CLOCKTYPE_PCLK1; |
276 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
276 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
277 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
277 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
Line 304... | Line 304... | ||
304 | ADC_ChannelConfTypeDef sConfig = {0}; |
304 | ADC_ChannelConfTypeDef sConfig = {0}; |
305 | 305 | ||
306 | /* USER CODE BEGIN ADC_Init 1 */ |
306 | /* USER CODE BEGIN ADC_Init 1 */ |
307 | 307 | ||
308 | /* USER CODE END ADC_Init 1 */ |
308 | /* USER CODE END ADC_Init 1 */ |
309 | /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) |
309 | /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) |
310 | */ |
310 | */ |
311 | hadc.Instance = ADC1; |
311 | hadc.Instance = ADC1; |
312 | hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; |
312 | hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; |
313 | hadc.Init.Resolution = ADC_RESOLUTION_12B; |
313 | hadc.Init.Resolution = ADC_RESOLUTION_12B; |
314 | hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT; |
314 | hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT; |
Line 324... | Line 324... | ||
324 | hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED; |
324 | hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED; |
325 | if (HAL_ADC_Init(&hadc) != HAL_OK) |
325 | if (HAL_ADC_Init(&hadc) != HAL_OK) |
326 | { |
326 | { |
327 | Error_Handler(); |
327 | Error_Handler(); |
328 | } |
328 | } |
329 | /** Configure for the selected ADC regular channel to be converted. |
329 | /** Configure for the selected ADC regular channel to be converted. |
330 | */ |
330 | */ |
331 | sConfig.Channel = ADC_CHANNEL_0; |
331 | sConfig.Channel = ADC_CHANNEL_0; |
332 | sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; |
332 | sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; |
333 | sConfig.SamplingTime = ADC_SAMPLETIME_28CYCLES_5; |
333 | sConfig.SamplingTime = ADC_SAMPLETIME_28CYCLES_5; |
334 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
334 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
Line 340... | Line 340... | ||
340 | /* USER CODE END ADC_Init 2 */ |
340 | /* USER CODE END ADC_Init 2 */ |
341 | 341 | ||
342 | } |
342 | } |
343 | 343 | ||
344 | /** |
344 | /** |
- | 345 | * @brief SPI1 Initialization Function |
|
- | 346 | * @param None |
|
- | 347 | * @retval None |
|
- | 348 | */ |
|
- | 349 | static void MX_SPI1_Init(void) |
|
- | 350 | { |
|
- | 351 | ||
- | 352 | /* USER CODE BEGIN SPI1_Init 0 */ |
|
- | 353 | ||
- | 354 | /* USER CODE END SPI1_Init 0 */ |
|
- | 355 | ||
- | 356 | /* USER CODE BEGIN SPI1_Init 1 */ |
|
- | 357 | ||
- | 358 | /* USER CODE END SPI1_Init 1 */ |
|
- | 359 | /* SPI1 parameter configuration*/ |
|
- | 360 | hspi1.Instance = SPI1; |
|
- | 361 | hspi1.Init.Mode = SPI_MODE_MASTER; |
|
- | 362 | hspi1.Init.Direction = SPI_DIRECTION_2LINES; |
|
- | 363 | hspi1.Init.DataSize = SPI_DATASIZE_8BIT; |
|
- | 364 | hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; |
|
- | 365 | hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; |
|
- | 366 | hspi1.Init.NSS = SPI_NSS_SOFT; |
|
- | 367 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; |
|
- | 368 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
|
- | 369 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
|
- | 370 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
|
- | 371 | hspi1.Init.CRCPolynomial = 7; |
|
- | 372 | hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; |
|
- | 373 | hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE; |
|
- | 374 | if (HAL_SPI_Init(&hspi1) != HAL_OK) |
|
- | 375 | { |
|
- | 376 | Error_Handler(); |
|
- | 377 | } |
|
- | 378 | /* USER CODE BEGIN SPI1_Init 2 */ |
|
- | 379 | ||
- | 380 | /* USER CODE END SPI1_Init 2 */ |
|
- | 381 | ||
- | 382 | } |
|
- | 383 | ||
- | 384 | /** |
|
345 | * @brief TIM1 Initialization Function |
385 | * @brief TIM1 Initialization Function |
346 | * @param None |
386 | * @param None |
347 | * @retval None |
387 | * @retval None |
348 | */ |
388 | */ |
349 | static void MX_TIM1_Init(void) |
389 | static void MX_TIM1_Init(void) |
Line 465... | Line 505... | ||
465 | 505 | ||
466 | /* USER CODE END USART1_Init 2 */ |
506 | /* USER CODE END USART1_Init 2 */ |
467 | 507 | ||
468 | } |
508 | } |
469 | 509 | ||
470 | /** |
510 | /** |
471 | * Enable DMA controller clock |
511 | * Enable DMA controller clock |
472 | */ |
512 | */ |
473 | static void MX_DMA_Init(void) |
513 | static void MX_DMA_Init(void) |
474 | { |
514 | { |
475 | 515 | ||
476 | /* DMA controller clock enable */ |
516 | /* DMA controller clock enable */ |
477 | __HAL_RCC_DMA1_CLK_ENABLE(); |
517 | __HAL_RCC_DMA1_CLK_ENABLE(); |
478 | 518 | ||
479 | /* DMA interrupt init */ |
519 | /* DMA interrupt init */ |
480 | /* DMA1_Channel1_IRQn interrupt configuration */ |
520 | /* DMA1_Channel1_IRQn interrupt configuration */ |
481 | HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0); |
521 | HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0); |
482 | HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn); |
522 | HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn); |
- | 523 | /* DMA1_Channel2_3_IRQn interrupt configuration */ |
|
- | 524 | HAL_NVIC_SetPriority(DMA1_Channel2_3_IRQn, 0, 0); |
|
- | 525 | HAL_NVIC_EnableIRQ(DMA1_Channel2_3_IRQn); |
|
483 | 526 | ||
484 | } |
527 | } |
485 | 528 | ||
486 | /** |
529 | /** |
487 | * @brief GPIO Initialization Function |
530 | * @brief GPIO Initialization Function |
Line 496... | Line 539... | ||
496 | __HAL_RCC_GPIOF_CLK_ENABLE(); |
539 | __HAL_RCC_GPIOF_CLK_ENABLE(); |
497 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
540 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
498 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
541 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
499 | 542 | ||
500 | /*Configure GPIO pin Output Level */ |
543 | /*Configure GPIO pin Output Level */ |
501 | HAL_GPIO_WritePin(GPIOA, enableCurrent_Pin|step2N_Pin|step2P_Pin|step1N_Pin, GPIO_PIN_RESET); |
544 | HAL_GPIO_WritePin(GPIOA, enableCurrent_Pin|step2N_Pin|step1N_Pin|step1P_Pin, GPIO_PIN_RESET); |
502 | 545 | ||
503 | /*Configure GPIO pin Output Level */ |
546 | /*Configure GPIO pin Output Level */ |
504 | HAL_GPIO_WritePin(step1P_GPIO_Port, step1P_Pin, GPIO_PIN_RESET); |
547 | HAL_GPIO_WritePin(step2P_GPIO_Port, step2P_Pin, GPIO_PIN_RESET); |
505 | 548 | ||
506 | /*Configure GPIO pins : enableCurrent_Pin step2N_Pin step2P_Pin step1N_Pin */ |
549 | /*Configure GPIO pins : enableCurrent_Pin step2N_Pin step1N_Pin step1P_Pin */ |
507 | GPIO_InitStruct.Pin = enableCurrent_Pin|step2N_Pin|step2P_Pin|step1N_Pin; |
550 | GPIO_InitStruct.Pin = enableCurrent_Pin|step2N_Pin|step1N_Pin|step1P_Pin; |
508 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
551 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
509 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
552 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
510 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
553 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
511 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
554 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
512 | 555 | ||
513 | /*Configure GPIO pin : step1P_Pin */ |
556 | /*Configure GPIO pin : step2P_Pin */ |
514 | GPIO_InitStruct.Pin = step1P_Pin; |
557 | GPIO_InitStruct.Pin = step2P_Pin; |
515 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
558 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
516 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
559 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
517 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
560 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
518 | HAL_GPIO_Init(step1P_GPIO_Port, &GPIO_InitStruct); |
561 | HAL_GPIO_Init(step2P_GPIO_Port, &GPIO_InitStruct); |
519 | 562 | ||
520 | } |
563 | } |
521 | 564 | ||
522 | /* USER CODE BEGIN 4 */ |
565 | /* USER CODE BEGIN 4 */ |
523 | 566 | ||
Line 528... | Line 571... | ||
528 | * @retval None |
571 | * @retval None |
529 | */ |
572 | */ |
530 | void Error_Handler(void) |
573 | void Error_Handler(void) |
531 | { |
574 | { |
532 | /* USER CODE BEGIN Error_Handler_Debug */ |
575 | /* USER CODE BEGIN Error_Handler_Debug */ |
533 | /* User can add his own implementation to report the HAL error return state */ |
576 | /* User can add his own implementation to report the HAL error return state */ |
534 | 577 | ||
535 | /* USER CODE END Error_Handler_Debug */ |
578 | /* USER CODE END Error_Handler_Debug */ |
536 | } |
579 | } |
537 | 580 | ||
538 | #ifdef USE_FULL_ASSERT |
581 | #ifdef USE_FULL_ASSERT |
Line 542... | Line 585... | ||
542 | * @param file: pointer to the source file name |
585 | * @param file: pointer to the source file name |
543 | * @param line: assert_param error line source number |
586 | * @param line: assert_param error line source number |
544 | * @retval None |
587 | * @retval None |
545 | */ |
588 | */ |
546 | void assert_failed(char *file, uint32_t line) |
589 | void assert_failed(char *file, uint32_t line) |
547 | { |
590 | { |
548 | /* USER CODE BEGIN 6 */ |
591 | /* USER CODE BEGIN 6 */ |
549 | /* User can add his own implementation to report the file name and line number, |
592 | /* User can add his own implementation to report the file name and line number, |
550 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
593 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
551 | /* USER CODE END 6 */ |
594 | /* USER CODE END 6 */ |
552 | } |
595 | } |