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