![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
f303_h_p1 1
I2C_SLAVE_TEST2_031_2/main.c@26:a047b389adfd, 2022-05-06 (annotated)
- Committer:
- caa45040
- Date:
- Fri May 06 14:22:30 2022 +0000
- Revision:
- 26:a047b389adfd
- Parent:
- 20:745e8267e7f5
i2c_slave_HC_SR04_010_BIN re
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
caa45040 | 20:745e8267e7f5 | 1 | /* USER CODE BEGIN Header */ |
caa45040 | 20:745e8267e7f5 | 2 | /** |
caa45040 | 20:745e8267e7f5 | 3 | ****************************************************************************** |
caa45040 | 20:745e8267e7f5 | 4 | * @file : main.c |
caa45040 | 20:745e8267e7f5 | 5 | * @brief : Main program body |
caa45040 | 20:745e8267e7f5 | 6 | ****************************************************************************** |
caa45040 | 20:745e8267e7f5 | 7 | * @attention |
caa45040 | 20:745e8267e7f5 | 8 | * |
caa45040 | 20:745e8267e7f5 | 9 | * <h2><center>© Copyright (c) 2021 STMicroelectronics. |
caa45040 | 20:745e8267e7f5 | 10 | * All rights reserved.</center></h2> |
caa45040 | 20:745e8267e7f5 | 11 | * |
caa45040 | 20:745e8267e7f5 | 12 | * This software component is licensed by ST under BSD 3-Clause license, |
caa45040 | 20:745e8267e7f5 | 13 | * the "License"; You may not use this file except in compliance with the |
caa45040 | 20:745e8267e7f5 | 14 | * License. You may obtain a copy of the License at: |
caa45040 | 20:745e8267e7f5 | 15 | * opensource.org/licenses/BSD-3-Clause |
caa45040 | 20:745e8267e7f5 | 16 | * |
caa45040 | 20:745e8267e7f5 | 17 | ****************************************************************************** |
caa45040 | 20:745e8267e7f5 | 18 | */ |
caa45040 | 20:745e8267e7f5 | 19 | /* USER CODE END Header */ |
caa45040 | 20:745e8267e7f5 | 20 | /* Includes ------------------------------------------------------------------*/ |
caa45040 | 20:745e8267e7f5 | 21 | #include "main.h" |
caa45040 | 20:745e8267e7f5 | 22 | |
caa45040 | 20:745e8267e7f5 | 23 | /* Private includes ----------------------------------------------------------*/ |
caa45040 | 20:745e8267e7f5 | 24 | /* USER CODE BEGIN Includes */ |
caa45040 | 20:745e8267e7f5 | 25 | |
caa45040 | 20:745e8267e7f5 | 26 | /* USER CODE END Includes */ |
caa45040 | 20:745e8267e7f5 | 27 | |
caa45040 | 20:745e8267e7f5 | 28 | /* Private typedef -----------------------------------------------------------*/ |
caa45040 | 20:745e8267e7f5 | 29 | /* USER CODE BEGIN PTD */ |
caa45040 | 20:745e8267e7f5 | 30 | |
caa45040 | 20:745e8267e7f5 | 31 | /* USER CODE END PTD */ |
caa45040 | 20:745e8267e7f5 | 32 | |
caa45040 | 20:745e8267e7f5 | 33 | /* Private define ------------------------------------------------------------*/ |
caa45040 | 20:745e8267e7f5 | 34 | /* USER CODE BEGIN PD */ |
caa45040 | 20:745e8267e7f5 | 35 | /* USER CODE END PD */ |
caa45040 | 20:745e8267e7f5 | 36 | |
caa45040 | 20:745e8267e7f5 | 37 | /* Private macro -------------------------------------------------------------*/ |
caa45040 | 20:745e8267e7f5 | 38 | /* USER CODE BEGIN PM */ |
caa45040 | 20:745e8267e7f5 | 39 | |
caa45040 | 20:745e8267e7f5 | 40 | /* USER CODE END PM */ |
caa45040 | 20:745e8267e7f5 | 41 | |
caa45040 | 20:745e8267e7f5 | 42 | /* Private variables ---------------------------------------------------------*/ |
caa45040 | 20:745e8267e7f5 | 43 | I2C_HandleTypeDef hi2c2; |
caa45040 | 20:745e8267e7f5 | 44 | |
caa45040 | 20:745e8267e7f5 | 45 | UART_HandleTypeDef huart2; |
caa45040 | 20:745e8267e7f5 | 46 | |
caa45040 | 20:745e8267e7f5 | 47 | /* USER CODE BEGIN PV */ |
caa45040 | 20:745e8267e7f5 | 48 | |
caa45040 | 20:745e8267e7f5 | 49 | /* USER CODE END PV */ |
caa45040 | 20:745e8267e7f5 | 50 | |
caa45040 | 20:745e8267e7f5 | 51 | /* Private function prototypes -----------------------------------------------*/ |
caa45040 | 20:745e8267e7f5 | 52 | void SystemClock_Config(void); |
caa45040 | 20:745e8267e7f5 | 53 | static void MX_GPIO_Init(void); |
caa45040 | 20:745e8267e7f5 | 54 | static void MX_I2C2_Init(void); |
caa45040 | 20:745e8267e7f5 | 55 | static void MX_USART2_UART_Init(void); |
caa45040 | 20:745e8267e7f5 | 56 | /* USER CODE BEGIN PFP */ |
caa45040 | 20:745e8267e7f5 | 57 | |
caa45040 | 20:745e8267e7f5 | 58 | /* USER CODE END PFP */ |
caa45040 | 20:745e8267e7f5 | 59 | |
caa45040 | 20:745e8267e7f5 | 60 | /* Private user code ---------------------------------------------------------*/ |
caa45040 | 20:745e8267e7f5 | 61 | /* USER CODE BEGIN 0 */ |
caa45040 | 20:745e8267e7f5 | 62 | |
caa45040 | 20:745e8267e7f5 | 63 | /* USER CODE END 0 */ |
caa45040 | 20:745e8267e7f5 | 64 | |
caa45040 | 20:745e8267e7f5 | 65 | /** |
caa45040 | 20:745e8267e7f5 | 66 | * @brief The application entry point. |
caa45040 | 20:745e8267e7f5 | 67 | * @retval int |
caa45040 | 20:745e8267e7f5 | 68 | */ |
caa45040 | 20:745e8267e7f5 | 69 | int main(void) |
caa45040 | 20:745e8267e7f5 | 70 | { |
caa45040 | 20:745e8267e7f5 | 71 | /* USER CODE BEGIN 1 */ |
caa45040 | 20:745e8267e7f5 | 72 | |
caa45040 | 20:745e8267e7f5 | 73 | /* USER CODE END 1 */ |
caa45040 | 20:745e8267e7f5 | 74 | |
caa45040 | 20:745e8267e7f5 | 75 | /* MCU Configuration--------------------------------------------------------*/ |
caa45040 | 20:745e8267e7f5 | 76 | |
caa45040 | 20:745e8267e7f5 | 77 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
caa45040 | 20:745e8267e7f5 | 78 | HAL_Init(); |
caa45040 | 20:745e8267e7f5 | 79 | |
caa45040 | 20:745e8267e7f5 | 80 | /* USER CODE BEGIN Init */ |
caa45040 | 20:745e8267e7f5 | 81 | |
caa45040 | 20:745e8267e7f5 | 82 | /* USER CODE END Init */ |
caa45040 | 20:745e8267e7f5 | 83 | |
caa45040 | 20:745e8267e7f5 | 84 | /* Configure the system clock */ |
caa45040 | 20:745e8267e7f5 | 85 | SystemClock_Config(); |
caa45040 | 20:745e8267e7f5 | 86 | |
caa45040 | 20:745e8267e7f5 | 87 | /* USER CODE BEGIN SysInit */ |
caa45040 | 20:745e8267e7f5 | 88 | |
caa45040 | 20:745e8267e7f5 | 89 | /* USER CODE END SysInit */ |
caa45040 | 20:745e8267e7f5 | 90 | |
caa45040 | 20:745e8267e7f5 | 91 | /* Initialize all configured peripherals */ |
caa45040 | 20:745e8267e7f5 | 92 | MX_GPIO_Init(); |
caa45040 | 20:745e8267e7f5 | 93 | MX_I2C2_Init(); |
caa45040 | 20:745e8267e7f5 | 94 | MX_USART2_UART_Init(); |
caa45040 | 20:745e8267e7f5 | 95 | /* USER CODE BEGIN 2 */ |
caa45040 | 20:745e8267e7f5 | 96 | |
caa45040 | 20:745e8267e7f5 | 97 | /* USER CODE END 2 */ |
caa45040 | 20:745e8267e7f5 | 98 | |
caa45040 | 20:745e8267e7f5 | 99 | /* Infinite loop */ |
caa45040 | 20:745e8267e7f5 | 100 | /* USER CODE BEGIN WHILE */ |
caa45040 | 20:745e8267e7f5 | 101 | while (1) |
caa45040 | 20:745e8267e7f5 | 102 | { |
caa45040 | 20:745e8267e7f5 | 103 | /* USER CODE END WHILE */ |
caa45040 | 20:745e8267e7f5 | 104 | |
caa45040 | 20:745e8267e7f5 | 105 | |
caa45040 | 20:745e8267e7f5 | 106 | //I2Cのアドレスの設定も忘れずに「hi2c2.Init.OwnAddress1 = 0x80;」 |
caa45040 | 20:745e8267e7f5 | 107 | |
caa45040 | 20:745e8267e7f5 | 108 | uint8_t aRxBuffer[10] = {0}; |
caa45040 | 20:745e8267e7f5 | 109 | |
caa45040 | 20:745e8267e7f5 | 110 | while (HAL_I2C_Slave_Receive(&hi2c2,aRxBuffer, 1, 1000) != HAL_OK) {}; |
caa45040 | 20:745e8267e7f5 | 111 | |
caa45040 | 20:745e8267e7f5 | 112 | //LED ON debug |
caa45040 | 20:745e8267e7f5 | 113 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_SET); |
caa45040 | 20:745e8267e7f5 | 114 | //HAL_Delay(500); //debug |
caa45040 | 20:745e8267e7f5 | 115 | |
caa45040 | 20:745e8267e7f5 | 116 | |
caa45040 | 20:745e8267e7f5 | 117 | //I2Cスレーブの受信データの表示 |
caa45040 | 20:745e8267e7f5 | 118 | HAL_UART_Transmit(&huart2,aRxBuffer, 1, 10); |
caa45040 | 20:745e8267e7f5 | 119 | |
caa45040 | 20:745e8267e7f5 | 120 | //I2Cスレーブの受信データの表示 |
caa45040 | 20:745e8267e7f5 | 121 | //HAL_UART_Transmit(&huart2, (uint8_t *)"\tRead A: ", 9, 10); |
caa45040 | 20:745e8267e7f5 | 122 | //uint8_t n1 = '0' + (aRxBuffer[0] % 16); |
caa45040 | 20:745e8267e7f5 | 123 | //uint8_t n10 = '0' + (aRxBuffer[0] / 16); |
caa45040 | 20:745e8267e7f5 | 124 | //HAL_UART_Transmit(&huart2, &n10, 1, 10); |
caa45040 | 20:745e8267e7f5 | 125 | //HAL_UART_Transmit(&huart2, &n1, 1, 10); |
caa45040 | 20:745e8267e7f5 | 126 | //HAL_UART_Transmit(&huart2, (uint8_t *)"\r\n", 2, 10); |
caa45040 | 20:745e8267e7f5 | 127 | |
caa45040 | 20:745e8267e7f5 | 128 | //LED OFF debug |
caa45040 | 20:745e8267e7f5 | 129 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_RESET); |
caa45040 | 20:745e8267e7f5 | 130 | //HAL_Delay(500); //debug |
caa45040 | 20:745e8267e7f5 | 131 | |
caa45040 | 20:745e8267e7f5 | 132 | |
caa45040 | 20:745e8267e7f5 | 133 | /* USER CODE BEGIN 3 */ |
caa45040 | 20:745e8267e7f5 | 134 | } |
caa45040 | 20:745e8267e7f5 | 135 | /* USER CODE END 3 */ |
caa45040 | 20:745e8267e7f5 | 136 | } |
caa45040 | 20:745e8267e7f5 | 137 | |
caa45040 | 20:745e8267e7f5 | 138 | /** |
caa45040 | 20:745e8267e7f5 | 139 | * @brief System Clock Configuration |
caa45040 | 20:745e8267e7f5 | 140 | * @retval None |
caa45040 | 20:745e8267e7f5 | 141 | */ |
caa45040 | 20:745e8267e7f5 | 142 | void SystemClock_Config(void) |
caa45040 | 20:745e8267e7f5 | 143 | { |
caa45040 | 20:745e8267e7f5 | 144 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
caa45040 | 20:745e8267e7f5 | 145 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
caa45040 | 20:745e8267e7f5 | 146 | |
caa45040 | 20:745e8267e7f5 | 147 | /** Configure the main internal regulator output voltage |
caa45040 | 20:745e8267e7f5 | 148 | */ |
caa45040 | 20:745e8267e7f5 | 149 | HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); |
caa45040 | 20:745e8267e7f5 | 150 | /** Initializes the RCC Oscillators according to the specified parameters |
caa45040 | 20:745e8267e7f5 | 151 | * in the RCC_OscInitTypeDef structure. |
caa45040 | 20:745e8267e7f5 | 152 | */ |
caa45040 | 20:745e8267e7f5 | 153 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; |
caa45040 | 20:745e8267e7f5 | 154 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
caa45040 | 20:745e8267e7f5 | 155 | RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; |
caa45040 | 20:745e8267e7f5 | 156 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; |
caa45040 | 20:745e8267e7f5 | 157 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
caa45040 | 20:745e8267e7f5 | 158 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; |
caa45040 | 20:745e8267e7f5 | 159 | RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1; |
caa45040 | 20:745e8267e7f5 | 160 | RCC_OscInitStruct.PLL.PLLN = 8; |
caa45040 | 20:745e8267e7f5 | 161 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; |
caa45040 | 20:745e8267e7f5 | 162 | RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2; |
caa45040 | 20:745e8267e7f5 | 163 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
caa45040 | 20:745e8267e7f5 | 164 | { |
caa45040 | 20:745e8267e7f5 | 165 | Error_Handler(); |
caa45040 | 20:745e8267e7f5 | 166 | } |
caa45040 | 20:745e8267e7f5 | 167 | /** Initializes the CPU, AHB and APB buses clocks |
caa45040 | 20:745e8267e7f5 | 168 | */ |
caa45040 | 20:745e8267e7f5 | 169 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
caa45040 | 20:745e8267e7f5 | 170 | |RCC_CLOCKTYPE_PCLK1; |
caa45040 | 20:745e8267e7f5 | 171 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
caa45040 | 20:745e8267e7f5 | 172 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
caa45040 | 20:745e8267e7f5 | 173 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; |
caa45040 | 20:745e8267e7f5 | 174 | |
caa45040 | 20:745e8267e7f5 | 175 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) |
caa45040 | 20:745e8267e7f5 | 176 | { |
caa45040 | 20:745e8267e7f5 | 177 | Error_Handler(); |
caa45040 | 20:745e8267e7f5 | 178 | } |
caa45040 | 20:745e8267e7f5 | 179 | } |
caa45040 | 20:745e8267e7f5 | 180 | |
caa45040 | 20:745e8267e7f5 | 181 | /** |
caa45040 | 20:745e8267e7f5 | 182 | * @brief I2C2 Initialization Function |
caa45040 | 20:745e8267e7f5 | 183 | * @param None |
caa45040 | 20:745e8267e7f5 | 184 | * @retval None |
caa45040 | 20:745e8267e7f5 | 185 | */ |
caa45040 | 20:745e8267e7f5 | 186 | static void MX_I2C2_Init(void) |
caa45040 | 20:745e8267e7f5 | 187 | { |
caa45040 | 20:745e8267e7f5 | 188 | |
caa45040 | 20:745e8267e7f5 | 189 | /* USER CODE BEGIN I2C2_Init 0 */ |
caa45040 | 20:745e8267e7f5 | 190 | |
caa45040 | 20:745e8267e7f5 | 191 | /* USER CODE END I2C2_Init 0 */ |
caa45040 | 20:745e8267e7f5 | 192 | |
caa45040 | 20:745e8267e7f5 | 193 | /* USER CODE BEGIN I2C2_Init 1 */ |
caa45040 | 20:745e8267e7f5 | 194 | |
caa45040 | 20:745e8267e7f5 | 195 | /* USER CODE END I2C2_Init 1 */ |
caa45040 | 20:745e8267e7f5 | 196 | hi2c2.Instance = I2C2; |
caa45040 | 20:745e8267e7f5 | 197 | hi2c2.Init.Timing = 0x10707DBC; |
caa45040 | 20:745e8267e7f5 | 198 | hi2c2.Init.OwnAddress1 = 0x80; |
caa45040 | 20:745e8267e7f5 | 199 | hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; |
caa45040 | 20:745e8267e7f5 | 200 | hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; |
caa45040 | 20:745e8267e7f5 | 201 | hi2c2.Init.OwnAddress2 = 0; |
caa45040 | 20:745e8267e7f5 | 202 | hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK; |
caa45040 | 20:745e8267e7f5 | 203 | hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; |
caa45040 | 20:745e8267e7f5 | 204 | hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; |
caa45040 | 20:745e8267e7f5 | 205 | if (HAL_I2C_Init(&hi2c2) != HAL_OK) |
caa45040 | 20:745e8267e7f5 | 206 | { |
caa45040 | 20:745e8267e7f5 | 207 | Error_Handler(); |
caa45040 | 20:745e8267e7f5 | 208 | } |
caa45040 | 20:745e8267e7f5 | 209 | /** Configure Analogue filter |
caa45040 | 20:745e8267e7f5 | 210 | */ |
caa45040 | 20:745e8267e7f5 | 211 | if (HAL_I2CEx_ConfigAnalogFilter(&hi2c2, I2C_ANALOGFILTER_ENABLE) != HAL_OK) |
caa45040 | 20:745e8267e7f5 | 212 | { |
caa45040 | 20:745e8267e7f5 | 213 | Error_Handler(); |
caa45040 | 20:745e8267e7f5 | 214 | } |
caa45040 | 20:745e8267e7f5 | 215 | /** Configure Digital filter |
caa45040 | 20:745e8267e7f5 | 216 | */ |
caa45040 | 20:745e8267e7f5 | 217 | if (HAL_I2CEx_ConfigDigitalFilter(&hi2c2, 0) != HAL_OK) |
caa45040 | 20:745e8267e7f5 | 218 | { |
caa45040 | 20:745e8267e7f5 | 219 | Error_Handler(); |
caa45040 | 20:745e8267e7f5 | 220 | } |
caa45040 | 20:745e8267e7f5 | 221 | /* USER CODE BEGIN I2C2_Init 2 */ |
caa45040 | 20:745e8267e7f5 | 222 | |
caa45040 | 20:745e8267e7f5 | 223 | /* USER CODE END I2C2_Init 2 */ |
caa45040 | 20:745e8267e7f5 | 224 | |
caa45040 | 20:745e8267e7f5 | 225 | } |
caa45040 | 20:745e8267e7f5 | 226 | |
caa45040 | 20:745e8267e7f5 | 227 | /** |
caa45040 | 20:745e8267e7f5 | 228 | * @brief USART2 Initialization Function |
caa45040 | 20:745e8267e7f5 | 229 | * @param None |
caa45040 | 20:745e8267e7f5 | 230 | * @retval None |
caa45040 | 20:745e8267e7f5 | 231 | */ |
caa45040 | 20:745e8267e7f5 | 232 | static void MX_USART2_UART_Init(void) |
caa45040 | 20:745e8267e7f5 | 233 | { |
caa45040 | 20:745e8267e7f5 | 234 | |
caa45040 | 20:745e8267e7f5 | 235 | /* USER CODE BEGIN USART2_Init 0 */ |
caa45040 | 20:745e8267e7f5 | 236 | |
caa45040 | 20:745e8267e7f5 | 237 | /* USER CODE END USART2_Init 0 */ |
caa45040 | 20:745e8267e7f5 | 238 | |
caa45040 | 20:745e8267e7f5 | 239 | /* USER CODE BEGIN USART2_Init 1 */ |
caa45040 | 20:745e8267e7f5 | 240 | |
caa45040 | 20:745e8267e7f5 | 241 | /* USER CODE END USART2_Init 1 */ |
caa45040 | 20:745e8267e7f5 | 242 | huart2.Instance = USART2; |
caa45040 | 20:745e8267e7f5 | 243 | huart2.Init.BaudRate = 9600; |
caa45040 | 20:745e8267e7f5 | 244 | huart2.Init.WordLength = UART_WORDLENGTH_8B; |
caa45040 | 20:745e8267e7f5 | 245 | huart2.Init.StopBits = UART_STOPBITS_1; |
caa45040 | 20:745e8267e7f5 | 246 | huart2.Init.Parity = UART_PARITY_NONE; |
caa45040 | 20:745e8267e7f5 | 247 | huart2.Init.Mode = UART_MODE_TX_RX; |
caa45040 | 20:745e8267e7f5 | 248 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
caa45040 | 20:745e8267e7f5 | 249 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; |
caa45040 | 20:745e8267e7f5 | 250 | huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; |
caa45040 | 20:745e8267e7f5 | 251 | huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1; |
caa45040 | 20:745e8267e7f5 | 252 | huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; |
caa45040 | 20:745e8267e7f5 | 253 | if (HAL_HalfDuplex_Init(&huart2) != HAL_OK) |
caa45040 | 20:745e8267e7f5 | 254 | { |
caa45040 | 20:745e8267e7f5 | 255 | Error_Handler(); |
caa45040 | 20:745e8267e7f5 | 256 | } |
caa45040 | 20:745e8267e7f5 | 257 | /* USER CODE BEGIN USART2_Init 2 */ |
caa45040 | 20:745e8267e7f5 | 258 | |
caa45040 | 20:745e8267e7f5 | 259 | /* USER CODE END USART2_Init 2 */ |
caa45040 | 20:745e8267e7f5 | 260 | |
caa45040 | 20:745e8267e7f5 | 261 | } |
caa45040 | 20:745e8267e7f5 | 262 | |
caa45040 | 20:745e8267e7f5 | 263 | /** |
caa45040 | 20:745e8267e7f5 | 264 | * @brief GPIO Initialization Function |
caa45040 | 20:745e8267e7f5 | 265 | * @param None |
caa45040 | 20:745e8267e7f5 | 266 | * @retval None |
caa45040 | 20:745e8267e7f5 | 267 | */ |
caa45040 | 20:745e8267e7f5 | 268 | static void MX_GPIO_Init(void) |
caa45040 | 20:745e8267e7f5 | 269 | { |
caa45040 | 20:745e8267e7f5 | 270 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
caa45040 | 20:745e8267e7f5 | 271 | |
caa45040 | 20:745e8267e7f5 | 272 | /* GPIO Ports Clock Enable */ |
caa45040 | 20:745e8267e7f5 | 273 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
caa45040 | 20:745e8267e7f5 | 274 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
caa45040 | 20:745e8267e7f5 | 275 | |
caa45040 | 20:745e8267e7f5 | 276 | /*Configure GPIO pin Output Level */ |
caa45040 | 20:745e8267e7f5 | 277 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_RESET); |
caa45040 | 20:745e8267e7f5 | 278 | |
caa45040 | 20:745e8267e7f5 | 279 | /*Configure GPIO pin : PB7 */ |
caa45040 | 20:745e8267e7f5 | 280 | GPIO_InitStruct.Pin = GPIO_PIN_7; |
caa45040 | 20:745e8267e7f5 | 281 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
caa45040 | 20:745e8267e7f5 | 282 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
caa45040 | 20:745e8267e7f5 | 283 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
caa45040 | 20:745e8267e7f5 | 284 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
caa45040 | 20:745e8267e7f5 | 285 | |
caa45040 | 20:745e8267e7f5 | 286 | } |
caa45040 | 20:745e8267e7f5 | 287 | |
caa45040 | 20:745e8267e7f5 | 288 | /* USER CODE BEGIN 4 */ |
caa45040 | 20:745e8267e7f5 | 289 | |
caa45040 | 20:745e8267e7f5 | 290 | /* USER CODE END 4 */ |
caa45040 | 20:745e8267e7f5 | 291 | |
caa45040 | 20:745e8267e7f5 | 292 | /** |
caa45040 | 20:745e8267e7f5 | 293 | * @brief This function is executed in case of error occurrence. |
caa45040 | 20:745e8267e7f5 | 294 | * @retval None |
caa45040 | 20:745e8267e7f5 | 295 | */ |
caa45040 | 20:745e8267e7f5 | 296 | void Error_Handler(void) |
caa45040 | 20:745e8267e7f5 | 297 | { |
caa45040 | 20:745e8267e7f5 | 298 | /* USER CODE BEGIN Error_Handler_Debug */ |
caa45040 | 20:745e8267e7f5 | 299 | /* User can add his own implementation to report the HAL error return state */ |
caa45040 | 20:745e8267e7f5 | 300 | __disable_irq(); |
caa45040 | 20:745e8267e7f5 | 301 | while (1) |
caa45040 | 20:745e8267e7f5 | 302 | { |
caa45040 | 20:745e8267e7f5 | 303 | } |
caa45040 | 20:745e8267e7f5 | 304 | /* USER CODE END Error_Handler_Debug */ |
caa45040 | 20:745e8267e7f5 | 305 | } |
caa45040 | 20:745e8267e7f5 | 306 | |
caa45040 | 20:745e8267e7f5 | 307 | #ifdef USE_FULL_ASSERT |
caa45040 | 20:745e8267e7f5 | 308 | /** |
caa45040 | 20:745e8267e7f5 | 309 | * @brief Reports the name of the source file and the source line number |
caa45040 | 20:745e8267e7f5 | 310 | * where the assert_param error has occurred. |
caa45040 | 20:745e8267e7f5 | 311 | * @param file: pointer to the source file name |
caa45040 | 20:745e8267e7f5 | 312 | * @param line: assert_param error line source number |
caa45040 | 20:745e8267e7f5 | 313 | * @retval None |
caa45040 | 20:745e8267e7f5 | 314 | */ |
caa45040 | 20:745e8267e7f5 | 315 | void assert_failed(uint8_t *file, uint32_t line) |
caa45040 | 20:745e8267e7f5 | 316 | { |
caa45040 | 20:745e8267e7f5 | 317 | /* USER CODE BEGIN 6 */ |
caa45040 | 20:745e8267e7f5 | 318 | /* User can add his own implementation to report the file name and line number, |
caa45040 | 20:745e8267e7f5 | 319 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
caa45040 | 20:745e8267e7f5 | 320 | /* USER CODE END 6 */ |
caa45040 | 20:745e8267e7f5 | 321 | } |
caa45040 | 20:745e8267e7f5 | 322 | #endif /* USE_FULL_ASSERT */ |
caa45040 | 20:745e8267e7f5 | 323 | |
caa45040 | 20:745e8267e7f5 | 324 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
caa45040 | 20:745e8267e7f5 | 325 |