Is the data cache used on the Teensy 4.0 in a usual program for holding the data? Or is the on-chip RAM so fast that no data cache is used. How can I demonstrate that the data-cache is used. Is the data cache used if I put data into the flash memory?
malloc() uses RAM2.
No, it would use the cache. (not need). As it works automagically, you don't need to worry about the cache.
You need cache-handling manually in one case only: If you use DMA.
DMA does not invalidate the cache, and it does not know that cache may contain data which is not in RAM. The cache is configured as write-back.