cancel
Showing results for 
Search instead for 
Did you mean: 

FATFS Code Generation for STM32L (CubeMX)

OHaal
Associate II

I am using STM32L476VG and I want to write files to a SD card. In CubeMX I generate code for the FAT File System with the following settings:

0690X000006ByBOQA0.png

Moreover, I am using FreeRTOS with static memory allocation only:

0690X000006ByBYQA0.png

However, I have found two issues so far:

  1. Since the reentrancy setting for FATFS configuration must be enabled when using FreeRTOS, the function ff_cre_syncobj(...) (syscall.c) is called inside f_mount(...) (ff.c). However, since this function does not allocate memory dynamically oder statically, the execution fails. I think the line
osSemaphoreDef(...);

is not correct, since there is a dedicated macro

osSemaphoreStaticDef(...);

for the static definition of a semaphore. Is this a bug in ff_cre_syncobj(...)?

2. For some reason the setting for USE_LFN (Use Long Filename) is not accepted for code generation. This setting is disabled in CubeMX (see first screenshot) but in ffconf_template.h the lines

#define	_USE_LFN	3
#define	_MAX_LFN	255
/* The _USE_LFN switches the support of long file name (LFN).
/
/   0: Disable support of LFN. _MAX_LFN has no effect.
/   1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
/   2: Enable LFN with dynamic working buffer on the STACK.
/   3: Enable LFN with dynamic working buffer on the HEAP.
...*/

are generated. I also noticed that _USE_LFN can take three distinct values in CubeMX, but as you can see from the file above, the comment suggests that there are four distinct values possible. So why is the generated code not consistent with the CubeMX settings? Can I just (safely) change the value of _USE_LFN manually or might this result in further issues?

4 REPLIES 4
Pavel A.
Evangelist III

> but in ffconf_template.h the lines .... are generated.

This file is template only. What is actually generated in Inc/ffconf.h in your project folder?

-- pa

OHaal
Associate II

Thanks Pavel. The generated code in Inc/ffconf.h is correct. This answers question 2.

Any ideas/suggestions related to question 1?

PR?�f
Associate

Hey,

I think I have run into the same problem (Q1). Did you manage to solve it somehow?

OHaal
Associate II

Unfortunately not, but the answer would still be of use for me.