/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file sdmmc.c * @brief This file provides code for the configuration * of the SDMMC instances. ****************************************************************************** * @attention * * Copyright (c) 2025 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "sdmmc.h" /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ MMC_HandleTypeDef hmmc2; /* SDMMC2 init function */ void MX_SDMMC2_MMC_Init(void) { /* USER CODE BEGIN SDMMC2_Init 0 */ /* USER CODE END SDMMC2_Init 0 */ /* USER CODE BEGIN SDMMC2_Init 1 */ /* USER CODE END SDMMC2_Init 1 */ hmmc2.Instance = SDMMC2; hmmc2.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING; hmmc2.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE; hmmc2.Init.BusWide = SDMMC_BUS_WIDE_4B; hmmc2.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE; hmmc2.Init.ClockDiv = 0; if (HAL_MMC_Init(&hmmc2) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN SDMMC2_Init 2 */ /* USER CODE END SDMMC2_Init 2 */ } void HAL_MMC_MspInit(MMC_HandleTypeDef* mmcHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; if(mmcHandle->Instance==SDMMC2) { /* USER CODE BEGIN SDMMC2_MspInit 0 */ /* USER CODE END SDMMC2_MspInit 0 */ /** Initializes the peripherals clock */ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SDMMC; PeriphClkInitStruct.SdmmcClockSelection = RCC_SDMMCCLKSOURCE_PLL; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { Error_Handler(); } /* SDMMC2 clock enable */ __HAL_RCC_SDMMC2_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); /**SDMMC2 GPIO Configuration PB4 (NJTRST) ------> SDMMC2_D3 PB3 (JTDO/TRACESWO) ------> SDMMC2_D2 PD7 ------> SDMMC2_CMD PD6 ------> SDMMC2_CK PB14 ------> SDMMC2_D0 PB15 ------> SDMMC2_D1 */ GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_3|GPIO_PIN_14|GPIO_PIN_15; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF9_SDIO2; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_6; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF11_SDIO2; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); /* USER CODE BEGIN SDMMC2_MspInit 1 */ /* USER CODE END SDMMC2_MspInit 1 */ } } void HAL_MMC_MspDeInit(MMC_HandleTypeDef* mmcHandle) { if(mmcHandle->Instance==SDMMC2) { /* USER CODE BEGIN SDMMC2_MspDeInit 0 */ /* USER CODE END SDMMC2_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_SDMMC2_CLK_DISABLE(); /**SDMMC2 GPIO Configuration PB4 (NJTRST) ------> SDMMC2_D3 PB3 (JTDO/TRACESWO) ------> SDMMC2_D2 PD7 ------> SDMMC2_CMD PD6 ------> SDMMC2_CK PB14 ------> SDMMC2_D0 PB15 ------> SDMMC2_D1 */ HAL_GPIO_DeInit(GPIOB, GPIO_PIN_4|GPIO_PIN_3|GPIO_PIN_14|GPIO_PIN_15); HAL_GPIO_DeInit(GPIOD, GPIO_PIN_7|GPIO_PIN_6); /* USER CODE BEGIN SDMMC2_MspDeInit 1 */ /* USER CODE END SDMMC2_MspDeInit 1 */ } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */