We know that the ARM MCU core can run at a speed line 60Mhz or even more than 100Mhz. But usually, the ARM program is located in Flash memory. But flash memory execution speed can reach only up to20MHz. Practically speaking, Flash memory is 3 – 4 times slower than ARM core speed can run. Of course, one of the workarounds could be loading critical program parts to RAM, but RAM is a limited resource – we cannot locate all programs to RAM as needed for data storing and so on. So second option is to have on-chip cash memory, which stands between CPU and memory. Well, LPC2000 and other ARM7 family has reduced cache module so-called Memory acceleration module (MAM).
Without going too deep on how MAM works, I can say that acceleration basically works by loading four ARM instructions simultaneously from Flash (Eight THUMB instructions). If an ARM is running at a speed of 60MHz, then there would be 3 access cycles to flash needed. MAM loads these instructions at one cycle. Usually, the MAM module is disabled after MCU reset. There can be three working modes of memory Acceleration Module:
- MAM is OFF- all instructions are read directly from Flash memory;
- Partially enables MAM – sequential instructions are accessed using MAM while branches and constants are accessed directly from Flash;
- Fully enables MAM – all memory fetching from MAM.
Two registers control MAM – timing(MAMTIM) and control(MAMCR). There also are statistics registers that allow gathering statistical information about instruction and data hit rate.
To initialize MAM you only need two lines of code:
//switch OFF MAM before adjusting timing MAMCR=0 // MAM-Fetch cycle to 3 cclk (>40MHz) MAMTIM = 3; // Activate MAM MAMCR = 2;
So if cclk<=20 Mhz then MAMTIM=1
if cclk 20-40 Mhz then MAMTIM=2
if cclk 40-60 Mhz then MAMTIM=3
if cclk 60-80 Mhz then MAMTIM=4
MAMTIM=4 for >80Mhz.
MAMCR=1 – partially enables MAM module.