Subversion Repositories dashGPS

Rev

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