1 /** 2 ****************************************************************************** 3 * File Name : gpio.c 4 * Description : This file provides code for the configuration 5 * of all used GPIO pins. 6 ****************************************************************************** 7 * @attention 8 * 9 * <h2><center>© Copyright (c) 2019 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 20 /* Includes ------------------------------------------------------------------*/ 21 #include "gpio.h" 22 /* USER CODE BEGIN 0 */ 23 24 /* USER CODE END 0 */ 25 26 /*----------------------------------------------------------------------------*/ 27 /* Configure GPIO */ 28 /*----------------------------------------------------------------------------*/ 29 /* USER CODE BEGIN 1 */ 30 31 /* USER CODE END 1 */ 32 33 /** Configure pins as 34 * Analog 35 * Input 36 * Output 37 * EVENT_OUT 38 * EXTI 39 PC3 ------> I2S2_SD 40 PA4 ------> I2S3_WS 41 PA5 ------> SPI1_SCK 42 PA6 ------> SPI1_MISO 43 PA7 ------> SPI1_MOSI 44 PB10 ------> I2S2_CK 45 PC7 ------> I2S3_MCK 46 PA9 ------> USB_OTG_FS_VBUS 47 PA10 ------> USB_OTG_FS_ID 48 PA11 ------> USB_OTG_FS_DM 49 PA12 ------> USB_OTG_FS_DP 50 PC10 ------> I2S3_CK 51 PC12 ------> I2S3_SD 52 PB6 ------> I2C1_SCL 53 PB9 ------> I2C1_SDA 54 */ 55 void MX_GPIO_Init(void) 56 { 57 58 GPIO_InitTypeDef GPIO_InitStruct = {0}; 59 60 /* GPIO Ports Clock Enable */ 61 __HAL_RCC_GPIOE_CLK_ENABLE(); 62 __HAL_RCC_GPIOC_CLK_ENABLE(); 63 __HAL_RCC_GPIOH_CLK_ENABLE(); 64 __HAL_RCC_GPIOA_CLK_ENABLE(); 65 __HAL_RCC_GPIOB_CLK_ENABLE(); 66 __HAL_RCC_GPIOD_CLK_ENABLE(); 67 68 /*Configure GPIO pin Output Level */ 69 HAL_GPIO_WritePin(GPIOE, CS_I2C_SPI_Pin|CC_nSHUTD_Pin, GPIO_PIN_RESET); 70 71 /*Configure GPIO pin Output Level */ 72 HAL_GPIO_WritePin(OTG_FS_PowerSwitchOn_GPIO_Port, OTG_FS_PowerSwitchOn_Pin, GPIO_PIN_RESET); 73 74 /*Configure GPIO pin Output Level */ 75 HAL_GPIO_WritePin(GPIOD, LD3_Pin|LD5_Pin|LD6_Pin|Audio_RST_Pin, GPIO_PIN_RESET); 76 77 /*Configure GPIO pins : PEPin PEPin */ 78 GPIO_InitStruct.Pin = CS_I2C_SPI_Pin|CC_nSHUTD_Pin; 79 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 80 GPIO_InitStruct.Pull = GPIO_NOPULL; 81 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 82 HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); 83 84 /*Configure GPIO pin : PtPin */ 85 GPIO_InitStruct.Pin = OTG_FS_PowerSwitchOn_Pin; 86 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 87 GPIO_InitStruct.Pull = GPIO_NOPULL; 88 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 89 HAL_GPIO_Init(OTG_FS_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct); 90 91 /*Configure GPIO pin : PtPin */ 92 GPIO_InitStruct.Pin = PDM_OUT_Pin; 93 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 94 GPIO_InitStruct.Pull = GPIO_NOPULL; 95 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 96 GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; 97 HAL_GPIO_Init(PDM_OUT_GPIO_Port, &GPIO_InitStruct); 98 99 /*Configure GPIO pin : PtPin */ 100 GPIO_InitStruct.Pin = B1_Pin; 101 GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING; 102 GPIO_InitStruct.Pull = GPIO_NOPULL; 103 HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct); 104 105 /*Configure GPIO pin : PtPin */ 106 GPIO_InitStruct.Pin = I2S3_WS_Pin; 107 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 108 GPIO_InitStruct.Pull = GPIO_NOPULL; 109 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 110 GPIO_InitStruct.Alternate = GPIO_AF6_SPI3; 111 HAL_GPIO_Init(I2S3_WS_GPIO_Port, &GPIO_InitStruct); 112 113 /*Configure GPIO pins : PAPin PAPin PAPin */ 114 GPIO_InitStruct.Pin = SPI1_SCK_Pin|SPI1_MISO_Pin|SPI1_MOSI_Pin; 115 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 116 GPIO_InitStruct.Pull = GPIO_NOPULL; 117 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 118 GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; 119 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 120 121 /*Configure GPIO pin : PtPin */ 122 GPIO_InitStruct.Pin = BOOT1_Pin; 123 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 124 GPIO_InitStruct.Pull = GPIO_NOPULL; 125 HAL_GPIO_Init(BOOT1_GPIO_Port, &GPIO_InitStruct); 126 127 /*Configure GPIO pin : PtPin */ 128 GPIO_InitStruct.Pin = CLK_IN_Pin; 129 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 130 GPIO_InitStruct.Pull = GPIO_NOPULL; 131 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 132 GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; 133 HAL_GPIO_Init(CLK_IN_GPIO_Port, &GPIO_InitStruct); 134 135 /*Configure GPIO pins : PDPin PDPin PDPin PDPin */ 136 GPIO_InitStruct.Pin = LD3_Pin|LD5_Pin|LD6_Pin|Audio_RST_Pin; 137 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 138 GPIO_InitStruct.Pull = GPIO_NOPULL; 139 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 140 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); 141 142 /*Configure GPIO pins : PCPin PCPin PCPin */ 143 GPIO_InitStruct.Pin = I2S3_MCK_Pin|I2S3_SCK_Pin|I2S3_SD_Pin; 144 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 145 GPIO_InitStruct.Pull = GPIO_NOPULL; 146 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 147 GPIO_InitStruct.Alternate = GPIO_AF6_SPI3; 148 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); 149 150 /*Configure GPIO pin : PtPin */ 151 GPIO_InitStruct.Pin = VBUS_FS_Pin; 152 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 153 GPIO_InitStruct.Pull = GPIO_NOPULL; 154 HAL_GPIO_Init(VBUS_FS_GPIO_Port, &GPIO_InitStruct); 155 156 /*Configure GPIO pins : PAPin PAPin PAPin */ 157 GPIO_InitStruct.Pin = OTG_FS_ID_Pin|OTG_FS_DM_Pin|OTG_FS_DP_Pin; 158 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 159 GPIO_InitStruct.Pull = GPIO_NOPULL; 160 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 161 GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; 162 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 163 164 /*Configure GPIO pin : PtPin */ 165 GPIO_InitStruct.Pin = OTG_FS_OverCurrent_Pin; 166 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 167 GPIO_InitStruct.Pull = GPIO_NOPULL; 168 HAL_GPIO_Init(OTG_FS_OverCurrent_GPIO_Port, &GPIO_InitStruct); 169 170 /*Configure GPIO pins : PBPin PBPin */ 171 GPIO_InitStruct.Pin = Audio_SCL_Pin|Audio_SDA_Pin; 172 GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; 173 GPIO_InitStruct.Pull = GPIO_PULLUP; 174 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 175 GPIO_InitStruct.Alternate = GPIO_AF4_I2C1; 176 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 177 178 /*Configure GPIO pin : PtPin */ 179 GPIO_InitStruct.Pin = MEMS_INT2_Pin; 180 GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING; 181 GPIO_InitStruct.Pull = GPIO_NOPULL; 182 HAL_GPIO_Init(MEMS_INT2_GPIO_Port, &GPIO_InitStruct); 183 184 } 185 186 /* USER CODE BEGIN 2 */ 187 188 /* USER CODE END 2 */ 189 190 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 191