Rev 21 | Rev 23 | 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 : main.c |
||
5 | * @brief : Main program body |
||
6 | ****************************************************************************** |
||
7 | * @attention |
||
8 | * |
||
9 | * <h2><center>© Copyright (c) 2020 STMicroelectronics. |
||
10 | * All rights reserved.</center></h2> |
||
11 | * |
||
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 |
||
14 | * License. You may obtain a copy of the License at: |
||
15 | * opensource.org/licenses/BSD-3-Clause |
||
16 | * |
||
17 | ****************************************************************************** |
||
18 | */ |
||
19 | /* USER CODE END Header */ |
||
20 | /* Includes ------------------------------------------------------------------*/ |
||
21 | #include "main.h" |
||
13 | mjames | 22 | #include "usb_device.h" |
2 | mjames | 23 | |
24 | /* Private includes ----------------------------------------------------------*/ |
||
25 | /* USER CODE BEGIN Includes */ |
||
26 | #include "libSerial/serial.h" |
||
11 | mjames | 27 | #include "libBMP280/bmp280.h" |
6 | mjames | 28 | #include "display.h" |
2 | mjames | 29 | /* USER CODE END Includes */ |
30 | |||
31 | /* Private typedef -----------------------------------------------------------*/ |
||
32 | /* USER CODE BEGIN PTD */ |
||
33 | |||
34 | /* USER CODE END PTD */ |
||
35 | |||
36 | /* Private define ------------------------------------------------------------*/ |
||
37 | /* USER CODE BEGIN PD */ |
||
38 | /* USER CODE END PD */ |
||
39 | |||
40 | /* Private macro -------------------------------------------------------------*/ |
||
41 | /* USER CODE BEGIN PM */ |
||
42 | |||
43 | /* USER CODE END PM */ |
||
44 | |||
45 | /* Private variables ---------------------------------------------------------*/ |
||
11 | mjames | 46 | I2C_HandleTypeDef hi2c2; |
47 | |||
13 | mjames | 48 | RTC_HandleTypeDef hrtc; |
49 | |||
2 | mjames | 50 | SPI_HandleTypeDef hspi1; |
51 | |||
9 | mjames | 52 | TIM_HandleTypeDef htim3; |
2 | mjames | 53 | TIM_HandleTypeDef htim4; |
54 | |||
55 | UART_HandleTypeDef huart1; |
||
56 | |||
57 | /* USER CODE BEGIN PV */ |
||
11 | mjames | 58 | typedef struct |
59 | { |
||
60 | uint8_t dev_addr; |
||
61 | } interface_t; |
||
2 | mjames | 62 | |
11 | mjames | 63 | static int8_t |
64 | user_i2c_write (uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint32_t len) |
||
65 | { |
||
66 | HAL_StatusTypeDef st = HAL_I2C_Mem_Write(&hi2c2, i2c_addr<<1, reg_addr, 1, reg_data, len, 10000); |
||
67 | |||
68 | return st != HAL_OK ? BMP280_E_COMM_FAIL: BMP280_OK; |
||
69 | |||
70 | } |
||
71 | static int8_t |
||
72 | user_i2c_read (uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint32_t len) |
||
73 | { |
||
74 | HAL_StatusTypeDef st = HAL_I2C_Mem_Read(&hi2c2, i2c_addr<<1, reg_addr, 1, reg_data, len, 10000); |
||
75 | |||
76 | return st != HAL_OK ? BMP280_E_COMM_FAIL: BMP280_OK; |
||
77 | |||
78 | } |
||
79 | |||
80 | static void |
||
81 | user_delay_ms (uint32_t ms, void *handle) |
||
82 | { |
||
83 | HAL_Delay (ms); |
||
84 | |||
85 | } |
||
86 | |||
87 | |||
88 | |||
89 | |||
90 | struct bmp280_dev bmp = |
||
91 | { |
||
92 | |||
93 | .intf = BMP280_I2C_INTF, .read = user_i2c_read, .write = user_i2c_write, |
||
94 | .delay_ms = user_delay_ms, |
||
95 | |||
96 | /* Update interface pointer with the structure that contains both device address and file descriptor */ |
||
97 | .dev_id = BMP280_I2C_ADDR_PRIM }; |
||
98 | |||
99 | int8_t rslt; |
||
100 | struct bmp280_config conf; |
||
101 | |||
102 | |||
2 | mjames | 103 | /* USER CODE END PV */ |
104 | |||
105 | /* Private function prototypes -----------------------------------------------*/ |
||
9 | mjames | 106 | void SystemClock_Config(void); |
107 | static void MX_GPIO_Init(void); |
||
108 | static void MX_SPI1_Init(void); |
||
109 | static void MX_TIM4_Init(void); |
||
110 | static void MX_USART1_UART_Init(void); |
||
111 | static void MX_TIM3_Init(void); |
||
11 | mjames | 112 | static void MX_I2C2_Init(void); |
13 | mjames | 113 | static void MX_RTC_Init(void); |
2 | mjames | 114 | /* USER CODE BEGIN PFP */ |
115 | |||
116 | /* USER CODE END PFP */ |
||
117 | |||
118 | /* Private user code ---------------------------------------------------------*/ |
||
119 | /* USER CODE BEGIN 0 */ |
||
120 | |||
121 | /* USER CODE END 0 */ |
||
122 | |||
123 | /** |
||
9 | mjames | 124 | * @brief The application entry point. |
125 | * @retval int |
||
126 | */ |
||
127 | int main(void) |
||
2 | mjames | 128 | { |
129 | /* USER CODE BEGIN 1 */ |
||
130 | |||
131 | /* USER CODE END 1 */ |
||
132 | |||
133 | /* MCU Configuration--------------------------------------------------------*/ |
||
134 | |||
135 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
||
9 | mjames | 136 | HAL_Init(); |
2 | mjames | 137 | |
138 | /* USER CODE BEGIN Init */ |
||
139 | |||
140 | /* USER CODE END Init */ |
||
141 | |||
142 | /* Configure the system clock */ |
||
9 | mjames | 143 | SystemClock_Config(); |
2 | mjames | 144 | |
145 | /* USER CODE BEGIN SysInit */ |
||
146 | |||
147 | /* USER CODE END SysInit */ |
||
148 | |||
149 | /* Initialize all configured peripherals */ |
||
9 | mjames | 150 | MX_GPIO_Init(); |
151 | MX_SPI1_Init(); |
||
152 | MX_TIM4_Init(); |
||
153 | MX_USART1_UART_Init(); |
||
154 | MX_TIM3_Init(); |
||
11 | mjames | 155 | MX_I2C2_Init(); |
13 | mjames | 156 | MX_RTC_Init(); |
157 | MX_USB_DEVICE_Init(); |
||
2 | mjames | 158 | /* USER CODE BEGIN 2 */ |
14 | mjames | 159 | |
160 | HAL_GPIO_WritePin ( USB_PULLUP_GPIO_Port, USB_PULLUP_Pin, GPIO_PIN_RESET); |
||
161 | HAL_Delay (1000); |
||
162 | HAL_GPIO_WritePin ( USB_PULLUP_GPIO_Port, USB_PULLUP_Pin, GPIO_PIN_SET); |
||
163 | |||
22 | mjames | 164 | /* setup the USART control blocks */# |
2 | mjames | 165 | |
22 | mjames | 166 | #if defined SERIAL_UART1 |
167 | init_usart_ctl (&uc1, huart1.Instance); |
||
168 | |||
2 | mjames | 169 | EnableSerialRxInterrupt (&uc1); |
22 | mjames | 170 | #endif |
2 | mjames | 171 | |
11 | mjames | 172 | /* Initialize the bmp280 */ |
173 | rslt = bmp280_init(&bmp); |
||
174 | // print_rslt(" bmp280_init status", rslt); |
||
175 | |||
176 | /* Always read the current settings before writing, especially when |
||
177 | * all the configuration is not modified |
||
178 | */ |
||
179 | rslt = bmp280_get_config(&conf, &bmp); |
||
180 | // print_rslt(" bmp280_get_config status", rslt); |
||
181 | |||
182 | /* configuring the temperature oversampling, filter coefficient and output data rate */ |
||
183 | /* Overwrite the desired settings */ |
||
184 | conf.filter = BMP280_FILTER_COEFF_2; |
||
185 | |||
186 | /* Temperature oversampling set at 4x */ |
||
187 | conf.os_temp = BMP280_OS_4X; |
||
188 | |||
189 | /* Pressure over sampling none (disabling pressure measurement) */ |
||
190 | conf.os_pres = BMP280_OS_4X; |
||
191 | |||
12 | mjames | 192 | /* Setting the output data rate as 2HZ(500ms) */ |
193 | conf.odr = BMP280_ODR_500_MS; |
||
11 | mjames | 194 | rslt = bmp280_set_config(&conf, &bmp); |
195 | //print_rslt(" bmp280_set_config status", rslt); |
||
196 | |||
197 | /* Always set the power mode after setting the configuration */ |
||
198 | rslt = bmp280_set_power_mode(BMP280_NORMAL_MODE, &bmp); |
||
199 | //print_rslt(" bmp280_set_power_mode status", rslt); |
||
200 | |||
201 | |||
202 | |||
6 | mjames | 203 | cc_init (); |
2 | mjames | 204 | /* USER CODE END 2 */ |
205 | |||
206 | /* Infinite loop */ |
||
207 | /* USER CODE BEGIN WHILE */ |
||
208 | while (1) |
||
209 | { |
||
22 | mjames | 210 | |
211 | |||
11 | mjames | 212 | cc_run (&bmp); |
2 | mjames | 213 | |
14 | mjames | 214 | |
215 | |||
9 | mjames | 216 | HAL_Delay (50); |
5 | mjames | 217 | |
9 | mjames | 218 | /* USER CODE END WHILE */ |
5 | mjames | 219 | |
9 | mjames | 220 | /* USER CODE BEGIN 3 */ |
2 | mjames | 221 | } |
222 | /* USER CODE END 3 */ |
||
223 | } |
||
224 | |||
225 | /** |
||
9 | mjames | 226 | * @brief System Clock Configuration |
227 | * @retval None |
||
228 | */ |
||
229 | void SystemClock_Config(void) |
||
2 | mjames | 230 | { |
9 | mjames | 231 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
232 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
||
13 | mjames | 233 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; |
2 | mjames | 234 | |
235 | /** Initializes the RCC Oscillators according to the specified parameters |
||
9 | mjames | 236 | * in the RCC_OscInitTypeDef structure. |
237 | */ |
||
13 | mjames | 238 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE; |
2 | mjames | 239 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
240 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; |
||
13 | mjames | 241 | RCC_OscInitStruct.LSEState = RCC_LSE_ON; |
2 | mjames | 242 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
243 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
||
244 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
||
13 | mjames | 245 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; |
9 | mjames | 246 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
247 | { |
||
248 | Error_Handler(); |
||
249 | } |
||
2 | mjames | 250 | /** Initializes the CPU, AHB and APB buses clocks |
9 | mjames | 251 | */ |
252 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
||
253 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
||
2 | mjames | 254 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
255 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
||
256 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; |
||
257 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
||
258 | |||
9 | mjames | 259 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) |
260 | { |
||
261 | Error_Handler(); |
||
262 | } |
||
13 | mjames | 263 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_USB; |
264 | PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; |
||
265 | PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5; |
||
266 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) |
||
9 | mjames | 267 | { |
268 | Error_Handler(); |
||
269 | } |
||
2 | mjames | 270 | } |
271 | |||
272 | /** |
||
11 | mjames | 273 | * @brief I2C2 Initialization Function |
274 | * @param None |
||
275 | * @retval None |
||
276 | */ |
||
277 | static void MX_I2C2_Init(void) |
||
278 | { |
||
279 | |||
280 | /* USER CODE BEGIN I2C2_Init 0 */ |
||
281 | |||
282 | /* USER CODE END I2C2_Init 0 */ |
||
283 | |||
284 | /* USER CODE BEGIN I2C2_Init 1 */ |
||
285 | |||
286 | /* USER CODE END I2C2_Init 1 */ |
||
287 | hi2c2.Instance = I2C2; |
||
288 | hi2c2.Init.ClockSpeed = 100000; |
||
289 | hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2; |
||
290 | hi2c2.Init.OwnAddress1 = 0; |
||
291 | hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; |
||
292 | hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; |
||
293 | hi2c2.Init.OwnAddress2 = 0; |
||
294 | hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; |
||
295 | hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; |
||
296 | if (HAL_I2C_Init(&hi2c2) != HAL_OK) |
||
297 | { |
||
298 | Error_Handler(); |
||
299 | } |
||
300 | /* USER CODE BEGIN I2C2_Init 2 */ |
||
301 | |||
302 | /* USER CODE END I2C2_Init 2 */ |
||
303 | |||
304 | } |
||
305 | |||
306 | /** |
||
13 | mjames | 307 | * @brief RTC Initialization Function |
308 | * @param None |
||
309 | * @retval None |
||
310 | */ |
||
311 | static void MX_RTC_Init(void) |
||
312 | { |
||
313 | |||
314 | /* USER CODE BEGIN RTC_Init 0 */ |
||
315 | |||
316 | /* USER CODE END RTC_Init 0 */ |
||
317 | |||
318 | RTC_TimeTypeDef sTime = {0}; |
||
319 | RTC_DateTypeDef DateToUpdate = {0}; |
||
320 | |||
321 | /* USER CODE BEGIN RTC_Init 1 */ |
||
322 | |||
323 | /* USER CODE END RTC_Init 1 */ |
||
324 | /** Initialize RTC Only |
||
325 | */ |
||
326 | hrtc.Instance = RTC; |
||
327 | hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND; |
||
328 | hrtc.Init.OutPut = RTC_OUTPUTSOURCE_ALARM; |
||
329 | if (HAL_RTC_Init(&hrtc) != HAL_OK) |
||
330 | { |
||
331 | Error_Handler(); |
||
332 | } |
||
333 | |||
334 | /* USER CODE BEGIN Check_RTC_BKUP */ |
||
335 | |||
336 | /* USER CODE END Check_RTC_BKUP */ |
||
337 | |||
338 | /** Initialize RTC and set the Time and Date |
||
339 | */ |
||
340 | sTime.Hours = 0x0; |
||
341 | sTime.Minutes = 0x0; |
||
342 | sTime.Seconds = 0x0; |
||
343 | |||
344 | if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK) |
||
345 | { |
||
346 | Error_Handler(); |
||
347 | } |
||
348 | DateToUpdate.WeekDay = RTC_WEEKDAY_MONDAY; |
||
349 | DateToUpdate.Month = RTC_MONTH_JANUARY; |
||
350 | DateToUpdate.Date = 0x1; |
||
351 | DateToUpdate.Year = 0x0; |
||
352 | |||
353 | if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BCD) != HAL_OK) |
||
354 | { |
||
355 | Error_Handler(); |
||
356 | } |
||
357 | /* USER CODE BEGIN RTC_Init 2 */ |
||
358 | |||
359 | /* USER CODE END RTC_Init 2 */ |
||
360 | |||
361 | } |
||
362 | |||
363 | /** |
||
9 | mjames | 364 | * @brief SPI1 Initialization Function |
365 | * @param None |
||
366 | * @retval None |
||
367 | */ |
||
368 | static void MX_SPI1_Init(void) |
||
2 | mjames | 369 | { |
370 | |||
371 | /* USER CODE BEGIN SPI1_Init 0 */ |
||
372 | |||
373 | /* USER CODE END SPI1_Init 0 */ |
||
374 | |||
375 | /* USER CODE BEGIN SPI1_Init 1 */ |
||
376 | |||
377 | /* USER CODE END SPI1_Init 1 */ |
||
378 | /* SPI1 parameter configuration*/ |
||
379 | hspi1.Instance = SPI1; |
||
380 | hspi1.Init.Mode = SPI_MODE_MASTER; |
||
381 | hspi1.Init.Direction = SPI_DIRECTION_1LINE; |
||
382 | hspi1.Init.DataSize = SPI_DATASIZE_8BIT; |
||
5 | mjames | 383 | hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH; |
384 | hspi1.Init.CLKPhase = SPI_PHASE_2EDGE; |
||
2 | mjames | 385 | hspi1.Init.NSS = SPI_NSS_SOFT; |
386 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; |
||
387 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
||
388 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
||
389 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
||
390 | hspi1.Init.CRCPolynomial = 10; |
||
9 | mjames | 391 | if (HAL_SPI_Init(&hspi1) != HAL_OK) |
392 | { |
||
393 | Error_Handler(); |
||
394 | } |
||
2 | mjames | 395 | /* USER CODE BEGIN SPI1_Init 2 */ |
396 | |||
397 | /* USER CODE END SPI1_Init 2 */ |
||
398 | |||
399 | } |
||
400 | |||
401 | /** |
||
9 | mjames | 402 | * @brief TIM3 Initialization Function |
403 | * @param None |
||
404 | * @retval None |
||
405 | */ |
||
406 | static void MX_TIM3_Init(void) |
||
2 | mjames | 407 | { |
408 | |||
9 | mjames | 409 | /* USER CODE BEGIN TIM3_Init 0 */ |
410 | |||
411 | /* USER CODE END TIM3_Init 0 */ |
||
412 | |||
413 | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
||
414 | TIM_OC_InitTypeDef sConfigOC = {0}; |
||
415 | |||
416 | /* USER CODE BEGIN TIM3_Init 1 */ |
||
417 | |||
418 | /* USER CODE END TIM3_Init 1 */ |
||
419 | htim3.Instance = TIM3; |
||
21 | mjames | 420 | htim3.Init.Prescaler = 719; |
9 | mjames | 421 | htim3.Init.CounterMode = TIM_COUNTERMODE_UP; |
422 | htim3.Init.Period = 10000; |
||
423 | htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
||
424 | htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
||
425 | if (HAL_TIM_OC_Init(&htim3) != HAL_OK) |
||
426 | { |
||
427 | Error_Handler(); |
||
428 | } |
||
429 | if (HAL_TIM_OnePulse_Init(&htim3, TIM_OPMODE_SINGLE) != HAL_OK) |
||
430 | { |
||
431 | Error_Handler(); |
||
432 | } |
||
433 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_ENABLE; |
||
434 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
||
435 | if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK) |
||
436 | { |
||
437 | Error_Handler(); |
||
438 | } |
||
439 | sConfigOC.OCMode = TIM_OCMODE_TIMING; |
||
440 | sConfigOC.Pulse = 9999; |
||
441 | sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; |
||
442 | sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; |
||
443 | if (HAL_TIM_OC_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) |
||
444 | { |
||
445 | Error_Handler(); |
||
446 | } |
||
447 | /* USER CODE BEGIN TIM3_Init 2 */ |
||
448 | |||
449 | /* USER CODE END TIM3_Init 2 */ |
||
450 | |||
451 | } |
||
452 | |||
453 | /** |
||
454 | * @brief TIM4 Initialization Function |
||
455 | * @param None |
||
456 | * @retval None |
||
457 | */ |
||
458 | static void MX_TIM4_Init(void) |
||
459 | { |
||
460 | |||
2 | mjames | 461 | /* USER CODE BEGIN TIM4_Init 0 */ |
462 | |||
463 | /* USER CODE END TIM4_Init 0 */ |
||
464 | |||
9 | mjames | 465 | TIM_Encoder_InitTypeDef sConfig = {0}; |
466 | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
||
2 | mjames | 467 | |
468 | /* USER CODE BEGIN TIM4_Init 1 */ |
||
469 | |||
470 | /* USER CODE END TIM4_Init 1 */ |
||
471 | htim4.Instance = TIM4; |
||
472 | htim4.Init.Prescaler = 0; |
||
473 | htim4.Init.CounterMode = TIM_COUNTERMODE_UP; |
||
474 | htim4.Init.Period = 65535; |
||
475 | htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
||
476 | htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
||
477 | sConfig.EncoderMode = TIM_ENCODERMODE_TI12; |
||
478 | sConfig.IC1Polarity = TIM_ICPOLARITY_RISING; |
||
479 | sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI; |
||
480 | sConfig.IC1Prescaler = TIM_ICPSC_DIV1; |
||
21 | mjames | 481 | sConfig.IC1Filter = 15; |
2 | mjames | 482 | sConfig.IC2Polarity = TIM_ICPOLARITY_RISING; |
483 | sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI; |
||
484 | sConfig.IC2Prescaler = TIM_ICPSC_DIV1; |
||
21 | mjames | 485 | sConfig.IC2Filter = 15; |
9 | mjames | 486 | if (HAL_TIM_Encoder_Init(&htim4, &sConfig) != HAL_OK) |
487 | { |
||
488 | Error_Handler(); |
||
489 | } |
||
2 | mjames | 490 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; |
491 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
||
9 | mjames | 492 | if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK) |
493 | { |
||
494 | Error_Handler(); |
||
495 | } |
||
2 | mjames | 496 | /* USER CODE BEGIN TIM4_Init 2 */ |
497 | |||
498 | /* USER CODE END TIM4_Init 2 */ |
||
499 | |||
500 | } |
||
501 | |||
502 | /** |
||
9 | mjames | 503 | * @brief USART1 Initialization Function |
504 | * @param None |
||
505 | * @retval None |
||
506 | */ |
||
507 | static void MX_USART1_UART_Init(void) |
||
2 | mjames | 508 | { |
509 | |||
510 | /* USER CODE BEGIN USART1_Init 0 */ |
||
511 | |||
512 | /* USER CODE END USART1_Init 0 */ |
||
513 | |||
514 | /* USER CODE BEGIN USART1_Init 1 */ |
||
515 | |||
516 | /* USER CODE END USART1_Init 1 */ |
||
517 | huart1.Instance = USART1; |
||
518 | huart1.Init.BaudRate = 115200; |
||
519 | huart1.Init.WordLength = UART_WORDLENGTH_8B; |
||
520 | huart1.Init.StopBits = UART_STOPBITS_1; |
||
521 | huart1.Init.Parity = UART_PARITY_NONE; |
||
522 | huart1.Init.Mode = UART_MODE_TX_RX; |
||
523 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
||
524 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; |
||
9 | mjames | 525 | if (HAL_UART_Init(&huart1) != HAL_OK) |
526 | { |
||
527 | Error_Handler(); |
||
528 | } |
||
2 | mjames | 529 | /* USER CODE BEGIN USART1_Init 2 */ |
530 | |||
531 | /* USER CODE END USART1_Init 2 */ |
||
532 | |||
533 | } |
||
534 | |||
535 | /** |
||
9 | mjames | 536 | * @brief GPIO Initialization Function |
537 | * @param None |
||
538 | * @retval None |
||
539 | */ |
||
540 | static void MX_GPIO_Init(void) |
||
2 | mjames | 541 | { |
9 | mjames | 542 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
2 | mjames | 543 | |
544 | /* GPIO Ports Clock Enable */ |
||
5 | mjames | 545 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
2 | mjames | 546 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
547 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
||
548 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
||
549 | |||
550 | /*Configure GPIO pin Output Level */ |
||
13 | mjames | 551 | HAL_GPIO_WritePin(GPIOA, SPI_CD_Pin|SPI_RESET_Pin|SPI_NSS1_Pin, GPIO_PIN_RESET); |
2 | mjames | 552 | |
14 | mjames | 553 | /*Configure GPIO pin Output Level */ |
554 | HAL_GPIO_WritePin(USB_PULLUP_GPIO_Port, USB_PULLUP_Pin, GPIO_PIN_RESET); |
||
555 | |||
13 | mjames | 556 | /*Configure GPIO pins : SPI_CD_Pin SPI_RESET_Pin SPI_NSS1_Pin */ |
557 | GPIO_InitStruct.Pin = SPI_CD_Pin|SPI_RESET_Pin|SPI_NSS1_Pin; |
||
2 | mjames | 558 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
559 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
560 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
||
13 | mjames | 561 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
2 | mjames | 562 | |
14 | mjames | 563 | /*Configure GPIO pin : USB_PULLUP_Pin */ |
564 | GPIO_InitStruct.Pin = USB_PULLUP_Pin; |
||
565 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
||
566 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
567 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
||
568 | HAL_GPIO_Init(USB_PULLUP_GPIO_Port, &GPIO_InitStruct); |
||
569 | |||
21 | mjames | 570 | /*Configure GPIO pin : encoder_push_Pin */ |
571 | GPIO_InitStruct.Pin = encoder_push_Pin; |
||
572 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
||
573 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
||
574 | HAL_GPIO_Init(encoder_push_GPIO_Port, &GPIO_InitStruct); |
||
575 | |||
2 | mjames | 576 | } |
577 | |||
578 | /* USER CODE BEGIN 4 */ |
||
579 | |||
580 | /* USER CODE END 4 */ |
||
581 | |||
582 | /** |
||
9 | mjames | 583 | * @brief This function is executed in case of error occurrence. |
584 | * @retval None |
||
585 | */ |
||
586 | void Error_Handler(void) |
||
2 | mjames | 587 | { |
588 | /* USER CODE BEGIN Error_Handler_Debug */ |
||
589 | /* User can add his own implementation to report the HAL error return state */ |
||
590 | |||
591 | /* USER CODE END Error_Handler_Debug */ |
||
592 | } |
||
593 | |||
594 | #ifdef USE_FULL_ASSERT |
||
595 | /** |
||
596 | * @brief Reports the name of the source file and the source line number |
||
597 | * where the assert_param error has occurred. |
||
598 | * @param file: pointer to the source file name |
||
599 | * @param line: assert_param error line source number |
||
600 | * @retval None |
||
601 | */ |
||
602 | void assert_failed(uint8_t *file, uint32_t line) |
||
603 | { |
||
604 | /* USER CODE BEGIN 6 */ |
||
605 | /* User can add his own implementation to report the file name and line number, |
||
606 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
||
607 | /* USER CODE END 6 */ |
||
608 | } |
||
609 | #endif /* USE_FULL_ASSERT */ |
||
610 | |||
611 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |