Rev 63 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
50 | mjames | 1 | /* USER CODE BEGIN Header */ |
2 | mjames | 2 | /** |
52 | mjames | 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 | */ |
||
50 | mjames | 19 | /* USER CODE END Header */ |
2 | mjames | 20 | /* Includes ------------------------------------------------------------------*/ |
50 | mjames | 21 | #include "main.h" |
2 | mjames | 22 | |
50 | mjames | 23 | /* Private includes ----------------------------------------------------------*/ |
2 | mjames | 24 | /* USER CODE BEGIN Includes */ |
50 | mjames | 25 | |
26 | #include "libPLX/plx.h" |
||
27 | #include "libSerial/serial.H" |
||
28 | #include "libSmallPrintf/small_printf.h" |
||
58 | mjames | 29 | #include "libNMEA/nmea.h" |
4 | mjames | 30 | #include "switches.h" |
62 | mjames | 31 | #include<string.h> |
2 | mjames | 32 | |
33 | /* USER CODE END Includes */ |
||
34 | |||
50 | mjames | 35 | /* Private typedef -----------------------------------------------------------*/ |
36 | /* USER CODE BEGIN PTD */ |
||
37 | |||
38 | /* USER CODE END PTD */ |
||
39 | |||
40 | /* Private define ------------------------------------------------------------*/ |
||
41 | /* USER CODE BEGIN PD */ |
||
42 | /* USER CODE END PD */ |
||
43 | |||
44 | /* Private macro -------------------------------------------------------------*/ |
||
45 | /* USER CODE BEGIN PM */ |
||
46 | |||
47 | /* USER CODE END PM */ |
||
48 | |||
2 | mjames | 49 | /* Private variables ---------------------------------------------------------*/ |
64 | mjames | 50 | I2C_HandleTypeDef hi2c1; |
51 | |||
62 | mjames | 52 | SPI_HandleTypeDef hspi1; |
2 | mjames | 53 | |
50 | mjames | 54 | TIM_HandleTypeDef htim2; |
44 | mjames | 55 | TIM_HandleTypeDef htim3; |
56 | TIM_HandleTypeDef htim9; |
||
57 | |||
60 | mjames | 58 | UART_HandleTypeDef huart4; |
3 | mjames | 59 | UART_HandleTypeDef huart1; |
2 | mjames | 60 | UART_HandleTypeDef huart2; |
23 | mjames | 61 | UART_HandleTypeDef huart3; |
2 | mjames | 62 | |
63 | /* USER CODE BEGIN PV */ |
||
64 | /* Private variables ---------------------------------------------------------*/ |
||
65 | |||
50 | mjames | 66 | context_t contexts[MAX_DISPLAYS]; |
67 | |||
24 | mjames | 68 | /* timeout when the ignition is switched off */ |
69 | #define IGNITION_OFF_TIMEOUT 30000UL |
||
70 | |||
62 | mjames | 71 | // 500mS per logger period. |
52 | mjames | 72 | #define LOGGER_INTERVAL 500UL |
14 | mjames | 73 | |
57 | mjames | 74 | const int DialTimeout = 10000; // about 10 seconds after twiddle, save the dial position. |
18 | mjames | 75 | |
56 | mjames | 76 | nvram_info_t dial_nvram[MAX_DISPLAYS] __attribute__((section(".NVRAM_Data"))); |
14 | mjames | 77 | |
56 | mjames | 78 | info_t Info[MAXRDG]; |
79 | |||
80 | /// \brief storage for incoming data |
||
50 | mjames | 81 | data_t Data; |
56 | mjames | 82 | |
7 | mjames | 83 | int PLXItems; |
24 | mjames | 84 | |
27 | mjames | 85 | uint32_t Latch_Timer = IGNITION_OFF_TIMEOUT; |
24 | mjames | 86 | |
58 | mjames | 87 | // location for GPS data |
88 | Location loc; |
||
89 | |||
2 | mjames | 90 | /* USER CODE END PV */ |
91 | |||
92 | /* Private function prototypes -----------------------------------------------*/ |
||
58 | mjames | 93 | void SystemClock_Config(void); |
94 | static void MX_GPIO_Init(void); |
||
95 | static void MX_SPI1_Init(void); |
||
96 | static void MX_USART1_UART_Init(void); |
||
97 | static void MX_USART2_UART_Init(void); |
||
98 | static void MX_USART3_UART_Init(void); |
||
99 | static void MX_TIM3_Init(void); |
||
100 | static void MX_TIM9_Init(void); |
||
101 | static void MX_TIM2_Init(void); |
||
60 | mjames | 102 | static void MX_UART4_Init(void); |
64 | mjames | 103 | static void MX_I2C1_Init(void); |
2 | mjames | 104 | /* USER CODE BEGIN PFP */ |
105 | |||
7 | mjames | 106 | // the dial is the switch number we are using. |
107 | // suppress is the ItemIndex we wish to suppress on this display |
||
60 | mjames | 108 | int DisplayCurrent(int dial, int suppress) |
7 | mjames | 109 | { |
57 | mjames | 110 | if (contexts[dial].knobPos < 0) |
50 | mjames | 111 | return -1; |
60 | mjames | 112 | return cc_display(dial, suppress); |
50 | mjames | 113 | } |
30 | mjames | 114 | |
56 | mjames | 115 | /// \note this code doesnt work so it leaves speed as 9600. |
116 | /// \brief Setup Bluetooth module |
||
60 | mjames | 117 | void initModule(usart_ctl *ctl, uint32_t baudRate) |
53 | mjames | 118 | { |
119 | char initBuf[30]; |
||
120 | // switch to command mode |
||
60 | mjames | 121 | HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, GPIO_PIN_RESET); |
122 | HAL_Delay(500); |
||
62 | mjames | 123 | int initLen = small_sprintf(initBuf, "AT+UART=%lu,1,2\n", baudRate); |
60 | mjames | 124 | setBaud(ctl, 38400); |
125 | sendString(ctl, initBuf, initLen); |
||
126 | TxWaitEmpty(ctl); |
||
53 | mjames | 127 | // switch back to normal comms at new baud rate |
128 | |||
60 | mjames | 129 | HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, GPIO_PIN_SET); |
130 | setBaud(ctl, baudRate); |
||
131 | HAL_Delay(100); |
||
132 | } |
||
53 | mjames | 133 | |
60 | mjames | 134 | // workspace for RMC data read from GPS module. |
135 | uint8_t rmc_buff[80]; |
||
62 | mjames | 136 | volatile uint16_t rmc_length; |
60 | mjames | 137 | |
138 | uint8_t rmc_callback(uint8_t *data, uint16_t length) |
||
139 | { |
||
62 | mjames | 140 | rmc_length = length < sizeof(rmc_buff) ? length : sizeof(rmc_buff); |
60 | mjames | 141 | memcpy(rmc_buff, data, length); |
62 | mjames | 142 | return 0; |
53 | mjames | 143 | } |
144 | |||
63 | mjames | 145 | |
146 | // check if bluetooth connected |
||
147 | uint8_t btConnected() |
||
148 | { |
||
149 | return HAL_GPIO_ReadPin(BT_STATE_GPIO_Port, BT_STATE_Pin) == GPIO_PIN_SET; |
||
150 | } |
||
151 | |||
50 | mjames | 152 | /* USER CODE END PFP */ |
14 | mjames | 153 | |
50 | mjames | 154 | /* Private user code ---------------------------------------------------------*/ |
155 | /* USER CODE BEGIN 0 */ |
||
14 | mjames | 156 | |
7 | mjames | 157 | /* USER CODE END 0 */ |
2 | mjames | 158 | |
50 | mjames | 159 | /** |
64 | mjames | 160 | * @brief The application entry point. |
161 | * @retval int |
||
162 | */ |
||
58 | mjames | 163 | int main(void) |
7 | mjames | 164 | { |
16 | mjames | 165 | /* USER CODE BEGIN 1 */ |
60 | mjames | 166 | __HAL_RCC_SPI1_CLK_ENABLE(); |
167 | __HAL_RCC_USART1_CLK_ENABLE(); // PLX main port |
||
168 | __HAL_RCC_USART2_CLK_ENABLE(); // debug port |
||
169 | __HAL_RCC_USART3_CLK_ENABLE(); // Bluetooth port |
||
61 | mjames | 170 | __HAL_RCC_UART4_CLK_ENABLE(); // NMEA0183 port |
2 | mjames | 171 | |
50 | mjames | 172 | __HAL_RCC_TIM3_CLK_ENABLE(); |
2 | mjames | 173 | |
50 | mjames | 174 | __HAL_RCC_TIM9_CLK_ENABLE(); |
23 | mjames | 175 | |
16 | mjames | 176 | /* USER CODE END 1 */ |
2 | mjames | 177 | |
50 | mjames | 178 | /* MCU Configuration--------------------------------------------------------*/ |
6 | mjames | 179 | |
16 | mjames | 180 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
58 | mjames | 181 | HAL_Init(); |
2 | mjames | 182 | |
50 | mjames | 183 | /* USER CODE BEGIN Init */ |
184 | |||
185 | /* USER CODE END Init */ |
||
186 | |||
16 | mjames | 187 | /* Configure the system clock */ |
58 | mjames | 188 | SystemClock_Config(); |
2 | mjames | 189 | |
50 | mjames | 190 | /* USER CODE BEGIN SysInit */ |
59 | mjames | 191 | // Switch handler called on sysTick interrupt. |
60 | mjames | 192 | InitSwitches(); |
50 | mjames | 193 | |
194 | /* USER CODE END SysInit */ |
||
195 | |||
16 | mjames | 196 | /* Initialize all configured peripherals */ |
58 | mjames | 197 | MX_GPIO_Init(); |
198 | MX_SPI1_Init(); |
||
199 | MX_USART1_UART_Init(); |
||
200 | MX_USART2_UART_Init(); |
||
201 | MX_USART3_UART_Init(); |
||
202 | MX_TIM3_Init(); |
||
203 | MX_TIM9_Init(); |
||
204 | MX_TIM2_Init(); |
||
60 | mjames | 205 | MX_UART4_Init(); |
64 | mjames | 206 | MX_I2C1_Init(); |
16 | mjames | 207 | /* USER CODE BEGIN 2 */ |
2 | mjames | 208 | |
50 | mjames | 209 | /* Turn on USART1 IRQ */ |
60 | mjames | 210 | HAL_NVIC_SetPriority(USART1_IRQn, 2, 0); |
211 | HAL_NVIC_EnableIRQ(USART1_IRQn); |
||
4 | mjames | 212 | |
50 | mjames | 213 | /* Turn on USART2 IRQ */ |
60 | mjames | 214 | HAL_NVIC_SetPriority(USART2_IRQn, 4, 0); |
215 | HAL_NVIC_EnableIRQ(USART2_IRQn); |
||
2 | mjames | 216 | |
50 | mjames | 217 | /* turn on USART3 IRQ */ |
60 | mjames | 218 | HAL_NVIC_SetPriority(USART3_IRQn, 4, 0); |
219 | HAL_NVIC_EnableIRQ(USART3_IRQn); |
||
4 | mjames | 220 | |
60 | mjames | 221 | /* turn on UART4 IRQ */ |
222 | HAL_NVIC_SetPriority(UART4_IRQn, 4, 0); |
||
223 | HAL_NVIC_EnableIRQ(UART4_IRQn); |
||
224 | |||
50 | mjames | 225 | /* setup the USART control blocks */ |
60 | mjames | 226 | init_usart_ctl(&uc1, &huart1); |
227 | init_usart_ctl(&uc2, &huart2); |
||
228 | init_usart_ctl(&uc3, &huart3); |
||
229 | init_usart_ctl(&uc4, &huart4); |
||
23 | mjames | 230 | |
60 | mjames | 231 | EnableSerialRxInterrupt(&uc1); |
232 | EnableSerialRxInterrupt(&uc2); |
||
233 | EnableSerialRxInterrupt(&uc3); |
||
234 | EnableSerialRxInterrupt(&uc4); |
||
23 | mjames | 235 | |
60 | mjames | 236 | HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL); |
23 | mjames | 237 | |
60 | mjames | 238 | HAL_TIM_Encoder_Start(&htim9, TIM_CHANNEL_ALL); |
44 | mjames | 239 | |
60 | mjames | 240 | initModule(&uc3, 9600); |
2 | mjames | 241 | |
58 | mjames | 242 | // Initialise UART for 4800 baud NMEA |
60 | mjames | 243 | setBaud(&uc2, 4800); |
58 | mjames | 244 | |
60 | mjames | 245 | // Initialuse UART4 for 4800 baud NMEA. |
246 | setBaud(&uc4, 4800); |
||
23 | mjames | 247 | |
60 | mjames | 248 | cc_init(); |
249 | |||
50 | mjames | 250 | int i; |
251 | for (i = 0; i < 2; i++) |
||
60 | mjames | 252 | { |
253 | dial_pos[i] = 0; // default to items 0 and 1 |
||
254 | contexts[i].knobPos = -1; |
||
255 | } |
||
7 | mjames | 256 | |
50 | mjames | 257 | /* reset the display timeout, latch on power from accessories */ |
258 | Latch_Timer = IGNITION_OFF_TIMEOUT; |
||
60 | mjames | 259 | HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, GPIO_PIN_RESET); |
16 | mjames | 260 | |
60 | mjames | 261 | setRmcCallback(&rmc_callback); |
262 | |||
16 | mjames | 263 | /* USER CODE END 2 */ |
7 | mjames | 264 | |
16 | mjames | 265 | /* Infinite loop */ |
266 | /* USER CODE BEGIN WHILE */ |
||
52 | mjames | 267 | while (1) |
60 | mjames | 268 | { |
269 | |||
270 | /* while ignition is on, keep resetting power latch timer */ |
||
271 | if (HAL_GPIO_ReadPin(IGNITION_GPIO_Port, IGNITION_Pin) == GPIO_PIN_RESET) |
||
52 | mjames | 272 | { |
60 | mjames | 273 | Latch_Timer = HAL_GetTick() + IGNITION_OFF_TIMEOUT; |
274 | } |
||
275 | else |
||
276 | { |
||
277 | /* if the ignition has been off for a while, then turn off power */ |
||
278 | if (HAL_GetTick() > Latch_Timer) |
||
279 | { |
||
280 | HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, |
||
281 | GPIO_PIN_RESET); |
||
282 | } |
||
283 | } |
||
7 | mjames | 284 | |
60 | mjames | 285 | uint32_t timeout = 0; // |
58 | mjames | 286 | |
62 | mjames | 287 | uint32_t nextTick = 0; |
60 | mjames | 288 | uint8_t log = 0; |
62 | mjames | 289 | uint8_t logCount = 1000 / LOGGER_INTERVAL; |
60 | mjames | 290 | // PLX decoder protocols |
291 | char PLXPacket = 0; |
||
292 | for (i = 0; i < MAXRDG; i++) |
||
293 | { |
||
294 | Info[i].Max = 0; |
||
295 | Info[i].Min = 0xFFF; // 12 bit max value |
||
62 | mjames | 296 | Info[i].sum = 0; // |
297 | Info[i].count=0; |
||
60 | mjames | 298 | } |
58 | mjames | 299 | |
60 | mjames | 300 | int PLXPtr = 0; |
301 | |||
302 | while (1) |
||
303 | { |
||
304 | |||
305 | // poll GPS Position/time on UART4 |
||
62 | mjames | 306 | (void)updateLocation(&loc, &uc4); |
58 | mjames | 307 | if (loc.valid == 'V') |
60 | mjames | 308 | memset(loc.time, '-', 6); |
58 | mjames | 309 | |
62 | mjames | 310 | // if permitted, log data from RMC packet |
63 | mjames | 311 | if (rmc_length && btConnected()) |
62 | mjames | 312 | { |
313 | sendString(&uc3, rmc_buff, rmc_length); |
||
314 | rmc_length = 0; |
||
315 | nextTick = HAL_GetTick() + LOGGER_INTERVAL; |
||
316 | logCount = 0; |
||
317 | log = 1; |
||
318 | } |
||
319 | |||
320 | // time several counted logger intervals after RMC recieved, enable logger each timeout. |
||
321 | if (logCount < ((1000 / LOGGER_INTERVAL)-1) && HAL_GetTick() > nextTick) |
||
322 | { |
||
323 | nextTick = HAL_GetTick() + LOGGER_INTERVAL; |
||
324 | ++logCount; |
||
325 | log = 1; |
||
326 | } |
||
327 | |||
60 | mjames | 328 | // Handle the bluetooth pairing / reset function by pressing both buttons. |
329 | if ((push_pos[0] == 1) && (push_pos[1] == 1)) |
||
330 | { |
||
331 | HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, |
||
332 | GPIO_PIN_RESET); |
||
333 | } |
||
52 | mjames | 334 | else |
60 | mjames | 335 | { |
336 | HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, |
||
337 | GPIO_PIN_SET); |
||
338 | } |
||
27 | mjames | 339 | |
60 | mjames | 340 | uint16_t cc = SerialCharsReceived(&uc1); |
341 | int chr; |
||
342 | if (cc == 0) |
||
343 | { |
||
344 | timeout++; |
||
345 | if (timeout % 1000 == 0) |
||
346 | { |
||
347 | const char msg[] = "Timeout\r\n"; |
||
348 | sendString(&uc3, msg, sizeof(msg)); |
||
349 | } |
||
27 | mjames | 350 | |
60 | mjames | 351 | if (timeout > 60000) |
352 | { |
||
27 | mjames | 353 | |
60 | mjames | 354 | // do turn off screen |
355 | } |
||
356 | } |
||
62 | mjames | 357 | |
358 | |||
60 | mjames | 359 | for (chr = 0; chr < cc; chr++) |
360 | { |
||
361 | char c = GetCharSerial(&uc1); |
||
24 | mjames | 362 | |
60 | mjames | 363 | if (c == PLX_Start) // at any time if the start byte appears, reset the pointers |
364 | { |
||
365 | PLXPtr = 0; // reset the pointer |
||
366 | PLXPacket = 1; |
||
367 | timeout = 0; // Reset the timer |
||
368 | } |
||
369 | else if (c == PLX_Stop) |
||
370 | { |
||
371 | if (PLXPacket) |
||
372 | { |
||
373 | // we can now decode the selected parameter |
||
374 | PLXItems = PLXPtr / sizeof(PLX_SensorInfo); // total |
||
375 | // saturate the rotary switch position |
||
7 | mjames | 376 | |
60 | mjames | 377 | // process min/max |
378 | for (i = 0; i < PLXItems; i++) |
||
379 | { |
||
380 | Info[i].observation = ConvPLX(Data.Sensor[i].AddrH, |
||
381 | Data.Sensor[i].AddrL); |
||
382 | Info[i].instance = Data.Sensor[i].Instance; |
||
383 | Info[i].data = ConvPLX(Data.Sensor[i].ReadingH, |
||
384 | Data.Sensor[i].ReadingL); |
||
385 | if (Info[i].data > Info[i].Max) |
||
386 | { |
||
387 | Info[i].Max = Info[i].data; |
||
388 | } |
||
389 | if (Info[i].data < Info[i].Min) |
||
390 | { |
||
391 | Info[i].Min = Info[i].data; |
||
392 | } |
||
62 | mjames | 393 | // take an avarage |
394 | Info[i].sum += Info[i].data; |
||
395 | Info[i].count ++; |
||
38 | mjames | 396 | |
62 | mjames | 397 | // Send items to BT if it is in connected state |
63 | mjames | 398 | if (log && btConnected()) |
60 | mjames | 399 | { |
38 | mjames | 400 | |
62 | mjames | 401 | char outbuff[100]; |
7 | mjames | 402 | |
62 | mjames | 403 | int cnt = small_sprintf(outbuff, |
404 | "$PLLOG,%d,%d,%d,%ld", |
||
405 | logCount, |
||
406 | Info[i].observation, |
||
407 | Info[i].instance, |
||
408 | Info[i].count==0? 0: Info[i].sum/Info[i].count); |
||
27 | mjames | 409 | |
62 | mjames | 410 | // NMEA style checksum |
411 | int ck; |
||
412 | int sum = 0; |
||
413 | for (ck = 1; ck < cnt; ck++) |
||
414 | sum += outbuff[ck]; |
||
415 | cnt += small_sprintf(outbuff + cnt, "*%02X\n", |
||
416 | sum & 0xFF); |
||
417 | sendString(&uc3, outbuff, cnt); |
||
60 | mjames | 418 | } |
419 | } |
||
62 | mjames | 420 | log = 0; |
421 | // now to display the information |
||
60 | mjames | 422 | int suppress = DisplayCurrent(0, -1); |
423 | DisplayCurrent(1, suppress); |
||
424 | } |
||
425 | PLXPtr = 0; |
||
426 | PLXPacket = 0; |
||
427 | } |
||
428 | else if (c > PLX_Stop) // illegal char, restart reading |
||
429 | { |
||
430 | PLXPacket = 0; |
||
431 | PLXPtr = 0; |
||
432 | } |
||
433 | else if (PLXPacket && PLXPtr < sizeof(Data.Bytes)) |
||
434 | { |
||
435 | Data.Bytes[PLXPtr++] = c; |
||
436 | } |
||
437 | } |
||
23 | mjames | 438 | |
60 | mjames | 439 | HAL_Delay(1); |
56 | mjames | 440 | |
60 | mjames | 441 | for (i = 0; i < MAX_DISPLAYS; i++) |
442 | { |
||
443 | if (dial_pos[i] < 0) |
||
444 | dial_pos[i] = PLXItems - 1; |
||
445 | if (dial_pos[i] >= PLXItems) |
||
446 | dial_pos[i] = 0; |
||
56 | mjames | 447 | |
60 | mjames | 448 | int prevPos = contexts[i].knobPos; |
449 | if (contexts[i].knobPos >= 0) |
||
450 | contexts[i].knobPos = dial_pos[i]; |
||
451 | // if the dial position was changed then reset timer |
||
452 | if (prevPos != contexts[i].knobPos) |
||
453 | contexts[i].dial_timer = DialTimeout; |
||
30 | mjames | 454 | |
60 | mjames | 455 | cc_check_nvram(i); |
456 | if (contexts[i].knobPos >= 0) |
||
457 | dial_pos[i] = contexts[i].knobPos; |
||
458 | } |
||
459 | } |
||
58 | mjames | 460 | /* USER CODE END WHILE */ |
52 | mjames | 461 | |
58 | mjames | 462 | /* USER CODE BEGIN 3 */ |
60 | mjames | 463 | } |
16 | mjames | 464 | /* USER CODE END 3 */ |
2 | mjames | 465 | } |
466 | |||
50 | mjames | 467 | /** |
64 | mjames | 468 | * @brief System Clock Configuration |
469 | * @retval None |
||
470 | */ |
||
58 | mjames | 471 | void SystemClock_Config(void) |
5 | mjames | 472 | { |
58 | mjames | 473 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
474 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
||
2 | mjames | 475 | |
50 | mjames | 476 | /** Configure the main internal regulator output voltage |
64 | mjames | 477 | */ |
29 | mjames | 478 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
61 | mjames | 479 | |
50 | mjames | 480 | /** Initializes the RCC Oscillators according to the specified parameters |
64 | mjames | 481 | * in the RCC_OscInitTypeDef structure. |
482 | */ |
||
44 | mjames | 483 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
59 | mjames | 484 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
16 | mjames | 485 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
44 | mjames | 486 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
487 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12; |
||
29 | mjames | 488 | RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3; |
58 | mjames | 489 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
490 | { |
||
491 | Error_Handler(); |
||
492 | } |
||
61 | mjames | 493 | |
50 | mjames | 494 | /** Initializes the CPU, AHB and APB buses clocks |
64 | mjames | 495 | */ |
496 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
||
497 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
||
16 | mjames | 498 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
499 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
||
29 | mjames | 500 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; |
16 | mjames | 501 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
50 | mjames | 502 | |
58 | mjames | 503 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) |
504 | { |
||
505 | Error_Handler(); |
||
506 | } |
||
2 | mjames | 507 | } |
508 | |||
50 | mjames | 509 | /** |
64 | mjames | 510 | * @brief I2C1 Initialization Function |
511 | * @param None |
||
512 | * @retval None |
||
513 | */ |
||
514 | static void MX_I2C1_Init(void) |
||
515 | { |
||
516 | |||
517 | /* USER CODE BEGIN I2C1_Init 0 */ |
||
518 | |||
519 | /* USER CODE END I2C1_Init 0 */ |
||
520 | |||
521 | /* USER CODE BEGIN I2C1_Init 1 */ |
||
522 | |||
523 | /* USER CODE END I2C1_Init 1 */ |
||
524 | hi2c1.Instance = I2C1; |
||
525 | hi2c1.Init.ClockSpeed = 100000; |
||
526 | hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2; |
||
527 | hi2c1.Init.OwnAddress1 = 0; |
||
528 | hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; |
||
529 | hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; |
||
530 | hi2c1.Init.OwnAddress2 = 0; |
||
531 | hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; |
||
532 | hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; |
||
533 | if (HAL_I2C_Init(&hi2c1) != HAL_OK) |
||
534 | { |
||
535 | Error_Handler(); |
||
536 | } |
||
537 | /* USER CODE BEGIN I2C1_Init 2 */ |
||
538 | |||
539 | /* USER CODE END I2C1_Init 2 */ |
||
540 | |||
541 | } |
||
542 | |||
543 | /** |
||
544 | * @brief SPI1 Initialization Function |
||
545 | * @param None |
||
546 | * @retval None |
||
547 | */ |
||
58 | mjames | 548 | static void MX_SPI1_Init(void) |
5 | mjames | 549 | { |
2 | mjames | 550 | |
50 | mjames | 551 | /* USER CODE BEGIN SPI1_Init 0 */ |
552 | |||
553 | /* USER CODE END SPI1_Init 0 */ |
||
554 | |||
555 | /* USER CODE BEGIN SPI1_Init 1 */ |
||
556 | |||
557 | /* USER CODE END SPI1_Init 1 */ |
||
558 | /* SPI1 parameter configuration*/ |
||
16 | mjames | 559 | hspi1.Instance = SPI1; |
560 | hspi1.Init.Mode = SPI_MODE_MASTER; |
||
561 | hspi1.Init.Direction = SPI_DIRECTION_1LINE; |
||
562 | hspi1.Init.DataSize = SPI_DATASIZE_8BIT; |
||
563 | hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH; |
||
564 | hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; |
||
565 | hspi1.Init.NSS = SPI_NSS_SOFT; |
||
50 | mjames | 566 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; |
16 | mjames | 567 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
568 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
||
569 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
||
570 | hspi1.Init.CRCPolynomial = 10; |
||
58 | mjames | 571 | if (HAL_SPI_Init(&hspi1) != HAL_OK) |
572 | { |
||
573 | Error_Handler(); |
||
574 | } |
||
50 | mjames | 575 | /* USER CODE BEGIN SPI1_Init 2 */ |
2 | mjames | 576 | |
50 | mjames | 577 | /* USER CODE END SPI1_Init 2 */ |
64 | mjames | 578 | |
2 | mjames | 579 | } |
580 | |||
50 | mjames | 581 | /** |
64 | mjames | 582 | * @brief TIM2 Initialization Function |
583 | * @param None |
||
584 | * @retval None |
||
585 | */ |
||
58 | mjames | 586 | static void MX_TIM2_Init(void) |
50 | mjames | 587 | { |
588 | |||
589 | /* USER CODE BEGIN TIM2_Init 0 */ |
||
590 | |||
591 | /* USER CODE END TIM2_Init 0 */ |
||
592 | |||
58 | mjames | 593 | TIM_ClockConfigTypeDef sClockSourceConfig = {0}; |
594 | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
||
50 | mjames | 595 | |
596 | /* USER CODE BEGIN TIM2_Init 1 */ |
||
597 | |||
598 | /* USER CODE END TIM2_Init 1 */ |
||
599 | htim2.Instance = TIM2; |
||
600 | htim2.Init.Prescaler = 0; |
||
601 | htim2.Init.CounterMode = TIM_COUNTERMODE_UP; |
||
602 | htim2.Init.Period = 65535; |
||
603 | htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
||
604 | htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
||
58 | mjames | 605 | if (HAL_TIM_Base_Init(&htim2) != HAL_OK) |
606 | { |
||
607 | Error_Handler(); |
||
608 | } |
||
50 | mjames | 609 | sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; |
58 | mjames | 610 | if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) |
611 | { |
||
612 | Error_Handler(); |
||
613 | } |
||
50 | mjames | 614 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; |
615 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
||
58 | mjames | 616 | if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) |
617 | { |
||
618 | Error_Handler(); |
||
619 | } |
||
50 | mjames | 620 | /* USER CODE BEGIN TIM2_Init 2 */ |
621 | |||
622 | /* USER CODE END TIM2_Init 2 */ |
||
64 | mjames | 623 | |
50 | mjames | 624 | } |
625 | |||
626 | /** |
||
64 | mjames | 627 | * @brief TIM3 Initialization Function |
628 | * @param None |
||
629 | * @retval None |
||
630 | */ |
||
58 | mjames | 631 | static void MX_TIM3_Init(void) |
44 | mjames | 632 | { |
633 | |||
50 | mjames | 634 | /* USER CODE BEGIN TIM3_Init 0 */ |
44 | mjames | 635 | |
50 | mjames | 636 | /* USER CODE END TIM3_Init 0 */ |
637 | |||
58 | mjames | 638 | TIM_Encoder_InitTypeDef sConfig = {0}; |
639 | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
||
50 | mjames | 640 | |
641 | /* USER CODE BEGIN TIM3_Init 1 */ |
||
642 | |||
643 | /* USER CODE END TIM3_Init 1 */ |
||
44 | mjames | 644 | htim3.Instance = TIM3; |
645 | htim3.Init.Prescaler = 0; |
||
646 | htim3.Init.CounterMode = TIM_COUNTERMODE_UP; |
||
50 | mjames | 647 | htim3.Init.Period = 65535; |
648 | htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
||
649 | htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
||
44 | mjames | 650 | sConfig.EncoderMode = TIM_ENCODERMODE_TI1; |
50 | mjames | 651 | sConfig.IC1Polarity = TIM_ICPOLARITY_RISING; |
44 | mjames | 652 | sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI; |
653 | sConfig.IC1Prescaler = TIM_ICPSC_DIV1; |
||
654 | sConfig.IC1Filter = 15; |
||
50 | mjames | 655 | sConfig.IC2Polarity = TIM_ICPOLARITY_RISING; |
44 | mjames | 656 | sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI; |
657 | sConfig.IC2Prescaler = TIM_ICPSC_DIV1; |
||
658 | sConfig.IC2Filter = 15; |
||
58 | mjames | 659 | if (HAL_TIM_Encoder_Init(&htim3, &sConfig) != HAL_OK) |
660 | { |
||
661 | Error_Handler(); |
||
662 | } |
||
44 | mjames | 663 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; |
664 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
||
58 | mjames | 665 | if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK) |
666 | { |
||
667 | Error_Handler(); |
||
668 | } |
||
50 | mjames | 669 | /* USER CODE BEGIN TIM3_Init 2 */ |
44 | mjames | 670 | |
50 | mjames | 671 | /* USER CODE END TIM3_Init 2 */ |
64 | mjames | 672 | |
44 | mjames | 673 | } |
674 | |||
50 | mjames | 675 | /** |
64 | mjames | 676 | * @brief TIM9 Initialization Function |
677 | * @param None |
||
678 | * @retval None |
||
679 | */ |
||
58 | mjames | 680 | static void MX_TIM9_Init(void) |
44 | mjames | 681 | { |
682 | |||
50 | mjames | 683 | /* USER CODE BEGIN TIM9_Init 0 */ |
44 | mjames | 684 | |
50 | mjames | 685 | /* USER CODE END TIM9_Init 0 */ |
686 | |||
58 | mjames | 687 | TIM_Encoder_InitTypeDef sConfig = {0}; |
688 | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
||
50 | mjames | 689 | |
690 | /* USER CODE BEGIN TIM9_Init 1 */ |
||
691 | |||
692 | /* USER CODE END TIM9_Init 1 */ |
||
44 | mjames | 693 | htim9.Instance = TIM9; |
694 | htim9.Init.Prescaler = 0; |
||
695 | htim9.Init.CounterMode = TIM_COUNTERMODE_UP; |
||
50 | mjames | 696 | htim9.Init.Period = 65535; |
697 | htim9.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
||
698 | htim9.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
||
44 | mjames | 699 | sConfig.EncoderMode = TIM_ENCODERMODE_TI1; |
50 | mjames | 700 | sConfig.IC1Polarity = TIM_ICPOLARITY_RISING; |
44 | mjames | 701 | sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI; |
702 | sConfig.IC1Prescaler = TIM_ICPSC_DIV1; |
||
703 | sConfig.IC1Filter = 15; |
||
50 | mjames | 704 | sConfig.IC2Polarity = TIM_ICPOLARITY_RISING; |
44 | mjames | 705 | sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI; |
706 | sConfig.IC2Prescaler = TIM_ICPSC_DIV1; |
||
50 | mjames | 707 | sConfig.IC2Filter = 0; |
58 | mjames | 708 | if (HAL_TIM_Encoder_Init(&htim9, &sConfig) != HAL_OK) |
709 | { |
||
710 | Error_Handler(); |
||
711 | } |
||
44 | mjames | 712 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; |
713 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
||
58 | mjames | 714 | if (HAL_TIMEx_MasterConfigSynchronization(&htim9, &sMasterConfig) != HAL_OK) |
715 | { |
||
716 | Error_Handler(); |
||
717 | } |
||
50 | mjames | 718 | /* USER CODE BEGIN TIM9_Init 2 */ |
44 | mjames | 719 | |
50 | mjames | 720 | /* USER CODE END TIM9_Init 2 */ |
64 | mjames | 721 | |
60 | mjames | 722 | } |
50 | mjames | 723 | |
60 | mjames | 724 | /** |
64 | mjames | 725 | * @brief UART4 Initialization Function |
726 | * @param None |
||
727 | * @retval None |
||
728 | */ |
||
60 | mjames | 729 | static void MX_UART4_Init(void) |
730 | { |
||
731 | |||
732 | /* USER CODE BEGIN UART4_Init 0 */ |
||
733 | |||
734 | /* USER CODE END UART4_Init 0 */ |
||
735 | |||
736 | /* USER CODE BEGIN UART4_Init 1 */ |
||
737 | |||
738 | /* USER CODE END UART4_Init 1 */ |
||
739 | huart4.Instance = UART4; |
||
740 | huart4.Init.BaudRate = 4800; |
||
741 | huart4.Init.WordLength = UART_WORDLENGTH_8B; |
||
742 | huart4.Init.StopBits = UART_STOPBITS_1; |
||
743 | huart4.Init.Parity = UART_PARITY_NONE; |
||
744 | huart4.Init.Mode = UART_MODE_TX_RX; |
||
745 | huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
||
746 | huart4.Init.OverSampling = UART_OVERSAMPLING_16; |
||
747 | if (HAL_UART_Init(&huart4) != HAL_OK) |
||
748 | { |
||
749 | Error_Handler(); |
||
750 | } |
||
751 | /* USER CODE BEGIN UART4_Init 2 */ |
||
752 | |||
753 | /* USER CODE END UART4_Init 2 */ |
||
64 | mjames | 754 | |
44 | mjames | 755 | } |
756 | |||
50 | mjames | 757 | /** |
64 | mjames | 758 | * @brief USART1 Initialization Function |
759 | * @param None |
||
760 | * @retval None |
||
761 | */ |
||
58 | mjames | 762 | static void MX_USART1_UART_Init(void) |
5 | mjames | 763 | { |
3 | mjames | 764 | |
50 | mjames | 765 | /* USER CODE BEGIN USART1_Init 0 */ |
766 | |||
767 | /* USER CODE END USART1_Init 0 */ |
||
768 | |||
769 | /* USER CODE BEGIN USART1_Init 1 */ |
||
770 | |||
771 | /* USER CODE END USART1_Init 1 */ |
||
16 | mjames | 772 | huart1.Instance = USART1; |
773 | huart1.Init.BaudRate = 19200; |
||
774 | huart1.Init.WordLength = UART_WORDLENGTH_8B; |
||
44 | mjames | 775 | huart1.Init.StopBits = UART_STOPBITS_1; |
16 | mjames | 776 | huart1.Init.Parity = UART_PARITY_NONE; |
777 | huart1.Init.Mode = UART_MODE_TX_RX; |
||
778 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
||
779 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; |
||
58 | mjames | 780 | if (HAL_UART_Init(&huart1) != HAL_OK) |
781 | { |
||
782 | Error_Handler(); |
||
783 | } |
||
50 | mjames | 784 | /* USER CODE BEGIN USART1_Init 2 */ |
3 | mjames | 785 | |
50 | mjames | 786 | /* USER CODE END USART1_Init 2 */ |
64 | mjames | 787 | |
3 | mjames | 788 | } |
789 | |||
50 | mjames | 790 | /** |
64 | mjames | 791 | * @brief USART2 Initialization Function |
792 | * @param None |
||
793 | * @retval None |
||
794 | */ |
||
58 | mjames | 795 | static void MX_USART2_UART_Init(void) |
5 | mjames | 796 | { |
2 | mjames | 797 | |
50 | mjames | 798 | /* USER CODE BEGIN USART2_Init 0 */ |
799 | |||
800 | /* USER CODE END USART2_Init 0 */ |
||
801 | |||
802 | /* USER CODE BEGIN USART2_Init 1 */ |
||
803 | |||
804 | /* USER CODE END USART2_Init 1 */ |
||
16 | mjames | 805 | huart2.Instance = USART2; |
806 | huart2.Init.BaudRate = 115200; |
||
807 | huart2.Init.WordLength = UART_WORDLENGTH_8B; |
||
808 | huart2.Init.StopBits = UART_STOPBITS_1; |
||
809 | huart2.Init.Parity = UART_PARITY_NONE; |
||
810 | huart2.Init.Mode = UART_MODE_TX_RX; |
||
811 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
||
812 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; |
||
58 | mjames | 813 | if (HAL_UART_Init(&huart2) != HAL_OK) |
814 | { |
||
815 | Error_Handler(); |
||
816 | } |
||
50 | mjames | 817 | /* USER CODE BEGIN USART2_Init 2 */ |
2 | mjames | 818 | |
50 | mjames | 819 | /* USER CODE END USART2_Init 2 */ |
64 | mjames | 820 | |
2 | mjames | 821 | } |
822 | |||
50 | mjames | 823 | /** |
64 | mjames | 824 | * @brief USART3 Initialization Function |
825 | * @param None |
||
826 | * @retval None |
||
827 | */ |
||
58 | mjames | 828 | static void MX_USART3_UART_Init(void) |
23 | mjames | 829 | { |
830 | |||
50 | mjames | 831 | /* USER CODE BEGIN USART3_Init 0 */ |
832 | |||
833 | /* USER CODE END USART3_Init 0 */ |
||
834 | |||
835 | /* USER CODE BEGIN USART3_Init 1 */ |
||
836 | |||
837 | /* USER CODE END USART3_Init 1 */ |
||
23 | mjames | 838 | huart3.Instance = USART3; |
58 | mjames | 839 | huart3.Init.BaudRate = 19200; |
23 | mjames | 840 | huart3.Init.WordLength = UART_WORDLENGTH_8B; |
50 | mjames | 841 | huart3.Init.StopBits = UART_STOPBITS_1; |
44 | mjames | 842 | huart3.Init.Parity = UART_PARITY_NONE; |
23 | mjames | 843 | huart3.Init.Mode = UART_MODE_TX_RX; |
844 | huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
||
845 | huart3.Init.OverSampling = UART_OVERSAMPLING_16; |
||
58 | mjames | 846 | if (HAL_UART_Init(&huart3) != HAL_OK) |
847 | { |
||
848 | Error_Handler(); |
||
849 | } |
||
50 | mjames | 850 | /* USER CODE BEGIN USART3_Init 2 */ |
23 | mjames | 851 | |
50 | mjames | 852 | /* USER CODE END USART3_Init 2 */ |
64 | mjames | 853 | |
23 | mjames | 854 | } |
855 | |||
50 | mjames | 856 | /** |
64 | mjames | 857 | * @brief GPIO Initialization Function |
858 | * @param None |
||
859 | * @retval None |
||
860 | */ |
||
58 | mjames | 861 | static void MX_GPIO_Init(void) |
5 | mjames | 862 | { |
58 | mjames | 863 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
2 | mjames | 864 | |
16 | mjames | 865 | /* GPIO Ports Clock Enable */ |
29 | mjames | 866 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
867 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
||
868 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
||
869 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
||
2 | mjames | 870 | |
16 | mjames | 871 | /*Configure GPIO pin Output Level */ |
58 | mjames | 872 | HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET); |
2 | mjames | 873 | |
16 | mjames | 874 | /*Configure GPIO pin Output Level */ |
64 | mjames | 875 | HAL_GPIO_WritePin(GPIOA, SPI_CD_Pin|BT_BUTTON_Pin, GPIO_PIN_RESET); |
2 | mjames | 876 | |
50 | mjames | 877 | /*Configure GPIO pin Output Level */ |
64 | mjames | 878 | HAL_GPIO_WritePin(GPIOC, SPI_RESET_Pin|POWER_LATCH_Pin|USB_PWR_Pin, GPIO_PIN_RESET); |
50 | mjames | 879 | |
880 | /*Configure GPIO pin Output Level */ |
||
58 | mjames | 881 | HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET); |
50 | mjames | 882 | |
883 | /*Configure GPIO pins : SPI_NSS1_Pin SPI_CD_Pin */ |
||
64 | mjames | 884 | GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI_CD_Pin; |
16 | mjames | 885 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
29 | mjames | 886 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
16 | mjames | 887 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
58 | mjames | 888 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
2 | mjames | 889 | |
24 | mjames | 890 | /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin POWER_LATCH_Pin USB_PWR_Pin */ |
64 | mjames | 891 | GPIO_InitStruct.Pin = SPI_RESET_Pin|SPI_NSS2_Pin|POWER_LATCH_Pin|USB_PWR_Pin; |
16 | mjames | 892 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
29 | mjames | 893 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
16 | mjames | 894 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
58 | mjames | 895 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
2 | mjames | 896 | |
61 | mjames | 897 | /*Configure GPIO pins : BT_STATE_Pin SW1_PUSH_Pin SW2_PUSH_Pin */ |
64 | mjames | 898 | GPIO_InitStruct.Pin = BT_STATE_Pin|SW1_PUSH_Pin|SW2_PUSH_Pin; |
16 | mjames | 899 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
32 | mjames | 900 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
58 | mjames | 901 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
5 | mjames | 902 | |
32 | mjames | 903 | /*Configure GPIO pin : IGNITION_Pin */ |
904 | GPIO_InitStruct.Pin = IGNITION_Pin; |
||
905 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
||
906 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
58 | mjames | 907 | HAL_GPIO_Init(IGNITION_GPIO_Port, &GPIO_InitStruct); |
32 | mjames | 908 | |
37 | mjames | 909 | /*Configure GPIO pin : BT_BUTTON_Pin */ |
910 | GPIO_InitStruct.Pin = BT_BUTTON_Pin; |
||
911 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; |
||
912 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
913 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
||
58 | mjames | 914 | HAL_GPIO_Init(BT_BUTTON_GPIO_Port, &GPIO_InitStruct); |
64 | mjames | 915 | |
2 | mjames | 916 | } |
917 | |||
918 | /* USER CODE BEGIN 4 */ |
||
919 | |||
920 | /* USER CODE END 4 */ |
||
921 | |||
5 | mjames | 922 | /** |
64 | mjames | 923 | * @brief This function is executed in case of error occurrence. |
924 | * @retval None |
||
925 | */ |
||
58 | mjames | 926 | void Error_Handler(void) |
5 | mjames | 927 | { |
50 | mjames | 928 | /* USER CODE BEGIN Error_Handler_Debug */ |
929 | /* User can add his own implementation to report the HAL error return state */ |
||
930 | |||
931 | /* USER CODE END Error_Handler_Debug */ |
||
30 | mjames | 932 | } |
5 | mjames | 933 | |
64 | mjames | 934 | #ifdef USE_FULL_ASSERT |
2 | mjames | 935 | /** |
64 | mjames | 936 | * @brief Reports the name of the source file and the source line number |
937 | * where the assert_param error has occurred. |
||
938 | * @param file: pointer to the source file name |
||
939 | * @param line: assert_param error line source number |
||
940 | * @retval None |
||
941 | */ |
||
50 | mjames | 942 | void assert_failed(uint8_t *file, uint32_t line) |
29 | mjames | 943 | { |
944 | /* USER CODE BEGIN 6 */ |
||
50 | mjames | 945 | /* User can add his own implementation to report the file name and line number, |
946 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
||
29 | mjames | 947 | /* USER CODE END 6 */ |
948 | } |
||
50 | mjames | 949 | #endif /* USE_FULL_ASSERT */ |