Disable Cache for Shared Data
The default cache policy is write-back with write allocation. This policy is the easiest for the hardware to implement and consumes the least system bus resources and power. It is also the least useful for keeping shared (CPU and DMA) data coherent. Combining this cache policy with uncached memory for shared data is the simplest cache management approach.
You can force specific variables or buffers to be uncached by allocating shared data to the uncached memory segment (KSEG1).
Static Variables
Static variables can be created using the coherent attribute. This assigns a variable or array to the un-cached KSEG1 memory segment.
Automatic Variables
The stack is implemented in cachable memory (KSEG0) by default. If you don’t want to cache automatic (local) variables, use the
_ _pic32_alloc_coherent() and _ _pic32_free_coherent() functions as shown in this example.
void myFunction(void)
{
char* buffer = __pic32_alloc_coherent(1024);
if (buffer)
{
/* do something */
}
else
{
/* handle error */
}
if (buffer)
{
__pic32_free_coherent(buffer);
}
}