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