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