AnsweredAssumed Answered

STM32F7 SDCard FR_DISK_ERR Error

Question asked by Ehsan Behravan on May 14, 2017
Latest reply on May 16, 2017 by Ehsan Behravan

Hi there

I waste much time on mounting sdcard in my prgram. the chip is stm32f745vg and i work with Firmware version 1.7 CubMX 4.19 and Keil 5.16

in CubeMX, i choose SDMMC1 in 1-bit mode with clock 48MHz(PLLQ=9) and FatFS --> SD Card. i leave Fatfs Options in Default(no change). other Configurations:

 Flash Interface --> Enable

ART ACCLERATOR --> Enable

Instruction PreFetch -->Enable

CPU ICach --> Enable

CPU DCach --> Enable

GPIO Configuration

SDMMC divide Factor=0

when i try to use f_mount function, i receive FR_DISK_ERR error as result Value.

no difference in Activating SD interrupt. my program is :

 

 

////////////////////////////////////////////////////////////////////////////

SD_HandleTypeDef hsd1;


FRESULT res3,res1,res2;
FATFS SDFatFs;
FIL MyFile;
/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void Error_Handler(void);
static void MX_GPIO_Init(void);
static void MX_SDMMC1_SD_Init(void);

/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/

/* USER CODE END PFP */

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

int main(void)
{
uint32_t byteswritten;
uint8_t wtext[] = "This is STM32 working with FatFs";

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MCU Configuration----------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* Configure the system clock */
SystemClock_Config();

/* Initialize all configured peripherals */
MX_GPIO_Init();
HAL_Delay(200);
HAL_GPIO_WritePin(GPIOD,GPIO_PIN_1,GPIO_PIN_RESET);   ---for activating uSD Power that Connected with trsistor
HAL_Delay(1000);



MX_SDMMC1_SD_Init();

HAL_SD_Init(&hsd1);
HAL_Delay(200);
MX_FATFS_Init();

/* USER CODE BEGIN 2 */
res1=f_mount(&SDFatFs, SD_Path, 1);
if(res1 != FR_OK)
{
/* FatFs Initialization Error */
HAL_GPIO_WritePin(GPIOD,GPIO_PIN_8,GPIO_PIN_SET);
}
else
{
res2=f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE);
if(res2 != FR_OK)
{
HAL_GPIO_WritePin(GPIOD,GPIO_PIN_9,GPIO_PIN_SET);
}
else
{
res3 = f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten);
if((byteswritten == 0) || (res3 != FR_OK))
{
/* 'STM32.TXT' file Write or EOF Error */
HAL_GPIO_WritePin(GPIOD,GPIO_PIN_10,GPIO_PIN_SET);
}
else
{
/*##-6- Close the open text file #################################*/
f_close(&MyFile);

/*##-7- Open the text file object with read access ###############*/

}
}

}

FATFS_UnLinkDriver(SD_Path);
/* USER CODE END 2 */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */

}
/* USER CODE END 3 */

}

 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

my SD Configuration is :

 

static void MX_SDMMC1_SD_Init(void)
{

hsd1.Instance = SDMMC1;
hsd1.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;
hsd1.Init.ClockBypass = SDMMC_CLOCK_BYPASS_DISABLE;
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;

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Please Help me!!!!

thank you

Outcomes