Subversion Repositories dashGPS

Rev

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