cancel
Showing results for 
Search instead for 
Did you mean: 

FatFS and STM32L4+ internal flash

zous
Associate II

Hi There,

I am starting to work with an STM32L4R5ZI chip which is embedded on STM32 Nucleo-144 L4R4ZI.

I am using the internal flash 2 M-Bytes in dual bank mode and I would like to enable the FatFs to use the internal flash to store configuration files (JSON format).

I am still wondering whether it is the right solution to store configuration files BTW...

I did find information about the reliability to use the internal flash and FatFs for this STM32L4+ chip.

Does anyone have tips if we can configure the internal flash and FatFS together to create a filesystem with this STM32L4+ chip?

Please let me know if you need more details,

Thanks,

Regards

8 REPLIES 8

Going to want to switch to 4KB sectors.

Will be very slow to write, Erase 22 ms, Write 30-40 ms

>>I am still wondering whether it is the right solution to store configuration files BTW...

Yes, probably more effective ways to store a few blocks of data..

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III

You don't need FatFS or any filesystem at all to save one small file. Just write it into some block, and be done. Make two copies, if you like.

-- pa

zous
Associate II

Hi there,

Thanks for your reply.

To be complete, the purpose of my tests is to be able to send later a binary program for a DSP controlled by the STM32L4R5.

And I think that it is the best solution to use FatFs to do so.

@Community member​ I am not sure to have well understood when you wrote: "Going to want to switch to 4KB sectors" ... You mean that in this configuration I must use

the dual-bank organization with 4KB per pages and 64 bits read width?

Please clarify,

Thank you,

Regards

If you don't want to manage the blocking/de-blocking of 512 byte sectors in your DISKIO layer implementation, then you'll want to configure the FATFS settings to use 4KB blocks/sectors instead, as this is the minimum erase unit size.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
zous
Associate II

Thanks for your reply you helped me to start my tests.

I wrote my own USER_initialize, USER_write, USER_read functions to try to read from the internal flash but something tricky happened.

The f_mount returns FR_OK but the f_mkfs always return FR_INVALID_PARAMETER.

In ffconf.h Sector size is set to 4096 ...

All the read then write function failed ... (make sense when you have FR_INVALID_PARAMETER when I called f_mkfs)

I do not think I did something wrong but advise and or correction are welcome .

Regards

/* Gives a work area to the default drive */
	res = f_mount(&USERFatFS, (TCHAR const*) USERPath, 0);
	if (FR_OK != res) {
		/* FatFs Format Error */
		Error_Handler();
	}
 
	/* FatFs with internal flash */
	/* Format the default drive with default parameters */
	res = f_mkfs((TCHAR const*)USERPath, 0, 0, (BYTE*)work, (UINT) sizeof(work));
	if (res) {
		/* FatFs Format Error */
		Error_Handler();
	}
 
	/* Create a file as new */
	res = f_open(&fil, "test.txt",
			FA_CREATE_ALWAYS | FA_CREATE_NEW | FA_WRITE | FA_READ);
	if (FR_OK != res) {
		/* FatFs Format Error */
		Error_Handler();
	}
 
	/* Read 'BUF_LEN' bytes from source file */
	res = f_read(&fil, rBuffer, BUF_LEN, &br);
	if (res != FR_OK || br == 0) /* Error condition or EOF */
	{
 
		/* FatFs Format Error */
		Error_Handler();
	}
 
	/* Write a message */
	res = f_write(&fil, wtext, (UINT) btw, (UINT*) &bw);
	if ((btw != bw) || (FR_OK != res)) {
		/* FatFs Format Error */
		Error_Handler();
	}
 
 
	/* Close the file */
	res = f_close(&fil);
	if (res) {
 
		/* FatFs Format Error */
		Error_Handler();
	}
 
	/* Unregister work area */
	res = f_mount(0, "", 0);
	if (res) {
 
		/* FatFs Format Error */
		Error_Handler();
	}

All very top level, middleware source is available. Instrument lower levels, and chase down failure causes.

The work[] buffer needs to be sufficiently large, use an existing buffer rather than burn as a static allocation, on the stack be conscious about how large it is.

uint8_t work[_MAX_SS]; // Make sure _MAX_SS is 4096

Performance of USER_read() / USER_write() will be critical to functionality.

Would avoid burning flash erase cycles with f_mkfs() if the memory is already initialized.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
zous
Associate II

Dear all,

Is it really possible to use FatFs with STM32L4+ on-chip flash ? I am not talking about external SDCARD etc.

I have tried several test based on examples (Examples found on other STM32 board)

I am a bit concern and disapointed that ST does not provide exampled with on-chip and FatFs for STM32L4+.

Regards

>>Is it really possible to use FatFs with STM32L4+ on-chip flash ? 

I'm pretty confident it can be done. The wisdom of doing it, less so.

>>I am a bit concerned and disappointed that ST does not provide examples with on-chip and FatFs for STM32L4+.

It is not really ST's responsibility to carry everyone development work for every possible outcome, especially the "Best worst, Idea" class, companies usually hire embedded developers who can carry ideas across the finish line.

Figure it would take me several hours of work, figure out what that's worth.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..