cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F7 SDCard FR_DISK_ERR Error

Ehsan Behravan
Associate II
Posted on May 14, 2017 at 09:03

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

5 REPLIES 5
Posted on May 14, 2017 at 20:04

Should your function call HAL_SD_Init(&hsd1, &SDCardInfo1); ?

Looking at the FatFs level isn't going to shine much light on failing layers below that.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 15, 2017 at 17:03

the function HAL_SD_Init has just one input parameter. i think SDCardInfoTypeDef type has been omitted in Firmware version 1.6 and 1.7 .

Posted on May 16, 2017 at 02:12

Dear Ehsan Behravan.

Why not try reference board like STM32F746-Disco?

AFAIK,Many problems lies on D.I.Y. hardware(lack of pullups,weakness powerlines....).
Posted on May 16, 2017 at 06:14

Thanks for your reply.

my board is a custom board and i have not  authority to change it to a Disco-Board.

I've Designed SD Circuit from ST example Boards. only difference is a transistor for selecting the power of sd card. it means i should RESET a GPIO to connect sd power. i will attach the circuit.

0690X0000060715QAA.png

every yellow ports in the figure, is connected to MCU directly. 

Ehsan Behravan
Associate II
Posted on May 16, 2017 at 08:49

it worked. there is a problem in hardware level. I omitted the transistor(BCX53) and connected VDD_MCU to VDD_uSD directly. everthink is OK.In fact the transistor has decreased voltage level. so VDD was lower than Vdd High.

Thanks everyone for your answer.