2015-05-29 05:53 PM
This is is very simple project, using stm32f4 discovery and wired microsd socket to read/write data to microsd card.
the code is generated by the stm32f4cubemx.However error occurs at f_open, tracking down it shows FS_DISK_ERR in ff.cPlease help..The code for reading/write is: /* Register the file system object to the FatFs module */ if(f_mount(&SDDISKFatFs, (TCHAR const*)SD_Path, 0) != FR_OK) { /* FatFs Initialization Error */ Error_Handler(); } else { LED_ON(ORANGE,1); /* Create and Open a new text file object with write access */ if(f_open(&MySdFile, ''STM32.TXT'', FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { LED_ON(RED,1); HAL_Delay(2000); LED_ON(RED,0);HAL_Delay(1000); /* 'STM32.TXT' file Open for write Error */ Error_Handler(); } else { LED_ON(BLUE,1); /* Write data to the text file */ res = f_write(&MySdFile, wtext, sizeof(wtext), (void *)&byteswritten); if((byteswritten == 0) || (res != FR_OK)) { /* 'STM32.TXT' file Write or EOF Error */ Error_Handler(); } else { LED_ON(GREEN,1); /* Close the open text file */ f_close(&MySdFile); /* Open the text file object with read access */ if(f_open(&MySdFile, ''STM32.TXT'', FA_READ) != FR_OK) { /* 'STM32.TXT' file Open for read Error */ Error_Handler(); } else { /* Read data from the text file */ res = f_read(&MySdFile, rtext, sizeof(rtext), (void *)&bytesread); if((bytesread == 0) || (res != FR_OK)) { /* 'STM32.TXT' file Read or EOF Error */ Error_Handler(); } else { /* Close the open text file */ f_close(&MySdFile); /* Compare read data with the expected data */ if((bytesread != byteswritten)) { /* Read data is different from the expected data */ Error_Handler(); } else { /* Success of the demo: no error occurrence */// BSP_LED_On(LED4); } } } } } }2015-06-11 04:10 PM
Hi Clivel
Update of the board. I got a board STM32F4DIS-BB fromhttp://www.newark.com/stmicroelectronics/stm32f4dis-bb/expansion-stm32f4-cortex-m4-for/dp/47W1731
Tested the connection. Clearly the error is caused by the connection problem,maybe signal interference . I will move forward to test my own code. Thanks Clivel.2015-06-15 08:35 PM
Hi Clivel,
My code still doesn't go through.The connection is definitely fine because I tested your hex file.The program at problem when loading sector 0 of sd card.I have much experiences on pic but not stm32. I can get the LED blinking but really lost on the uSD.Please give me some advise.Thanks2015-06-16 08:29 AM
I've published projects to the forum, there are a couple in the thread cited earlier.
I'm not sure what your sector 0 issue is, the sector should typically contain the MBR (Master Boot Record), which is nominally some boot code and a partition table.2015-07-02 10:56 PM
Hi Clivel,
With the help of you and burton.mark , I have a better understanding of cubemx. Also I studied the example provided in STM32Cube\Repository\STM32Cube_FW_F4_V1.5.0\Projects\STM324xG_EVAL\Applications\FatFs\FatFs_uSD. Slightly revised project and produced an standalone project. Maybe there is someone with entry level needs the code to start with. Therefore I uploaded it to github (bitbucket) The source code can be downloaded there. Thanks