Skip to main content
JGale
Associate
August 22, 2019
Question

Setting up SDIO for the STM32F103ZC, fatfs FR_DISK_ERR error.

  • August 22, 2019
  • 3 replies
  • 6141 views

I'm trying to transfer my Arduino code to the ST HAL library. I've got everything implemented except for the SD card. After some research I set up FatFS using the SD 4-bit bus. Using PA15 as the detect SDIO pin, which I've both tried to set as a pull_up, pull_down and neither.

Now I'm trying to use the example code to get a sense of how to implement my own code, but I keep getting a FR_DISK_ERR when trying to open anything.

When debugging the f_mount returns that mounting of the card was done successfully (it returns FR_OK), here is the code for that:

#include "fatfs.h"
 
uint8_t retSD; /* Return value for SD */
char SDPath[4]; /* SD logical drive path */
FATFS SDFatFS; /* File system object for SD logical drive */
FIL SDFile; /* File object for SD */
 
/* USER CODE BEGIN Variables */
 
/* USER CODE END Variables */ 
 
void MX_FATFS_Init(void) 
{
 /*## FatFS: Link the SD driver ###########################*/
 retSD = FATFS_LinkDriver(&SD_Driver, SDPath);
 
 /* USER CODE BEGIN Init */
 FRESULT res = f_mount(&SDFatFS, (TCHAR const *) SDPath, 0 );
 if(res != FR_OK){
 Error_Handler();
 }
 
 /* additional user code for init */ 
 /* USER CODE END Init */
}

Then when trying to open directories, it returns a disk error:

 MX_GPIO_Init();
 MX_I2C2_Init();
 MX_SDIO_SD_Init();
 MX_TIM3_Init();
 MX_TIM4_Init();
 MX_USART1_UART_Init();
 MX_FATFS_Init();
 /* USER CODE BEGIN 2 */
 LED DASH_LED_1(DASH_LED_1_GPIO_Port, DASH_LED_1_Pin);
 LED DASH_LED_2(DASH_LED_2_GPIO_Port, DASH_LED_2_Pin);
 LED DASH_LED_3(DASH_LED_3_GPIO_Port, DASH_LED_3_Pin);
 LED DASH_LED_4(DASH_LED_4_GPIO_Port, DASH_LED_4_Pin);
 
 //FATFS FatFs;
 //File object
 FIL fil;
 DIR directory;
 
 FRESULT res =f_opendir(&directory, (const TCHAR *) "0:SD-CARD");
 if(res == FR_OK){
 DASH_LED_1.turnOn();
 if(f_open(&fil, (const TCHAR *)"Test.txt", FA_OPEN_ALWAYS | FA_WRITE) == FR_OK){
 DASH_LED_2.turnOn();
 if(f_putc('S', &fil) == FR_OK){
 DASH_LED_3.turnOn();
 }
 }
 }else if(res == FR_DISK_ERR){
 DASH_LED_3.turnOn();
 } 

I've read some threads on that CubeMX (which I used to initialize a lot of stuff) does not do a good job with SDIO, but I couldn't find out if there were certain functions that I needed to change or overwrite to get it to work.

The cubeMX also created seven other files in my include/source folder that might be useful, I've added them as attachments.

I hope that I gave enough information on my problem, feel free to ask for more files if needed.

This topic has been closed for replies.

3 replies

Tesla DeLorean
Guru
August 22, 2019

Some custom hardware arrangement?

Either the socket or STM32 would want PULL-UP resistors on the DATA and CMD lines. Not on the socket wiring, enable on the STM32 side, or vice versa.

FR_DISK_ERR indicates a failure at the DISKIO layer, and the routines talking to SDIO and Card. Suggests the hardware's not wired/functioning correctly.

You could instrument the SDIO code, you could try porting the SDIO code from one of the EVAL board HAL examples. Personally don't trust CubeMX to generate viable code.

Try using 1-bit mode, rather than 4-bit, see if that works.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
JGale
JGaleAuthor
Associate
August 23, 2019

Thanks for the quick answer, I've changed the mode from 4 bit to 1 bit and most of the things seems to work. Thanks so much.

GBarb.2
Visitor II
July 14, 2020

Hello! I'm somewhat new to all this and I am having a similar issue. Could one of you be a bit more clear on what mode is being discussed, and maybe where to find it?

Tesla DeLorean
Guru
July 15, 2020

Review the Reference Manual Chapter on the SDIO peripheral, RM0008 for the STM32F1 series.

Instrument code so you can understand sequence and failure mode.

Normally it transitions though various states

1-bit 400 KHz (initialization)

1-bit 12 MHz (perhaps 18 or 24 MHz, depends on divider settings)

4-bit 12 MHz

So in cases where the high speed 4-bit mode isn't working you stop at the high speed 1-bit mode.

Usually circuitry and wiring issues

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
GBarb.2
Visitor II
July 15, 2020
I was sort of hoping to piggyback off of this issue, since it is similar but maybe I should start a new thread, since I do have some differences. I am running an stm32f107 and the chapter on USB says that it doesn't apply to the 107s. That RM0008 document is 1134 pages, and as much as I appreciate putting some footwork in to get my answers, that's a bit much and sort of leaves me at square one. Truthfully, I am still a student and this is just beyond my comfort zone. And I would not be in a hurry to do this if I wasn't debugging a firmware that I have already put months of work into. And no, I didn't write the core functionality, I started with a source code repository on Github and modified it. It has inherently has this issue since before I laid my hands on it, but as change things the problem becomes more pronounced. Thank you for the info, I will do what I can to process it. ~Gary Barbour -------- Original message --------From: ST Community Date: 7/14/20 8:25 PM (GMT-05:00) To: gwbarbour821@st.nashcc.edu Subject: clive1 (NFA Crew) answered: Setting up SDIO for the STM32F103ZC, fatfs FR_DISK_ERR error. @media only screen and (max-device-width: 480px) { html { -webkit-text-size-adjust: 100%; } table.container { width: 100% !important; } .hidden-for-mobile { display: none !important; } .callToAction, .callToAction td, .footer { font-size: 12px !important; } .button .text { font-size: 12px !important; } .defaultIndentation { width: 10 !important; } .text { font-size: 12px !important; } a.button { width: 96 !important; } a.buttonWide { width: 118 !important; } a.buttonAuto { padding-left:1em !important; padding-right:1em !important;} a.button, a.buttonWide, a.buttonAuto { height: 23 !important; line-height: 23px !important; border-radius: 4px !important; -webkit-border-radius: 4px !important; -moz-border-radius: 4px !important; } td.buttonWrapper { width: 98 !important; height: 23 !important; } img { display: inline !important; } .circle { border-radius: 50%; clip-path: circle(50px at center); } .square { border-radius: 10%; clip-path: circle(10px at center); } } @media only screen and (min-device-width: 600px) { table.container { width: 600px !important; } } @media screen { @font-face { font-family: 'Salesforce Sans'; font-style: normal; src: local('Salesforce Sans'), local('SalesforceSans'), url(https://community.st.com/fonts/SalesforceSans/SalesforceSans-Regular.woff) format('woff'); } } a, a:visited { color: #015BA7; text-decoration:none; } img { display: block; } .preheader { display: none !important; } table { border-collapse: collapse; mso-table-lspace: 0px; mso-table-rspace: 0px; } Review the Reference Manual Chapter on the SDIO peripheral, RM0008 for the STM32F1 series. Instrument code so you can understand sequence and failure mode.   Normally it transitions though various states 1-bit 400 KHz (initialization) 1-bit 12 MHz (perhaps 18 or 24 MHz, depends on divider settings) 4-bit 12 MHz   So in cases where the high speed 4-bit mode isn't working you stop at the high speed 1-bit mode. Usually circuitry and wiring issues             clive1 (NFA Crew) (Community Member) Review the Reference Manual Chapter on the SDIO peripheral, RM0008 for the STM32F1 series.Instrument code so you can understand sequence and failure mode. Normally it transitions though various states1-bit 400 KHz (initialization)1-bit 12 MHz (perhaps 18 or 24 MHz, depends on divider settings)4-bit 12 MHz So in cases where the high speed 4-bit mode isn't working you stop at the high speed 1-bit mode.Usually circuitry and wiring issues   View/Answer   or reply to this email             Replying to   Setting up SDIO for the STM32F103ZC, fatfs FR_DISK_ERR error.       GBarb.2 (Community Member) Tuesday, July 14, 2020 3:18 PM Hello! I'm somewhat new to all this and I am having a similar issue. Could one of you be a bit more clear on what mode is being discussed, and maybe where to find it?               clive1 (NFA Crew) (Community Member) Review the Reference Manual Chapter on the SDIO peripheral, RM0008 for the STM32F1 series.Instrument code so you can understand sequence and failure mode. Normally it transitions though various states1-bit 400 KHz (initialization)1-bit 12 MHz (perhaps 18 or 24 MHz, depends on divider settings)4-bit 12 MHz So in cases where the high speed 4-bit mode isn't working you stop at the high speed 1-bit mode.Usually circuitry and wiring issues Tuesday, July 14, 2020 5:25 PM               You're receiving emails when someone "Comments after me."   To change or turn off ST Community email, log in as gwbarbour821@st.nashcc.edu.st.   Are notifications about this post getting annoying? Reply to this email with the word " mute ".   STMicroelectronics N.V.