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-07 12:01 AM
My fatfs version R0.10a work with long file names and upper/lower case
tIn the ff.c haeder comment :/ Nov 03,'09 R0.07e Separated out configuration options from ff.h to ffconf.h.
/ Fixed f_unlink() fails to remove a sub-directory on _FS_RPATH.
/ Fixed name matching error on the 13 character boundary.
/ Added a configuration option, _LFN_UNICODE.
/ Changed f_readdir() to return the SFN with always upper case on non-LFN cfg.
Configure the _USE_LFN define in ffconf.h file
2014-05-07 06:46 AM
Thanks. I'm not sure to understand this _LFN_UNICODE and _USE_LFN.
In my code:_LFN_UNICODE = 0 (0
=ANSI/OEM
and1
=Unicode
)_USE_LFN = 0 (0
=Disable LFN feature. _MAX_LFN and _LFN_UNICODE have no effect.
1= Enable LFN)Is it the same for you ?Thanks a lot !2014-05-07 06:53 AM
If I configure_USE_LFN to =1 I need ff_convert() and ff_wtoupper() functions:
// The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes. To enable LFN,
// Unicode handling functions ff_convert() and ff_wtoupper() must be added
// to the project. When enable to use heap, memory control functions
// ff_memalloc() and ff_memfree() must be added to the project. */
But I'm unable to find these functions in my project. What I have to do ?
2014-05-07 07:15 AM
I'm sorry jean but
I have
alzheimer
....I totally forgot
You must include
the file
in the directory
option
according to the
chosen
code page
(Which
is always located
in the file
ffconf.h
) My project work with _CODE_PAGE 1252 and include ccsbcs.c from option directorySorry again
I hope
I've given you
all the details
I have added my ffconf.h see attachment ________________ Attachments : ffconf.h : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I14B&d=%2Fa%2F0X0000000bhh%2F7EY_H7YLydopDRRIZamrBZP0iLJBg0WY8pC0RTkP9_o&asPdf=false2014-05-07 07:20 AM
Hi
LFN = Long File Names. ''If I configure _USE_LFN to =1 I need ff_convert() and ff_wtoupper() functions:'' See : http://elm-chan.org/fsw/ff/en/appnote.html So the convert function does some of the convertion functions from wchar.h http://www.cplusplus.com/reference/cwchar/2014-05-07 08:04 AM
Hi Francescato,
Thanks for this comment. I try to put the ccsbcs.c file in my project, but it seems i also need to importpgmspace.h and maybe others...
This is a lot of functions and new libs just to write in lowercase and >8 characters isn't it ?Do you think there is a proper way ? thanks !2014-05-07 10:56 PM
Jean
I'm not sure
that
is the right way
I
just
described
what
I did to
use long names
I'm not
a
FATFS
expertbut I'm sure
, as thecomment
inffconf.h
,_USE_LFN
must be
!=
0 to enable
long file name
I do not know
the file
pgmspace.h
I tried
and
I have found only
references to
Arduino/Atmel AVR
.What
compiler
do you use?
I work with
IAR
and the file
is not part
of my project
.2014-05-08 03:12 AM
I use Coocox,
pgmspace.h is also not a part of my project.
I understand that I need_USE_LFN
> 0 to enable long file name and lowercase, and thus I need ff_convert() and ff_wtoupper() functions which are not included in my project.Do you use these two functions ?Thanks a lot !2014-05-08 03:28 AM
Chan's app note :
http://elm-chan.org/fsw/ff/en/appnote.html ''To enable LFN feature, set _USE_LFN to 1, 2 or 3, and add a Unicode code conversion function ff_convert() and ff_wtoupper() to the project.'' I doubt any environment provides ff_convert() and ff_wtoupper() - these are specific to FatFS BUT they can be just wrappers around other functions that may already exist!2014-05-08 04:31 AM
In my project
I've also included
the
ccsbcs.c
file
(attached)
It contains some
code tables
and
the definition of
WCHAR
ff_convert
(/ *
Convert
character
, it returnszero
in case of error
*
/
WCHAR
chr
, / *Character code
to be converted
*
/
UINT
dir /
*
0:
Unicode
OEMCP
, 1:OEMCP
to Unicode
*
/
)
WCHAR
ff_wtoupper
(/ *
High
converting the
character
*
/
WCHAR
chr
/ *
character
input
*
/
)
ccsbcs.c
is part of
FATFS
.zip
(directory
src.option
) downloaded from FATFS siteThe directory src.option
contains several files
where
the functions
ff_convert
and
ff_wtoupper
are defined.I think
the file you
choose
must be consistent
with the selection of
_CODE_PAGE
infile
ffconf.h
________________ Attachments : ccsbcs.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I146&d=%2Fa%2F0X0000000bhg%2FDAgD8FtdQt9M7u9Y4lnaOShhzBC0qIsbAKLnfat6Jd0&asPdf=false