cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX is replacing FatFS's ff.h

Despair1337
Associate III

According to this pull request, FatFS with DMA doesn't work on H7/F7 if cache is enabled.

For this, two members in structs (in FatFS) needs to be aligned (even, when I have _MAX_SS as number dividable by 32) to FatFS work (check PR). But, the CubeMX everytime after IOC change replaces this ff.h .

Is it possible to not replace the ff.h? Or maybe best will be to solve this internally in CubeMX, since without this mdoification, FatFS with DMA just don't work.

Thaks

3 REPLIES 3
Houssem CHAABANI
Senior II

Hi @Despair1337​ ,

Thank you for the details.

STM32CubeMX copy ff.h from the the package folder, So you can change the file in the package folder.

You can find it under user/STM32Cube/Repository ...

It's not recommended but it can help you until the fixe of this issue.

When your question is answered, please close this topic by choosing Select as Best. This will help other users find that answer faster.

Thanks!

Hello,

Thanks for the tip, but this is not good in long-term usage. The project is made by several developers, that means that every developer must have modified SDK, to have FatFS working with DMA, which is very bad. Can't be this situation solved other way? As you could seen, I send PR to SDK, but they don't want to make modifications to 3rd party libraries. Should I contact FatFS creator?

Thanks,

Piranha
Chief II

I've not used FatFs, but here is an idea for a dirty workaround... Wrap those FatFs structures into another structures, which are aligned to cache line size. Before FatFs structure insert a byte array and adjust it's size so that the particular buffer in FatFs structure is also aligned to cache line size.

typedef __PACKED_STRUCT {
	uint8_t ab[12];
	FATFS s;
} FATFS_ts __ALIGNED(__SCB_DCACHE_LINE_SIZE);
 
#define STATIC_ASSERT(condition)    ( (void)sizeof(char[1 - 2*!(condition)]) )
 
STATIC_ASSERT(!(offsetof(FATFS_ts, s.win) & (__SCB_DCACHE_LINE_SIZE - 1)));

Of course you will have to pass a pointer to FATFS_ts.s to all the respective FatFs functions.

> Should I contact FatFS creator?

As complex microcontrollers with cache and multiple different memories are becoming more popular, that would be the best action. Probably it's better to only store a pointer to the buffer in FatFs structure and initialize it from an additional parameter in f_mount()/f_open(). That will allow the data buffer to be placed anywhere in the system.