2021-04-01 10:48 PM
I'm trying to use FATFS on NUCLEO-F401RE to write a file into the SD Card.
I generated the project into cube MX and added thi code before the while(1) loop:
/* USER CODE BEGIN 2 */
temp = f_mount(&StrutturaCtrFS,"",1);
if(FR_OK != temp){
while(1);
}
temp = f_open(&File_CFG,"Cfg.ini", FA_READ | FA_WRITE | FA_CREATE_ALWAYS);
if(FR_OK != temp){
while(1);
}
temp = f_write(&File_CFG, "CIAO",4,0);
if(FR_OK != temp){
while(1);
}
f_close(&File_CFG);
/* USER CODE END 2 */
it stops in F_wirte instruction. With debugger I founded that the error is a HAL_SD_ERROR_TX_UNDERRUN in HAL_SD_WriteBlocks (line 782 in stm32f4xx_hal_sd.c).
Attached there is my .ioc file
The SD is connected as this:
MISO -> PC8 (SDIO_DO)
MOSI -> PD2 (SDIO_CMD)
CLK -> PC12 (SDIO_SK)
CS -> PC3 ( GPIO OUTPUT HIGH)
also (because my SD card slot doesn't have a SD_presence pin) I put PC9 of FATFS to GND.
What's wrong in this project ?
Thanks to all.
2021-04-04 02:10 AM
Hi to all,
After triple checked all (configuration and connection) I found the mistake.
The clock is too fast!
With oscilloscope on PC12 I see that the clock was not a square wave:
So I changed "SDIOCLK clock divide factor" in CubeMX from 0 to 32. Now the clock is ok:
and the file was successfully written into SD card.
this limitation on clock is due to the NUCLEO-board or my SD CARD/slot ?
I have a 10k pullup resistor on MISO, MOSI and SCK, but as I can see from the wave form is not a pull-up issue.
Attached there is new .ioc file
Thanks to all.
AB