Subversion Repositories dashGPS

Rev

Rev 26 | Rev 28 | 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
/**
3
 ******************************************************************************
4
 * @file           : main.c
5
 * @brief          : Main program body
6
 ******************************************************************************
7
 * @attention
8
 *
9
 * <h2><center>&copy; 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
 */
19
/* USER CODE END Header */
20
/* Includes ------------------------------------------------------------------*/
21
#include "main.h"
13 mjames 22
#include "usb_device.h"
2 mjames 23
 
24
/* Private includes ----------------------------------------------------------*/
25
/* USER CODE BEGIN Includes */
26
#include "libSerial/serial.h"
11 mjames 27
#include "libBMP280/bmp280.h"
6 mjames 28
#include "display.h"
2 mjames 29
/* USER CODE END Includes */
30
 
31
/* Private typedef -----------------------------------------------------------*/
32
/* USER CODE BEGIN PTD */
33
 
34
/* USER CODE END PTD */
35
 
36
/* Private define ------------------------------------------------------------*/
37
/* USER CODE BEGIN PD */
38
/* USER CODE END PD */
39
 
40
/* Private macro -------------------------------------------------------------*/
41
/* USER CODE BEGIN PM */
42
 
43
/* USER CODE END PM */
44
 
45
/* Private variables ---------------------------------------------------------*/
11 mjames 46
I2C_HandleTypeDef hi2c2;
47
 
27 mjames 48
IWDG_HandleTypeDef hiwdg;
49
 
13 mjames 50
RTC_HandleTypeDef hrtc;
51
 
2 mjames 52
SPI_HandleTypeDef hspi1;
53
 
9 mjames 54
TIM_HandleTypeDef htim3;
2 mjames 55
TIM_HandleTypeDef htim4;
56
 
57
UART_HandleTypeDef huart1;
58
 
59
/* USER CODE BEGIN PV */
11 mjames 60
typedef struct
61
{
62
  uint8_t dev_addr;
63
} interface_t;
2 mjames 64
 
11 mjames 65
static int8_t
24 mjames 66
user_i2c_write (uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data,
67
                uint32_t len)
11 mjames 68
{
24 mjames 69
  HAL_StatusTypeDef st = HAL_I2C_Mem_Write (&hi2c2, i2c_addr << 1, reg_addr, 1,
70
                                            reg_data, len, 10000);
11 mjames 71
 
24 mjames 72
  return st != HAL_OK ? BMP280_E_COMM_FAIL : BMP280_OK;
11 mjames 73
 
74
}
75
static int8_t
24 mjames 76
user_i2c_read (uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data,
77
               uint32_t len)
11 mjames 78
{
24 mjames 79
  HAL_StatusTypeDef st = HAL_I2C_Mem_Read (&hi2c2, i2c_addr << 1, reg_addr, 1,
80
                                           reg_data, len, 10000);
11 mjames 81
 
24 mjames 82
  return st != HAL_OK ? BMP280_E_COMM_FAIL : BMP280_OK;
11 mjames 83
 
84
}
85
 
86
static void
87
user_delay_ms (uint32_t ms, void *handle)
88
{
89
  HAL_Delay (ms);
90
 
91
}
92
 
93
struct bmp280_dev bmp =
94
  {
26 mjames 95
  .intf = BMP280_I2C_INTF,
96
  .read = user_i2c_read,
97
  .write = user_i2c_write,
98
  .delay_ms = user_delay_ms,
11 mjames 99
 
26 mjames 100
   /* Update interface pointer with the structure that contains both device address and file descriptor */
101
  .dev_id = BMP280_I2C_ADDR_PRIM
102
  };
11 mjames 103
 
26 mjames 104
struct bmp280_dev bmp2 =
105
  {
106
  .intf = BMP280_I2C_INTF,
107
  .read = user_i2c_read,
108
  .write = user_i2c_write,
109
  .delay_ms = user_delay_ms,
11 mjames 110
 
26 mjames 111
  /* Update interface pointer with the structure that contains both device address and file descriptor */
112
  .dev_id = BMP280_I2C_ADDR_SEC
113
  };
114
 
11 mjames 115
int8_t rslt;
26 mjames 116
 
117
 
11 mjames 118
struct bmp280_config conf;
26 mjames 119
struct bmp280_config conf2;
11 mjames 120
 
2 mjames 121
/* USER CODE END PV */
122
 
123
/* Private function prototypes -----------------------------------------------*/
26 mjames 124
void SystemClock_Config(void);
125
static void MX_GPIO_Init(void);
126
static void MX_SPI1_Init(void);
127
static void MX_TIM4_Init(void);
128
static void MX_USART1_UART_Init(void);
129
static void MX_TIM3_Init(void);
130
static void MX_I2C2_Init(void);
131
static void MX_RTC_Init(void);
27 mjames 132
static void MX_IWDG_Init(void);
2 mjames 133
/* USER CODE BEGIN PFP */
134
 
135
/* USER CODE END PFP */
136
 
137
/* Private user code ---------------------------------------------------------*/
138
/* USER CODE BEGIN 0 */
139
 
26 mjames 140
uint32_t const TICKS_LOOP = 50; // 50mS per loop.
24 mjames 141
 
26 mjames 142
// initialise the BMP
143
uint8_t init_bmp(struct bmp280_config * conf, struct bmp280_dev * bmp )
144
{
145
  rslt = bmp280_init(bmp);
146
  if (rslt != BMP280_OK)
147
    return rslt;
148
 
149
  rslt = bmp280_get_config (conf, bmp);
150
  if (rslt != BMP280_OK)
151
    return rslt;
152
  /* configuring the temperature oversampling, filter coefficient and output data rate */
153
  /* Overwrite the desired settings */
154
  conf->filter = BMP280_FILTER_COEFF_2;
155
 
156
  /* Temperature oversampling set at 4x */
157
  conf->os_temp = BMP280_OS_4X;
158
 
159
  /* Pressure over sampling none (disabling pressure measurement) */
160
  conf->os_pres = BMP280_OS_4X;
161
 
162
  /* Setting the output data rate as 2HZ(500ms) */
163
  conf->odr = BMP280_ODR_500_MS;
164
  rslt = bmp280_set_config (conf, bmp);
165
  if (rslt != BMP280_OK)
166
    return rslt;
167
 
168
  /* Always set the power mode after setting the configuration */
169
  rslt = bmp280_set_power_mode (BMP280_NORMAL_MODE, bmp);
170
  if (rslt != BMP280_OK)
171
    return rslt;
172
 
173
}
174
 
175
 
176
 
177
 
178
 
2 mjames 179
/* USER CODE END 0 */
180
 
181
/**
26 mjames 182
  * @brief  The application entry point.
183
  * @retval int
184
  */
185
int main(void)
2 mjames 186
{
187
  /* USER CODE BEGIN 1 */
188
 
189
  /* USER CODE END 1 */
190
 
191
  /* MCU Configuration--------------------------------------------------------*/
192
 
193
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
26 mjames 194
  HAL_Init();
2 mjames 195
 
196
  /* USER CODE BEGIN Init */
197
 
198
  /* USER CODE END Init */
199
 
200
  /* Configure the system clock */
26 mjames 201
  SystemClock_Config();
2 mjames 202
 
203
  /* USER CODE BEGIN SysInit */
204
 
205
  /* USER CODE END SysInit */
206
 
207
  /* Initialize all configured peripherals */
26 mjames 208
  MX_GPIO_Init();
209
  MX_SPI1_Init();
210
  MX_TIM4_Init();
211
  MX_USART1_UART_Init();
212
  MX_TIM3_Init();
213
  MX_I2C2_Init();
214
  MX_RTC_Init();
215
  MX_USB_DEVICE_Init();
27 mjames 216
  MX_IWDG_Init();
2 mjames 217
  /* USER CODE BEGIN 2 */
14 mjames 218
 
219
  HAL_GPIO_WritePin ( USB_PULLUP_GPIO_Port, USB_PULLUP_Pin, GPIO_PIN_RESET);
220
  HAL_Delay (1000);
221
  HAL_GPIO_WritePin ( USB_PULLUP_GPIO_Port, USB_PULLUP_Pin, GPIO_PIN_SET);
222
 
24 mjames 223
  /* setup the USART control blocks */
2 mjames 224
 
22 mjames 225
#if defined SERIAL_UART1
27 mjames 226
  init_usart_ctl (&uc1, &huart1);
22 mjames 227
 
25 mjames 228
 
2 mjames 229
  EnableSerialRxInterrupt (&uc1);
25 mjames 230
 
22 mjames 231
#endif
2 mjames 232
 
26 mjames 233
  init_bmp(&conf,&bmp);
234
  init_bmp(&conf2,&bmp2);
11 mjames 235
 
26 mjames 236
   cc_init ();
11 mjames 237
 
238
 
24 mjames 239
  uint32_t timeNext = HAL_GetTick () + TICKS_LOOP;
11 mjames 240
 
2 mjames 241
  /* USER CODE END 2 */
242
 
243
  /* Infinite loop */
244
  /* USER CODE BEGIN WHILE */
245
  while (1)
246
    {
24 mjames 247
      uint32_t timeNow = HAL_GetTick ();
22 mjames 248
 
24 mjames 249
      if (timeNow < timeNext)
250
        HAL_Delay (timeNext - timeNow);
251
      timeNext += TICKS_LOOP;
26 mjames 252
      cc_run (&bmp, &bmp2);
2 mjames 253
 
27 mjames 254
      // refresh watchdog timer
255
      HAL_IWDG_Refresh(&hiwdg);
256
 
257
 
26 mjames 258
    /* USER CODE END WHILE */
14 mjames 259
 
26 mjames 260
    /* USER CODE BEGIN 3 */
2 mjames 261
    }
262
  /* USER CODE END 3 */
263
}
264
 
265
/**
26 mjames 266
  * @brief System Clock Configuration
267
  * @retval None
268
  */
269
void SystemClock_Config(void)
2 mjames 270
{
26 mjames 271
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
272
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
273
  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
2 mjames 274
 
275
  /** Initializes the RCC Oscillators according to the specified parameters
26 mjames 276
  * in the RCC_OscInitTypeDef structure.
277
  */
27 mjames 278
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE
279
                              |RCC_OSCILLATORTYPE_LSE;
2 mjames 280
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
281
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
13 mjames 282
  RCC_OscInitStruct.LSEState = RCC_LSE_ON;
2 mjames 283
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
27 mjames 284
  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
2 mjames 285
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
286
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
13 mjames 287
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
26 mjames 288
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
289
  {
290
    Error_Handler();
291
  }
2 mjames 292
  /** Initializes the CPU, AHB and APB buses clocks
26 mjames 293
  */
294
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
295
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
2 mjames 296
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
297
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
298
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
299
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
300
 
26 mjames 301
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
302
  {
303
    Error_Handler();
304
  }
305
  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_USB;
13 mjames 306
  PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
307
  PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
26 mjames 308
  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
309
  {
310
    Error_Handler();
311
  }
2 mjames 312
}
313
 
314
/**
26 mjames 315
  * @brief I2C2 Initialization Function
316
  * @param None
317
  * @retval None
318
  */
319
static void MX_I2C2_Init(void)
11 mjames 320
{
321
 
322
  /* USER CODE BEGIN I2C2_Init 0 */
323
 
324
  /* USER CODE END I2C2_Init 0 */
325
 
326
  /* USER CODE BEGIN I2C2_Init 1 */
327
 
328
  /* USER CODE END I2C2_Init 1 */
329
  hi2c2.Instance = I2C2;
330
  hi2c2.Init.ClockSpeed = 100000;
331
  hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2;
332
  hi2c2.Init.OwnAddress1 = 0;
333
  hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
334
  hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
335
  hi2c2.Init.OwnAddress2 = 0;
336
  hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
337
  hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
26 mjames 338
  if (HAL_I2C_Init(&hi2c2) != HAL_OK)
339
  {
340
    Error_Handler();
341
  }
11 mjames 342
  /* USER CODE BEGIN I2C2_Init 2 */
343
 
344
  /* USER CODE END I2C2_Init 2 */
345
 
346
}
347
 
348
/**
27 mjames 349
  * @brief IWDG Initialization Function
350
  * @param None
351
  * @retval None
352
  */
353
static void MX_IWDG_Init(void)
354
{
355
 
356
  /* USER CODE BEGIN IWDG_Init 0 */
357
 
358
  /* USER CODE END IWDG_Init 0 */
359
 
360
  /* USER CODE BEGIN IWDG_Init 1 */
361
 
362
  /* USER CODE END IWDG_Init 1 */
363
  hiwdg.Instance = IWDG;
364
  hiwdg.Init.Prescaler = IWDG_PRESCALER_16;
365
  hiwdg.Init.Reload = 4095;
366
  if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
367
  {
368
    Error_Handler();
369
  }
370
  /* USER CODE BEGIN IWDG_Init 2 */
371
 
372
  /* USER CODE END IWDG_Init 2 */
373
 
374
}
375
 
376
/**
26 mjames 377
  * @brief RTC Initialization Function
378
  * @param None
379
  * @retval None
380
  */
381
static void MX_RTC_Init(void)
13 mjames 382
{
383
 
384
  /* USER CODE BEGIN RTC_Init 0 */
385
 
386
  /* USER CODE END RTC_Init 0 */
387
 
26 mjames 388
  RTC_TimeTypeDef sTime = {0};
389
  RTC_DateTypeDef DateToUpdate = {0};
13 mjames 390
 
391
  /* USER CODE BEGIN RTC_Init 1 */
392
 
393
  /* USER CODE END RTC_Init 1 */
394
  /** Initialize RTC Only
26 mjames 395
  */
13 mjames 396
  hrtc.Instance = RTC;
397
  hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
398
  hrtc.Init.OutPut = RTC_OUTPUTSOURCE_ALARM;
26 mjames 399
  if (HAL_RTC_Init(&hrtc) != HAL_OK)
400
  {
401
    Error_Handler();
402
  }
13 mjames 403
 
404
  /* USER CODE BEGIN Check_RTC_BKUP */
405
 
406
  /* USER CODE END Check_RTC_BKUP */
407
 
408
  /** Initialize RTC and set the Time and Date
26 mjames 409
  */
13 mjames 410
  sTime.Hours = 0x0;
411
  sTime.Minutes = 0x0;
412
  sTime.Seconds = 0x0;
413
 
26 mjames 414
  if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
415
  {
416
    Error_Handler();
417
  }
13 mjames 418
  DateToUpdate.WeekDay = RTC_WEEKDAY_MONDAY;
419
  DateToUpdate.Month = RTC_MONTH_JANUARY;
420
  DateToUpdate.Date = 0x1;
421
  DateToUpdate.Year = 0x0;
422
 
26 mjames 423
  if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BCD) != HAL_OK)
424
  {
425
    Error_Handler();
426
  }
13 mjames 427
  /* USER CODE BEGIN RTC_Init 2 */
428
 
429
  /* USER CODE END RTC_Init 2 */
430
 
431
}
432
 
433
/**
26 mjames 434
  * @brief SPI1 Initialization Function
435
  * @param None
436
  * @retval None
437
  */
438
static void MX_SPI1_Init(void)
2 mjames 439
{
440
 
441
  /* USER CODE BEGIN SPI1_Init 0 */
442
 
443
  /* USER CODE END SPI1_Init 0 */
444
 
445
  /* USER CODE BEGIN SPI1_Init 1 */
446
 
447
  /* USER CODE END SPI1_Init 1 */
448
  /* SPI1 parameter configuration*/
449
  hspi1.Instance = SPI1;
450
  hspi1.Init.Mode = SPI_MODE_MASTER;
451
  hspi1.Init.Direction = SPI_DIRECTION_1LINE;
452
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
5 mjames 453
  hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
454
  hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
2 mjames 455
  hspi1.Init.NSS = SPI_NSS_SOFT;
456
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
457
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
458
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
459
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
460
  hspi1.Init.CRCPolynomial = 10;
26 mjames 461
  if (HAL_SPI_Init(&hspi1) != HAL_OK)
462
  {
463
    Error_Handler();
464
  }
2 mjames 465
  /* USER CODE BEGIN SPI1_Init 2 */
466
 
467
  /* USER CODE END SPI1_Init 2 */
468
 
469
}
470
 
471
/**
26 mjames 472
  * @brief TIM3 Initialization Function
473
  * @param None
474
  * @retval None
475
  */
476
static void MX_TIM3_Init(void)
2 mjames 477
{
478
 
9 mjames 479
  /* USER CODE BEGIN TIM3_Init 0 */
480
 
481
  /* USER CODE END TIM3_Init 0 */
482
 
26 mjames 483
  TIM_MasterConfigTypeDef sMasterConfig = {0};
484
  TIM_OC_InitTypeDef sConfigOC = {0};
9 mjames 485
 
486
  /* USER CODE BEGIN TIM3_Init 1 */
487
 
488
  /* USER CODE END TIM3_Init 1 */
489
  htim3.Instance = TIM3;
21 mjames 490
  htim3.Init.Prescaler = 719;
9 mjames 491
  htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
492
  htim3.Init.Period = 10000;
493
  htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
494
  htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
26 mjames 495
  if (HAL_TIM_OC_Init(&htim3) != HAL_OK)
496
  {
497
    Error_Handler();
498
  }
499
  if (HAL_TIM_OnePulse_Init(&htim3, TIM_OPMODE_SINGLE) != HAL_OK)
500
  {
501
    Error_Handler();
502
  }
9 mjames 503
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_ENABLE;
504
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
26 mjames 505
  if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
506
  {
507
    Error_Handler();
508
  }
9 mjames 509
  sConfigOC.OCMode = TIM_OCMODE_TIMING;
510
  sConfigOC.Pulse = 9999;
511
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
512
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
26 mjames 513
  if (HAL_TIM_OC_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
514
  {
515
    Error_Handler();
516
  }
9 mjames 517
  /* USER CODE BEGIN TIM3_Init 2 */
518
 
519
  /* USER CODE END TIM3_Init 2 */
520
 
521
}
522
 
523
/**
26 mjames 524
  * @brief TIM4 Initialization Function
525
  * @param None
526
  * @retval None
527
  */
528
static void MX_TIM4_Init(void)
9 mjames 529
{
530
 
2 mjames 531
  /* USER CODE BEGIN TIM4_Init 0 */
532
 
533
  /* USER CODE END TIM4_Init 0 */
534
 
26 mjames 535
  TIM_Encoder_InitTypeDef sConfig = {0};
536
  TIM_MasterConfigTypeDef sMasterConfig = {0};
2 mjames 537
 
538
  /* USER CODE BEGIN TIM4_Init 1 */
539
 
540
  /* USER CODE END TIM4_Init 1 */
541
  htim4.Instance = TIM4;
542
  htim4.Init.Prescaler = 0;
543
  htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
544
  htim4.Init.Period = 65535;
545
  htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
546
  htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
547
  sConfig.EncoderMode = TIM_ENCODERMODE_TI12;
548
  sConfig.IC1Polarity = TIM_ICPOLARITY_RISING;
549
  sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI;
550
  sConfig.IC1Prescaler = TIM_ICPSC_DIV1;
21 mjames 551
  sConfig.IC1Filter = 15;
2 mjames 552
  sConfig.IC2Polarity = TIM_ICPOLARITY_RISING;
553
  sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
554
  sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
21 mjames 555
  sConfig.IC2Filter = 15;
26 mjames 556
  if (HAL_TIM_Encoder_Init(&htim4, &sConfig) != HAL_OK)
557
  {
558
    Error_Handler();
559
  }
2 mjames 560
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
561
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
26 mjames 562
  if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
563
  {
564
    Error_Handler();
565
  }
2 mjames 566
  /* USER CODE BEGIN TIM4_Init 2 */
567
 
568
  /* USER CODE END TIM4_Init 2 */
569
 
570
}
571
 
572
/**
26 mjames 573
  * @brief USART1 Initialization Function
574
  * @param None
575
  * @retval None
576
  */
577
static void MX_USART1_UART_Init(void)
2 mjames 578
{
579
 
580
  /* USER CODE BEGIN USART1_Init 0 */
581
 
582
  /* USER CODE END USART1_Init 0 */
583
 
584
  /* USER CODE BEGIN USART1_Init 1 */
585
 
586
  /* USER CODE END USART1_Init 1 */
587
  huart1.Instance = USART1;
27 mjames 588
  huart1.Init.BaudRate = 9600;
2 mjames 589
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
590
  huart1.Init.StopBits = UART_STOPBITS_1;
591
  huart1.Init.Parity = UART_PARITY_NONE;
592
  huart1.Init.Mode = UART_MODE_TX_RX;
593
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
594
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
26 mjames 595
  if (HAL_UART_Init(&huart1) != HAL_OK)
596
  {
597
    Error_Handler();
598
  }
2 mjames 599
  /* USER CODE BEGIN USART1_Init 2 */
600
 
601
  /* USER CODE END USART1_Init 2 */
602
 
603
}
604
 
605
/**
26 mjames 606
  * @brief GPIO Initialization Function
607
  * @param None
608
  * @retval None
609
  */
610
static void MX_GPIO_Init(void)
2 mjames 611
{
26 mjames 612
  GPIO_InitTypeDef GPIO_InitStruct = {0};
2 mjames 613
 
614
  /* GPIO Ports Clock Enable */
5 mjames 615
  __HAL_RCC_GPIOC_CLK_ENABLE();
2 mjames 616
  __HAL_RCC_GPIOD_CLK_ENABLE();
617
  __HAL_RCC_GPIOA_CLK_ENABLE();
618
  __HAL_RCC_GPIOB_CLK_ENABLE();
619
 
620
  /*Configure GPIO pin Output Level */
27 mjames 621
  HAL_GPIO_WritePin(Green_LED_GPIO_Port, Green_LED_Pin, GPIO_PIN_RESET);
622
 
623
  /*Configure GPIO pin Output Level */
26 mjames 624
  HAL_GPIO_WritePin(GPIOA, SPI_CD_Pin|SPI_RESET_Pin|SPI_NSS1_Pin, GPIO_PIN_RESET);
2 mjames 625
 
14 mjames 626
  /*Configure GPIO pin Output Level */
26 mjames 627
  HAL_GPIO_WritePin(USB_PULLUP_GPIO_Port, USB_PULLUP_Pin, GPIO_PIN_RESET);
14 mjames 628
 
27 mjames 629
  /*Configure GPIO pin : Green_LED_Pin */
630
  GPIO_InitStruct.Pin = Green_LED_Pin;
631
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
632
  GPIO_InitStruct.Pull = GPIO_NOPULL;
633
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
634
  HAL_GPIO_Init(Green_LED_GPIO_Port, &GPIO_InitStruct);
635
 
13 mjames 636
  /*Configure GPIO pins : SPI_CD_Pin SPI_RESET_Pin SPI_NSS1_Pin */
26 mjames 637
  GPIO_InitStruct.Pin = SPI_CD_Pin|SPI_RESET_Pin|SPI_NSS1_Pin;
2 mjames 638
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
639
  GPIO_InitStruct.Pull = GPIO_NOPULL;
640
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
26 mjames 641
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
2 mjames 642
 
14 mjames 643
  /*Configure GPIO pin : USB_PULLUP_Pin */
644
  GPIO_InitStruct.Pin = USB_PULLUP_Pin;
645
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
646
  GPIO_InitStruct.Pull = GPIO_NOPULL;
647
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
26 mjames 648
  HAL_GPIO_Init(USB_PULLUP_GPIO_Port, &GPIO_InitStruct);
14 mjames 649
 
21 mjames 650
  /*Configure GPIO pin : encoder_push_Pin */
651
  GPIO_InitStruct.Pin = encoder_push_Pin;
652
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
653
  GPIO_InitStruct.Pull = GPIO_PULLUP;
26 mjames 654
  HAL_GPIO_Init(encoder_push_GPIO_Port, &GPIO_InitStruct);
21 mjames 655
 
2 mjames 656
}
657
 
658
/* USER CODE BEGIN 4 */
659
 
660
/* USER CODE END 4 */
661
 
662
/**
26 mjames 663
  * @brief  This function is executed in case of error occurrence.
664
  * @retval None
665
  */
666
void Error_Handler(void)
2 mjames 667
{
668
  /* USER CODE BEGIN Error_Handler_Debug */
669
  /* User can add his own implementation to report the HAL error return state */
670
 
671
  /* USER CODE END Error_Handler_Debug */
672
}
673
 
674
#ifdef  USE_FULL_ASSERT
675
/**
676
  * @brief  Reports the name of the source file and the source line number
677
  *         where the assert_param error has occurred.
678
  * @param  file: pointer to the source file name
679
  * @param  line: assert_param error line source number
680
  * @retval None
681
  */
682
void assert_failed(uint8_t *file, uint32_t line)
683
{
684
  /* USER CODE BEGIN 6 */
685
  /* User can add his own implementation to report the file name and line number,
686
     tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
687
  /* USER CODE END 6 */
688
}
689
#endif /* USE_FULL_ASSERT */
690
 
691
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/