iCacheFlushDemo
This example (iCacheFlushDemo directory) illustrates how to
invalidate the instruction cache. The instruction cache invalidation is critical to
ensure the coherency between the cache and the main memory, ensuring that the CPU
fetches the most up-to-date instructions. First, the string funcA is
copied into an array and printed in this example. funcA is the output.
Next, the string funcB is copied into the same array and printed again.
Even though funcB is stored in the array, funcA is
seen as the output because the instruction cache has not yet been flushed.
To address this, the instruction cache is invalidated. Once the instruction cache is
invalidated, funcB can be expected to be printed out in the UART
console. Additionally, the most up-to-date instructions are fetched from the main
memory.
By following this process, you can ensure that the CPU fetches the most recent instructions from the main memory and maintains coherency with the instruction cache. The design displays these messages in a UART terminal:
***Starting Flush Instruction Cache Demo***
Memcpy funcA into array ..
Flush the instruction cache once to avoid preloaded data ..
Expected 'funcA', Obtained : funcA
Memcpy funcB into array ..
Expected 'funcA', Obtained : funcA
Still get the FuncA as there is no cache flush ..
Flush the instruction cache now ..
Expected 'funcB', Obtained : funcB
***Successfully Ran Demo***