Importance of flash cache when writing to program flash

cancel
Showing results for 
Search instead for 
Did you mean: 

Importance of flash cache when writing to program flash

606 Views
dpa
Contributor I

I am trying to erase, write and read a section of the program flash on the FRDM-K66F while performing other operations. This is so that I can perform firmware upgrades in the background. The program flash is partitioned so that the partition to be programmed is different to the partition that holds the running program's code and data.

To achieve this, I am reading through the pflash driver example so that I may understand what is necessary to write to flash. However I am having trouble determining the importance of the flash cache in this example. My understanding is that the cache is, by default, used for speeding up the reading of code and data from the flash. It then appears as if the example turns this off using

FTFx_CACHE_ClearCachePrefetchSpeculation(&s_cacheDriver, true);

probably so that it may use the cache for itself.

Since I wish to write to the flash in the background, would it be better to leave the cache in its default state, so that the performance of the main program is not altered? Is this possible, or is it mandatory to use the flash cache when programming the flash?

0 Kudos
3 Replies

447 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello d p

 

The cache is a block of high-speed memory. The purpose of the cache is to decrease the average time of memory access.

You can disable the cache and still write in the flash.

If the firmware will be used to erase and program flash space (this affects both the system cache and the FMC's cache and prefetch buffers) we recommend invalidate any cached lines from the flash in the CODE bus cache and also invalidate the FMC cache ways and prefetch buffer for the flash banks corresponding to the area that will be erased/programmed.

 

Let me know if this is helpful, if you have more questions do not hesitate to ask me.

Best regards,

Omar

447 Views
dpa
Contributor I

Hi Omar

Thank you for your helpful response. I think I understand that aspect now.

I am wondering if you could please elaborate on why the caches should be invalidated?

Thanks

0 Kudos

447 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello d p

 

The cache invalidation in the FMC just invalidates the small cache that resides within the flash memory controller. The FMC block is only used for read accesses to the flash. All writes and other commands to the flash go through a completely different interface.

Because writes go through a completely different mechanism, the FMC has no way of knowing when the flash has been modified, so when you erase or write the flash, you should invalidate the FMC cache to ensure that all future reads return the correct data instead of stale data from the cache.

 

Let me know if this is helpful, if you have more questions do not hesitate to ask me.

Best regards,

Omar