133 lines
3.7 KiB
C
133 lines
3.7 KiB
C
/**
|
|
******************************************************************************
|
|
* File Name : SDMMC.c
|
|
* Description : This file provides code for the configuration
|
|
* of the SDMMC instances.
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
|
* All rights reserved.</center></h2>
|
|
*
|
|
* This software component is licensed by ST under BSD 3-Clause license,
|
|
* the "License"; You may not use this file except in compliance with the
|
|
* License. You may obtain a copy of the License at:
|
|
* opensource.org/licenses/BSD-3-Clause
|
|
*
|
|
******************************************************************************
|
|
*/
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "sdmmc.h"
|
|
|
|
/* USER CODE BEGIN 0 */
|
|
|
|
/* USER CODE END 0 */
|
|
|
|
SD_HandleTypeDef hsd1;
|
|
|
|
/* SDMMC1 init function */
|
|
|
|
void MX_SDMMC1_SD_Init(void)
|
|
{
|
|
|
|
hsd1.Instance = SDMMC1;
|
|
hsd1.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;
|
|
hsd1.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;
|
|
hsd1.Init.BusWide = SDMMC_BUS_WIDE_1B;
|
|
hsd1.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;
|
|
hsd1.Init.ClockDiv = 0;
|
|
hsd1.Init.TranceiverPresent = SDMMC_TRANSCEIVER_NOT_PRESENT;
|
|
if (HAL_SD_Init(&hsd1) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
}
|
|
|
|
void HAL_SD_MspInit(SD_HandleTypeDef* sdHandle)
|
|
{
|
|
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
|
if(sdHandle->Instance==SDMMC1)
|
|
{
|
|
/* USER CODE BEGIN SDMMC1_MspInit 0 */
|
|
|
|
/* USER CODE END SDMMC1_MspInit 0 */
|
|
/** Initializes the peripherals clock
|
|
*/
|
|
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_SDMMC1;
|
|
PeriphClkInit.Sdmmc1ClockSelection = RCC_SDMMC1CLKSOURCE_PLLP;
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/* SDMMC1 clock enable */
|
|
__HAL_RCC_SDMMC1_CLK_ENABLE();
|
|
|
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
/**SDMMC1 GPIO Configuration
|
|
PC8 ------> SDMMC1_D0
|
|
PC12 ------> SDMMC1_CK
|
|
PD2 ------> SDMMC1_CMD
|
|
*/
|
|
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_12;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
GPIO_InitStruct.Alternate = GPIO_AF12_SDMMC1;
|
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_2;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
GPIO_InitStruct.Alternate = GPIO_AF12_SDMMC1;
|
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
|
|
/* SDMMC1 interrupt Init */
|
|
HAL_NVIC_SetPriority(SDMMC1_IRQn, 0, 0);
|
|
HAL_NVIC_EnableIRQ(SDMMC1_IRQn);
|
|
/* USER CODE BEGIN SDMMC1_MspInit 1 */
|
|
|
|
/* USER CODE END SDMMC1_MspInit 1 */
|
|
}
|
|
}
|
|
|
|
void HAL_SD_MspDeInit(SD_HandleTypeDef* sdHandle)
|
|
{
|
|
|
|
if(sdHandle->Instance==SDMMC1)
|
|
{
|
|
/* USER CODE BEGIN SDMMC1_MspDeInit 0 */
|
|
|
|
/* USER CODE END SDMMC1_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
__HAL_RCC_SDMMC1_CLK_DISABLE();
|
|
|
|
/**SDMMC1 GPIO Configuration
|
|
PC8 ------> SDMMC1_D0
|
|
PC12 ------> SDMMC1_CK
|
|
PD2 ------> SDMMC1_CMD
|
|
*/
|
|
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_8|GPIO_PIN_12);
|
|
|
|
HAL_GPIO_DeInit(GPIOD, GPIO_PIN_2);
|
|
|
|
/* SDMMC1 interrupt Deinit */
|
|
HAL_NVIC_DisableIRQ(SDMMC1_IRQn);
|
|
/* USER CODE BEGIN SDMMC1_MspDeInit 1 */
|
|
|
|
/* USER CODE END SDMMC1_MspDeInit 1 */
|
|
}
|
|
}
|
|
|
|
/* USER CODE BEGIN 1 */
|
|
|
|
/* USER CODE END 1 */
|
|
|
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|