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