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-05-08 06:36 AM
Thanks everybody, my problem is solved !
In fact, I didn't use the right ccsbcs.c fileNow I use the one from FatFs site and everything seems working, I can write in lowercase !