2014-04-16 03:36 AM
Hello,
I use a STM32F427 running with FreeRTOS. I try to create a file on my SD card, through SDIO, thestm32f4_discovery_sdio_sd.c (DMA mode). I also use the librairyFatFs R0.09, ported by Clive I think :)This is my code to write a file:
FRESULT res;
FILINFO fno;
FIL fil;
DIR dir;
FATFS fs32;
UINT bw; /* File write count */
char* path;
char *fn; /* This function is assuming non-Unicode cfg. */
#if _USE_LFN
static char lfn[_MAX_LFN + 1];
fno.lfname = lfn;
fno.lfsize = sizeof lfn;
#endif
void
testsdcard(
void
)
{
// SDCard mount
memset(&fs32, 0,
sizeof
(FATFS));
res = f_mount(0, &fs32);
memset(&fil, 0, sizeof(FIL));
res = f_open(&fil,
''NEW.TXT''
, FA_CREATE_ALWAYS | FA_WRITE);
res = f_write(&fil,
''hello YOU''
,
sizeof
(
''hello YOU''
) , &bw);
f_close(&fil);
}
Of course before I configured the NVIC:
int
init_NVIC_sdio(
void
)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
// SDIO Interrupt ENABLE
NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 6;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
The behavior seems random. - sometimes it works, all of the ''res'' returns are OK and the file is created on the SD card - sometimesf_open returns ''FR_NOT_READY'' andf_write returns ''FR_INVALID_OBJECT'' Do you have any idea ? It's hard to debug because of the random behavior... Thanks !!2014-04-16 04:40 AM
Hi
'' I also use the librairy FatFs R0.09, ported by Clive I think'' This makes life difficult (unless you have the reference manual/documentation for that version). According to the WEB site : http://elm-chan.org/fsw/ff/00index_e.html Both the mount and the f_open command need the drive as par of the path. (but that is for the current version of fatfs)2014-04-16 05:38 AM
Do you have any idea ? It's hard to debug because of the random behavior...
Instrumentation. Add debug output to the code path's involved in fails, and perhaps add test code (open/close file in a loop to provoke the problem). If necessary, drill down to the lower-level functions, until the fail-generating code is found.
2014-04-16 08:12 AM
Make sure you start with the most current port, writing tends to be more problematic and involves the SDIO FIFO. Probably want both the SDIO and DMA interrupts.
This is the STM32F4-DISCO + STM32F4-DIS-BB implementation using the then current F4 SDIO code.https://drive.google.com/file/d/0B7OY5pub_GfIY01DaHY4OVp4NUk/edit?usp=sharing
2014-05-06 02:41 AM
Thanks everybody ! I find a new STM32F4 SDIO driver for my project, it's very easy to implement : the stm32_ub_fatfs
http://www.coocox.org/driver_comp/fatfs_sd-for-stf4-c1670.html?mc=3&sc=132014-05-06 07:02 AM
I have two other questions:
- Do you know how I can create files in lowercase ? - Why the maximum file or directory name length is 8 characters ?Thanks !2014-05-06 07:30 AM
Hi
''- Do you know how I can create files in lowercase ? - Why the maximum file or directory name length is 8 characters ?'' Sound like FatFS is accessing the device in Fat16 mode. These are limitations of old Fat16 (related to pre-Windows days of filing system).2014-05-06 09:31 AM
Yes but this is strange, my SD card is FAT32 formatted.
Moreover, FatFs see my card as FAT32 (I can see it in the ff.c lib, the code passes through the ''case FS_FAT32'' and not through the ''case FS_FAT16''2014-05-06 10:09 AM
Hi
There may be other compiler directive in FatFS It is all to do with 'Long Filenames' : http://stackoverflow.com/questions/14123302/fat32-set-long-filename-and-8-3-filename-separately Check if FatFS has separate functions (create and write) for long file name.2014-05-06 10:19 AM
Got nothing to do with FAT16/FAT32