Subversion Repositories EDIS_Ignition

Rev

Rev 3 | Rev 5 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/* USER CODE BEGIN Header */
2
/**
4 mjames 3
 ******************************************************************************
4
 * @file           : main.c
5
 * @brief          : Main program body
6
 ******************************************************************************
7
 * @attention
8
 *
9
 * Copyright (c) 2023 STMicroelectronics.
10
 * All rights reserved.
11
 *
12
 * This software is licensed under terms that can be found in the LICENSE file
13
 * in the root directory of this software component.
14
 * If no LICENSE file comes with this software, it is provided AS-IS.
15
 *
16
 ******************************************************************************
17
 */
2 mjames 18
/* USER CODE END Header */
19
/* Includes ------------------------------------------------------------------*/
20
#include "main.h"
21
 
22
/* Private includes ----------------------------------------------------------*/
23
/* USER CODE BEGIN Includes */
24
#include "display.h"
25
#include "bmp280driver.h"
26
#include "libMisc/fixI2C.h"
27
#include "libPlx/plx.h"
28
#include "libSerial/serial.h"
29
#include "libIgnTiming/timing.h"
30
#include "libIgnTiming/edis.h"
31
/* USER CODE END Includes */
32
 
33
/* Private typedef -----------------------------------------------------------*/
34
/* USER CODE BEGIN PTD */
35
 
36
/* USER CODE END PTD */
37
 
38
/* Private define ------------------------------------------------------------*/
39
/* USER CODE BEGIN PD */
40
/* USER CODE END PD */
41
 
42
/* Private macro -------------------------------------------------------------*/
43
/* USER CODE BEGIN PM */
3 mjames 44
 
2 mjames 45
/* USER CODE END PM */
46
 
47
/* Private variables ---------------------------------------------------------*/
4 mjames 48
CAN_HandleTypeDef hcan;
2 mjames 49
 
50
I2C_HandleTypeDef hi2c1;
51
 
52
IWDG_HandleTypeDef hiwdg;
53
 
54
SPI_HandleTypeDef hspi1;
55
 
56
TIM_HandleTypeDef htim1;
57
TIM_HandleTypeDef htim2;
58
TIM_HandleTypeDef htim3;
59
 
60
UART_HandleTypeDef huart2;
61
 
62
/* USER CODE BEGIN PV */
63
int const T100MS = 100;
64
// index for our MAP value (there is maybe another in the system)
65
char ourMAPindex = 0;
66
 
67
// compensated pressure in mb * 100
68
uint32_t comp_pres = 0;
69
// compensated temperature
70
int32_t comp_temp = -10000;
71
/* USER CODE END PV */
72
 
73
/* Private function prototypes -----------------------------------------------*/
74
void SystemClock_Config(void);
75
static void MX_GPIO_Init(void);
76
static void MX_CAN_Init(void);
77
static void MX_I2C1_Init(void);
78
static void MX_TIM1_Init(void);
79
static void MX_TIM2_Init(void);
80
static void MX_SPI1_Init(void);
81
static void MX_USART2_UART_Init(void);
82
static void MX_TIM3_Init(void);
83
static void MX_IWDG_Init(void);
84
/* USER CODE BEGIN PFP */
85
 
86
void processObservations()
87
{
88
  // send MAP
89
  PLX_SensorInfo info;
90
  ConvToPLXInstance(ourMAPindex, &info);
91
  ConvToPLXAddr(PLX_MAP, &info);
92
  ConvToPLXReading(ConveriMFDData2Raw(PLX_MAP, PRESSURE_kPa, comp_pres / 1000.0), &info);
93
  int i;
4 mjames 94
  for (i = 0; i < sizeof(PLX_SensorInfo); ++i)
2 mjames 95
    PutCharSerial(&uc2, info.bytes[i]);
96
}
97
 
3 mjames 98
void triggerSAW()
99
{
4 mjames 100
  // trigger SAW timer, timer 1
101
  __HAL_TIM_ENABLE(&htim1);
3 mjames 102
}
103
 
2 mjames 104
/* USER CODE END PFP */
105
 
106
/* Private user code ---------------------------------------------------------*/
107
/* USER CODE BEGIN 0 */
108
 
109
/* USER CODE END 0 */
110
 
111
/**
4 mjames 112
 * @brief  The application entry point.
113
 * @retval int
114
 */
2 mjames 115
int main(void)
116
{
117
  /* USER CODE BEGIN 1 */
118
 
119
  /* USER CODE END 1 */
120
 
121
  /* MCU Configuration--------------------------------------------------------*/
122
 
123
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
124
  HAL_Init();
125
 
126
  /* USER CODE BEGIN Init */
127
 
128
  /* USER CODE END Init */
129
 
130
  /* Configure the system clock */
131
  SystemClock_Config();
132
 
133
  /* USER CODE BEGIN SysInit */
134
 
135
  /* USER CODE END SysInit */
136
 
137
  /* Initialize all configured peripherals */
138
  MX_GPIO_Init();
139
  MX_CAN_Init();
140
  MX_I2C1_Init();
141
  MX_TIM1_Init();
142
  MX_TIM2_Init();
143
  MX_SPI1_Init();
144
  MX_USART2_UART_Init();
145
  MX_TIM3_Init();
146
  MX_IWDG_Init();
147
  /* USER CODE BEGIN 2 */
148
  cc_init();
149
 
4 mjames 150
  HAL_TIM_Base_Start(&htim1);
151
 
152
  __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 5); // delay of 5 uS
153
 
2 mjames 154
  HAL_I2C_ClearBusyFlagErrata_2_14_7(&hi2c1);
155
  MX_I2C1_Init();
156
  init_bmp(&hi2c1);
157
  uint32_t lastTick = HAL_GetTick();
158
 
159
  uint32_t displayOff = lastTick + 10000;
160
  uint8_t intensity = 2;
4 mjames 161
  uint32_t timeout = 0;
2 mjames 162
  uint8_t send = 0; // enable sending our PLX data when non zero
163
  ResetRxBuffer(&uc2);
164
 
165
  // used to store data
166
  PLX_SensorInfo info;
167
  int infoCount = -1;
168
 
169
  HAL_IWDG_Init(&hiwdg);
170
  /* USER CODE END 2 */
171
 
172
  /* Infinite loop */
173
  /* USER CODE BEGIN WHILE */
174
  while (1)
175
  {
176
    int button = HAL_GPIO_ReadPin(PUSHBUTTON_GPIO_Port, PUSHBUTTON_Pin) == GPIO_PIN_RESET;
177
 
178
    if (button)
179
    {
180
      intensity = 2;
181
      displayOff = lastTick + 10000;
182
    }
183
 
184
    switch (intensity)
185
    {
186
    case 2:
187
      if (HAL_GetTick() > displayOff)
188
      {
189
        intensity = 1;
190
        displayOff = lastTick + 60000;
191
      }
192
 
193
      break;
194
    case 1:
195
      if (HAL_GetTick() > displayOff)
196
      {
197
        intensity = 0;
198
      }
199
    default:
200
      break;
201
    }
202
    cc_display(0, intensity);
203
 
204
    if (HAL_GetTick() - lastTick > 200)
205
    {
206
      lastTick = HAL_GetTick();
207
      /* Reading the raw data from sensor */
208
      struct bmp280_uncomp_data ucomp_data;
209
      uint8_t rslt = bmp280_get_uncomp_data(&ucomp_data, &bmp);
210
 
211
      uint32_t comp_pres = 0;
212
      int32_t comp_temp = -10000;
213
      if (rslt == 0)
214
      {
215
        uint8_t rslt2 = bmp280_get_comp_pres_32bit(&comp_pres, ucomp_data.uncomp_press, &bmp);
216
 
217
        uint8_t rslt3 = bmp280_get_comp_temp_32bit(&comp_temp, ucomp_data.uncomp_temp, &bmp);
4 mjames 218
        if (rslt2 == 0 && rslt3 == 0)
219
          cc_feed_env(comp_pres, comp_temp);
2 mjames 220
      }
221
    }
222
 
223
    // compute RPM value, feed to display
224
 
4 mjames 225
    int rpm = CalculateRPM();
226
    if (rpm > 0)
227
    {
228
      cc_feed_rpm(rpm);
229
      // compute timing value, feed to display
230
      int timing = mapTiming(rpm, 1000 - comp_pres / 100);
231
      cc_feed_timing(timing);
232
      int microsecs = mapTimingToMicroseconds(timing, 0);
233
      __HAL_TIM_SET_AUTORELOAD(&htim1, microsecs + SAW_DELAY);
234
    }
2 mjames 235
    // Handle PLX
236
    // poll the  input for a stop bit or timeout
237
    if (PollSerial(&uc2))
238
    {
239
      timeout = HAL_GetTick() + T100MS * 2;
240
      char c = GetCharSerial(&uc2);
241
      if (c != PLX_Stop)
242
      {
243
        PutCharSerial(&uc2, c); // echo all but the stop bit
244
      }
245
      else
246
      {           // must be a stop character
247
        send = 1; // start our sending process.
248
      }
249
      // look up the i
250
      if (c == PLX_Start)
251
      {
252
        ourMAPindex = 0;
253
        infoCount = 0;
254
      }
255
      else
256
      {
257
        info.bytes[infoCount++] = c;
258
        // process the sensor info field
259
        if (infoCount == sizeof(PLX_SensorInfo))
260
        {
261
          infoCount = 0;
262
          int addr = ConvPLXAddr(&info);
263
          if (addr == PLX_MAP)
264
            ourMAPindex = info.Instance + 1;
265
        }
266
      }
267
 
268
      if (c == PLX_Stop)
269
        infoCount = -1;
270
    }
271
 
272
    // sort out auto-sending
273
    if (HAL_GetTick() > timeout)
274
    {
275
      timeout = HAL_GetTick() + T100MS;
276
      send = 1;
277
    }
278
 
279
    if (send)
280
    {
281
      send = 0;
282
 
283
      // send the observations
284
      processObservations();
285
      //
286
      PutCharSerial(&uc2, PLX_Stop);
287
    }
288
 
289
    /* USER CODE END WHILE */
290
 
291
    /* USER CODE BEGIN 3 */
292
    HAL_IWDG_Refresh(&hiwdg);
293
  }
294
  /* USER CODE END 3 */
295
}
296
 
297
/**
4 mjames 298
 * @brief System Clock Configuration
299
 * @retval None
300
 */
2 mjames 301
void SystemClock_Config(void)
302
{
303
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
304
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
305
 
306
  /** Initializes the RCC Oscillators according to the specified parameters
4 mjames 307
   * in the RCC_OscInitTypeDef structure.
308
   */
309
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_HSE;
2 mjames 310
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
311
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
312
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
313
  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
314
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
315
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
316
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
317
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
318
  {
319
    Error_Handler();
320
  }
321
 
322
  /** Initializes the CPU, AHB and APB buses clocks
4 mjames 323
   */
324
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
2 mjames 325
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
326
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
327
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
328
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
329
 
330
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
331
  {
332
    Error_Handler();
333
  }
334
}
335
 
336
/**
4 mjames 337
 * @brief CAN Initialization Function
338
 * @param None
339
 * @retval None
340
 */
2 mjames 341
static void MX_CAN_Init(void)
342
{
343
 
344
  /* USER CODE BEGIN CAN_Init 0 */
345
 
346
  /* USER CODE END CAN_Init 0 */
347
 
348
  /* USER CODE BEGIN CAN_Init 1 */
349
 
350
  /* USER CODE END CAN_Init 1 */
351
  hcan.Instance = CAN1;
352
  hcan.Init.Prescaler = 18;
353
  hcan.Init.Mode = CAN_MODE_NORMAL;
354
  hcan.Init.SyncJumpWidth = CAN_SJW_1TQ;
355
  hcan.Init.TimeSeg1 = CAN_BS1_3TQ;
356
  hcan.Init.TimeSeg2 = CAN_BS2_4TQ;
357
  hcan.Init.TimeTriggeredMode = DISABLE;
358
  hcan.Init.AutoBusOff = DISABLE;
359
  hcan.Init.AutoWakeUp = DISABLE;
360
  hcan.Init.AutoRetransmission = DISABLE;
361
  hcan.Init.ReceiveFifoLocked = DISABLE;
362
  hcan.Init.TransmitFifoPriority = DISABLE;
363
  if (HAL_CAN_Init(&hcan) != HAL_OK)
364
  {
365
    Error_Handler();
366
  }
367
  /* USER CODE BEGIN CAN_Init 2 */
368
 
369
  /* USER CODE END CAN_Init 2 */
370
}
371
 
372
/**
4 mjames 373
 * @brief I2C1 Initialization Function
374
 * @param None
375
 * @retval None
376
 */
2 mjames 377
static void MX_I2C1_Init(void)
378
{
379
 
380
  /* USER CODE BEGIN I2C1_Init 0 */
381
 
382
  /* USER CODE END I2C1_Init 0 */
383
 
384
  /* USER CODE BEGIN I2C1_Init 1 */
385
 
386
  /* USER CODE END I2C1_Init 1 */
387
  hi2c1.Instance = I2C1;
388
  hi2c1.Init.ClockSpeed = 100000;
389
  hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
390
  hi2c1.Init.OwnAddress1 = 0;
391
  hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
392
  hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
393
  hi2c1.Init.OwnAddress2 = 0;
394
  hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
395
  hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
396
  if (HAL_I2C_Init(&hi2c1) != HAL_OK)
397
  {
398
    Error_Handler();
399
  }
400
  /* USER CODE BEGIN I2C1_Init 2 */
401
 
402
  /* USER CODE END I2C1_Init 2 */
403
}
404
 
405
/**
4 mjames 406
 * @brief IWDG Initialization Function
407
 * @param None
408
 * @retval None
409
 */
2 mjames 410
static void MX_IWDG_Init(void)
411
{
412
 
413
  /* USER CODE BEGIN IWDG_Init 0 */
414
 
415
  /* USER CODE END IWDG_Init 0 */
416
 
417
  /* USER CODE BEGIN IWDG_Init 1 */
418
 
419
  /* USER CODE END IWDG_Init 1 */
420
  hiwdg.Instance = IWDG;
421
  hiwdg.Init.Prescaler = IWDG_PRESCALER_4;
3 mjames 422
  hiwdg.Init.Reload = 819;
2 mjames 423
  if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
424
  {
425
    Error_Handler();
426
  }
427
  /* USER CODE BEGIN IWDG_Init 2 */
428
 
429
  /* USER CODE END IWDG_Init 2 */
430
}
431
 
432
/**
4 mjames 433
 * @brief SPI1 Initialization Function
434
 * @param None
435
 * @retval None
436
 */
2 mjames 437
static void MX_SPI1_Init(void)
438
{
439
 
440
  /* USER CODE BEGIN SPI1_Init 0 */
441
 
442
  /* USER CODE END SPI1_Init 0 */
443
 
444
  /* USER CODE BEGIN SPI1_Init 1 */
445
 
446
  /* USER CODE END SPI1_Init 1 */
447
  /* SPI1 parameter configuration*/
448
  hspi1.Instance = SPI1;
449
  hspi1.Init.Mode = SPI_MODE_MASTER;
450
  hspi1.Init.Direction = SPI_DIRECTION_2LINES;
451
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
452
  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
453
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
454
  hspi1.Init.NSS = SPI_NSS_SOFT;
455
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
456
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
457
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
458
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
459
  hspi1.Init.CRCPolynomial = 10;
460
  if (HAL_SPI_Init(&hspi1) != HAL_OK)
461
  {
462
    Error_Handler();
463
  }
464
  /* USER CODE BEGIN SPI1_Init 2 */
465
 
466
  /* USER CODE END SPI1_Init 2 */
467
}
468
 
469
/**
4 mjames 470
 * @brief TIM1 Initialization Function
471
 * @param None
472
 * @retval None
473
 */
2 mjames 474
static void MX_TIM1_Init(void)
475
{
476
 
477
  /* USER CODE BEGIN TIM1_Init 0 */
478
 
479
  /* USER CODE END TIM1_Init 0 */
480
 
481
  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
482
  TIM_MasterConfigTypeDef sMasterConfig = {0};
483
  TIM_OC_InitTypeDef sConfigOC = {0};
484
  TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
485
 
486
  /* USER CODE BEGIN TIM1_Init 1 */
487
 
488
  /* USER CODE END TIM1_Init 1 */
489
  htim1.Instance = TIM1;
490
  htim1.Init.Prescaler = 71;
491
  htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
492
  htim1.Init.Period = 65535;
493
  htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
494
  htim1.Init.RepetitionCounter = 0;
495
  htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
496
  if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
497
  {
498
    Error_Handler();
499
  }
500
  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
501
  if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
502
  {
503
    Error_Handler();
504
  }
505
  if (HAL_TIM_OC_Init(&htim1) != HAL_OK)
506
  {
507
    Error_Handler();
508
  }
509
  if (HAL_TIM_OnePulse_Init(&htim1, TIM_OPMODE_SINGLE) != HAL_OK)
510
  {
511
    Error_Handler();
512
  }
513
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_OC1REF;
514
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
515
  if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
516
  {
517
    Error_Handler();
518
  }
4 mjames 519
  sConfigOC.OCMode = TIM_OCMODE_ACTIVE;
520
  sConfigOC.Pulse = SAW_DELAY;
2 mjames 521
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
522
  sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
523
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
524
  sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
525
  sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
526
  if (HAL_TIM_OC_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
527
  {
528
    Error_Handler();
529
  }
530
  __HAL_TIM_ENABLE_OCxPRELOAD(&htim1, TIM_CHANNEL_1);
531
  sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
532
  sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
533
  sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
534
  sBreakDeadTimeConfig.DeadTime = 0;
535
  sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
536
  sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
537
  sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
538
  if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)
539
  {
540
    Error_Handler();
541
  }
542
  /* USER CODE BEGIN TIM1_Init 2 */
543
 
544
  /* USER CODE END TIM1_Init 2 */
545
  HAL_TIM_MspPostInit(&htim1);
546
}
547
 
548
/**
4 mjames 549
 * @brief TIM2 Initialization Function
550
 * @param None
551
 * @retval None
552
 */
2 mjames 553
static void MX_TIM2_Init(void)
554
{
555
 
556
  /* USER CODE BEGIN TIM2_Init 0 */
557
 
558
  /* USER CODE END TIM2_Init 0 */
559
 
560
  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
561
  TIM_SlaveConfigTypeDef sSlaveConfig = {0};
562
  TIM_MasterConfigTypeDef sMasterConfig = {0};
563
 
564
  /* USER CODE BEGIN TIM2_Init 1 */
565
 
566
  /* USER CODE END TIM2_Init 1 */
567
  htim2.Instance = TIM2;
568
  htim2.Init.Prescaler = 71;
569
  htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
570
  htim2.Init.Period = 9;
571
  htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
572
  htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
573
  if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
574
  {
575
    Error_Handler();
576
  }
577
  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
578
  if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
579
  {
580
    Error_Handler();
581
  }
582
  if (HAL_TIM_OnePulse_Init(&htim2, TIM_OPMODE_SINGLE) != HAL_OK)
583
  {
584
    Error_Handler();
585
  }
586
  sSlaveConfig.SlaveMode = TIM_SLAVEMODE_TRIGGER;
587
  sSlaveConfig.InputTrigger = TIM_TS_ETRF;
588
  sSlaveConfig.TriggerPolarity = TIM_TRIGGERPOLARITY_INVERTED;
589
  sSlaveConfig.TriggerPrescaler = TIM_TRIGGERPRESCALER_DIV1;
590
  sSlaveConfig.TriggerFilter = 15;
591
  if (HAL_TIM_SlaveConfigSynchro(&htim2, &sSlaveConfig) != HAL_OK)
592
  {
593
    Error_Handler();
594
  }
595
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
596
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
597
  if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
598
  {
599
    Error_Handler();
600
  }
601
  /* USER CODE BEGIN TIM2_Init 2 */
602
 
603
  /* USER CODE END TIM2_Init 2 */
604
}
605
 
606
/**
4 mjames 607
 * @brief TIM3 Initialization Function
608
 * @param None
609
 * @retval None
610
 */
2 mjames 611
static void MX_TIM3_Init(void)
612
{
613
 
614
  /* USER CODE BEGIN TIM3_Init 0 */
615
 
616
  /* USER CODE END TIM3_Init 0 */
617
 
618
  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
619
  TIM_MasterConfigTypeDef sMasterConfig = {0};
620
 
621
  /* USER CODE BEGIN TIM3_Init 1 */
622
 
623
  /* USER CODE END TIM3_Init 1 */
624
  htim3.Instance = TIM3;
625
  htim3.Init.Prescaler = 719;
626
  htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
627
  htim3.Init.Period = 10000;
628
  htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
629
  htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
630
  if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
631
  {
632
    Error_Handler();
633
  }
634
  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
635
  if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
636
  {
637
    Error_Handler();
638
  }
639
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
640
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
641
  if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
642
  {
643
    Error_Handler();
644
  }
645
  /* USER CODE BEGIN TIM3_Init 2 */
646
 
647
  /* USER CODE END TIM3_Init 2 */
648
}
649
 
650
/**
4 mjames 651
 * @brief USART2 Initialization Function
652
 * @param None
653
 * @retval None
654
 */
2 mjames 655
static void MX_USART2_UART_Init(void)
656
{
657
 
658
  /* USER CODE BEGIN USART2_Init 0 */
659
 
660
  /* USER CODE END USART2_Init 0 */
661
 
662
  /* USER CODE BEGIN USART2_Init 1 */
663
 
664
  /* USER CODE END USART2_Init 1 */
665
  huart2.Instance = USART2;
666
  huart2.Init.BaudRate = 19200;
667
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
668
  huart2.Init.StopBits = UART_STOPBITS_1;
669
  huart2.Init.Parity = UART_PARITY_NONE;
670
  huart2.Init.Mode = UART_MODE_TX_RX;
671
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
672
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
673
  if (HAL_UART_Init(&huart2) != HAL_OK)
674
  {
675
    Error_Handler();
676
  }
677
  /* USER CODE BEGIN USART2_Init 2 */
678
 
679
  /* USER CODE END USART2_Init 2 */
680
}
681
 
682
/**
4 mjames 683
 * @brief GPIO Initialization Function
684
 * @param None
685
 * @retval None
686
 */
2 mjames 687
static void MX_GPIO_Init(void)
688
{
689
  GPIO_InitTypeDef GPIO_InitStruct = {0};
690
 
691
  /* GPIO Ports Clock Enable */
692
  __HAL_RCC_GPIOD_CLK_ENABLE();
693
  __HAL_RCC_GPIOA_CLK_ENABLE();
694
  __HAL_RCC_GPIOB_CLK_ENABLE();
695
 
696
  /*Configure GPIO pin Output Level */
4 mjames 697
  HAL_GPIO_WritePin(GPIOA, SPI1_NSS_Pin | SPI1_RESET_Pin, GPIO_PIN_RESET);
2 mjames 698
 
699
  /*Configure GPIO pin Output Level */
4 mjames 700
  HAL_GPIO_WritePin(SPI1_CD_GPIO_Port, SPI1_CD_Pin, GPIO_PIN_RESET);
2 mjames 701
 
4 mjames 702
  /*Configure GPIO pins : SPI1_NSS_Pin SPI1_RESET_Pin */
703
  GPIO_InitStruct.Pin = SPI1_NSS_Pin | SPI1_RESET_Pin;
2 mjames 704
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
705
  GPIO_InitStruct.Pull = GPIO_NOPULL;
706
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
707
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
708
 
4 mjames 709
  /*Configure GPIO pin : SPI1_CD_Pin */
710
  GPIO_InitStruct.Pin = SPI1_CD_Pin;
2 mjames 711
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
712
  GPIO_InitStruct.Pull = GPIO_NOPULL;
713
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
4 mjames 714
  HAL_GPIO_Init(SPI1_CD_GPIO_Port, &GPIO_InitStruct);
2 mjames 715
 
4 mjames 716
  /*Configure GPIO pin : PUSHBUTTON_Pin */
717
  GPIO_InitStruct.Pin = PUSHBUTTON_Pin;
2 mjames 718
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
719
  GPIO_InitStruct.Pull = GPIO_PULLUP;
4 mjames 720
  HAL_GPIO_Init(PUSHBUTTON_GPIO_Port, &GPIO_InitStruct);
2 mjames 721
 
4 mjames 722
  /*Configure GPIO pin : dualSpark_Pin */
723
  GPIO_InitStruct.Pin = dualSpark_Pin;
2 mjames 724
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
725
  GPIO_InitStruct.Pull = GPIO_PULLUP;
4 mjames 726
  HAL_GPIO_Init(dualSpark_GPIO_Port, &GPIO_InitStruct);
2 mjames 727
}
728
 
729
/* USER CODE BEGIN 4 */
730
 
731
/* USER CODE END 4 */
732
 
733
/**
4 mjames 734
 * @brief  This function is executed in case of error occurrence.
735
 * @retval None
736
 */
2 mjames 737
void Error_Handler(void)
738
{
739
  /* USER CODE BEGIN Error_Handler_Debug */
740
  /* User can add his own implementation to report the HAL error return state */
741
  __disable_irq();
742
  while (1)
743
  {
744
  }
745
  /* USER CODE END Error_Handler_Debug */
746
}
747
 
4 mjames 748
#ifdef USE_FULL_ASSERT
2 mjames 749
/**
4 mjames 750
 * @brief  Reports the name of the source file and the source line number
751
 *         where the assert_param error has occurred.
752
 * @param  file: pointer to the source file name
753
 * @param  line: assert_param error line source number
754
 * @retval None
755
 */
2 mjames 756
void assert_failed(uint8_t *file, uint32_t line)
757
{
758
  /* USER CODE BEGIN 6 */
759
  /* User can add his own implementation to report the file name and line number,
760
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
761
  /* USER CODE END 6 */
762
}
763
#endif /* USE_FULL_ASSERT */