2018-06-16 11:44 PM
Environment:
STM32469I-EVAL Windows 10 x64 STM32CubeMX v. 4.25.0 STM32Cube FW_F4 V1.21.0 System Workbench for STM32 Version: 1.15.0.201708311556 SD card inserted, code sample Projects\STM32469I_EVAL\Applications\FatFs\FatFs_uSD_RTOS is working. Steps to reproduce the problem: CubeMX, create new STM32469I-EVAL project. Pinout. SDIO: SD 1 bit SYS, Timebase Source: TIM1 FATFS: SD card FreeRTOS: enabled Configuration. FREERTOS, default task stack size 1024 Generate SW4STM32 source code in CubeMX. Open generated project in STM32 Workbench and make the following changes in the code: void _Error_Handler(char *file, int line) { /* USER CODE BEGIN Error_Handler_Debug */ HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET); while(1) { } /* USER CODE END Error_Handler_Debug */ } void StartDefaultTask(void const * argument) { /* init code for FATFS */ MX_FATFS_Init(); /* USER CODE BEGIN 5 */ // Turn off all LEDs HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(LED4_GPIO_Port, LED4_Pin, GPIO_PIN_SET); // Check result of MX_FATFS_Init if (retSD != 0) { _Error_Handler(__FILE__, __LINE__); } FRESULT fresult; FATFS SDFatFs; fresult = f_mount(&SDFatFs, (TCHAR const*)SDPath, 1); // runs several seconds, returns 3 // Checked in the debugger: // resSD = 0, SDPATH = '0:/', fresut = 3 (FR_NOT_READY) if( fresult != FR_OK ) { _Error_Handler(__FILE__, __LINE__); } HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET); for(;;) { osDelay(1); } /* USER CODE END 5 */ }f_mount returns FR_NOT_READY. The same code was working in one of previous STM32CubeMX and firmware package versions. ioc project and main.c files are attached.#fatfs #sdcard #sdio #stm32469i-eval2018-06-17 02:51 AM
Make sure the stack is big enough, and that the local/auto allocation is cleared
FATFS SDFatFs = {0};
Sorry, don't have a personal interest in debugging broken CubeMX output.
Your options here are to instrument the DISKIO and SDIO layers, and make sure the IRQ handlers are named and function properly.
2018-06-17 05:24 AM
Thanks. Increasing the stack size to 2048 and initializing
SDFatFs
to 0 didn't help, still the same result.2018-06-18 02:51 AM
After some investigation I found two functions in sd_diskio.c: BSP_SD_WriteCpltCallback and BSP_SD_ReadCpltCallback. They are never called, so all SD card calls fail with timeout. Solution: add the following code to the end of sd_diskio.c
/* USER CODE BEGIN lastSection */
void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd)
{
osMessagePut(SDQueueID, READ_CPLT_MSG, osWaitForever);}void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd)
{ osMessagePut(SDQueueID, WRITE_CPLT_MSG, osWaitForever);}/* USER CODE END lastSection */This solution may be applied to CubeMX version 4.25.0, firmware package V1.21.0.
CubeMX, SDIO: global interrupt enabled, RX and TX channels are added to DMA.
Update: Installed CubeMX 4.26.0, finally no bugs in SD card support, so all tricks from this and may other posts are not needed.
2019-01-11 02:41 AM
Hello,
I get nearly the same problem with SD card - f_mount() returns FR_NOT_READY.
I created new project using Nucleo f401re with external card slot. The D0..D3 data lines and CMD line are pull-uped internally, clock for SD is 24MHz, DMA enabled, IRQ enabled, no RTOS.
The trick from above does not resolve the issue, any ideas? I also followed the tutorial: http://mkwsolutions.com/Blog/STM32F4_SDIO still without success.
Software: CubeMX version 5.0.1 (freshest), Atollic TrueStudio vestion 9.2.0 (freshest).
Best,
Adam
2019-01-11 07:04 AM
Should probably trace back to where the not ready is coming from. Check if it expects a Card Detect signal to be connected to the socket.
Review socket and wiring.
Validate HW with known working SW.
Instrument SW to understand what it is doing, and how it is failing.
2019-07-12 02:32 PM
Same problem with CUBEMX 5.1.0. The failure is occuring trying to read the boot sector. Perhaps there is no boot sector on the sd card? I don't know how to inspect the format of the drive. I formatted it on Win 10 as exFAT.
2019-11-14 12:00 AM
look at this topic https://community.st.com/s/question/0D50X00009XkWceSAF/stm32f411re-stm32cube-fatfs-sdio-sdcard-always-returns-frdiskerr?t=1573717870396
Changing pins to pull-up works for me
2020-08-06 08:39 AM
Could you find our why reading the boot sector fails?
I have the exact same problem. Everything is fine until reading the boot sector fails.