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.