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