Subversion Repositories dashGPS

Rev

Rev 13 | Rev 21 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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