cancel
Showing results for 
Search instead for 
Did you mean: 

SD can't read write

psalian
Associate II
Posted on October 28, 2016 at 10:48

Hey guys I am trying to interface sd card with stm32F4 but things are not working,code was developed using cubemx

int main(void)
{

/* 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();
MX_SDIO_SD_Init();
MX_FATFS_Init();
HAL_Delay(1000);
/* USER CODE BEGIN 2 */
if(f_mount(&mynewdiskFatFs,(const TCHAR*)SD_Path, 0) == FR_OK)
{
if(f_open(&MyFile, ''abc.txt'', FA_READ ) == FR_OK)
{
// GPIO_SetBits(GPIOD, GPIO_Pin_15);
if(f_read(&MyFile, wtext, sizeof(wtext), (void *)&wbytes) ==FR_OK);
{
f_close(&MyFile);
}
}
}
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}

1]Interface is sdio 1 bit mode(due to pin constraints) 2]Sd card 8Gb formated with default allocation size Steps taken to debug: I single step through the code fmount is successful but when i step through fopen there a error code atfind_volume() returningFR_NOT_READY. Hardware conections :I have arduino micro sd breakout board with SPI pins so connection are DI---SDIO_CMD DO---SDIO_D0 SCLK---SDIO_SCLK #stm32f4-discovery-sd-card
5 REPLIES 5
Posted on October 29, 2016 at 17:56

There seem to be a long parade of people with problem with Cube/HAL and SD cards via SDIO/SPI

You'd want to debug the SD card side of thing below FatFs, if the routines to read/write sectors in diskio.c don't function properly any abstraction layered on top isn't going to work and it is going to be harder to debug. Debug the read/write functions at a sector level.

Is the a Card Detect pin here? Is the IO code timing out?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
psalian
Associate II
Posted on October 31, 2016 at 19:12

Hi clive,there is no Sd card detect pin as such.For IO code timing  out I havent check that out.How is it possible to debug SD card without filesystem like if I write a block on sd card how do I check if it has indeed been written like can you check hex values written on the Sd card 

Posted on October 31, 2016 at 19:41

It is just blocks of data, you should be able to read back the same patterns as you wrote. You should be able to read random blocks across the whole media.

I'd start by reading blocks/sectors to confirm that worked before moving on to writing, as that tends to be more destructive, by nature.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
psalian
Associate II
Posted on November 01, 2016 at 16:52

errorstate = SD_CmdResp1Error(hsd, SD_CMD_SET_BLOCKLEN);

Hey clive you were rightHAL_SD_ReadBlocks returns with SD_CMD_RSP_TIMEOUT error due to the above code statement but good news is the SD initialization works all fine I could read SD card capacity,block size,card type etc I have attached the screenshot of values so hardware isn't a problem I guess.I tried 3 different Sd card but with same results.

________________

Attachments :

Screenshot__48_.png : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzUC&d=%2Fa%2F0X0000000bMY%2Fbdz1hq0aekZUmHGLRgF3DtA..bfpjR3DgBoVqQycu6s&asPdf=false
psalian
Associate II
Posted on November 02, 2016 at 20:19

Hey clive,I also tried enabling the DMA still can't get rid of response timout error quite puzzled as initialization is done without problem just can't read blocks