8. Instruction cache (ICACHE)

8.1 ICACHE introduction

The instruction cache (ICACHE) is introduced on the C-AHB code bus of the Cortex®-M33 processor, to improve performance when fetching instructions and data from internal memories.

Some specific features like hit-under-miss, and critical-word-first refill policy, allow close to zero-wait-state performance in most use cases.

8.2 ICACHE main features

The main features of ICACHE are listed below:

8.3 ICACHE implementation

Table 45. ICACHE features

FeatureICACHE
Number of ways2
Cache size8 Kbytes
Cache line width16 bytes
Number of regions to remap0
Data size of AHB slave interface32 bits
Data size of AHB fast master1 interface128 bits
Data size of AHB slow master2 interface0

8.4 ICACHE functional description

The purpose of the instruction cache is to cache instruction fetches or instruction memories loads, coming from the processor. As such, the ICACHE only manages cacheable read transactions and does not manage cacheable write transactions.

The noncacheable transactions (both read and write ones) bypass the ICACHE.

For the error management purpose, in case a write cacheable transaction is presented (this only happens in case of bad software programming), the ICACHE sets an error flag and, if enabled, raises an interrupt to the processor.

8.4.1 ICACHE block diagram

Figure 18. ICACHE block diagram

ICACHE block diagram showing internal components and external interfaces.

The diagram illustrates the ICACHE block structure. At the top, a bidirectional AHB bus connects to a 'Configuration slave port'. This port leads into the 'Configuration interface' block, which contains sub-blocks for 'Region 0 cfg', 'Region 2 cfg', 'Hit monitor', 'Control', 'Region 1 cfg', 'Region 3 cfg', 'Miss monitor', and 'Status'. Below this is the 'Cache control logic' block, containing a 'Cache FSM' and a 'pLRU-t' block. This logic is connected via a 'Cache memory port' to two parallel sets of 'Cache TAG memories' and 'Cache data memories', both labeled 'n ways'. The entire ICACHE block is flanked by two interfaces: an 'Execution port interface' on the left and a 'Master port interface' on the right. The left interface connects to the Cortex-M33 C-AHB bus via an 'Execution port AHB' and an 'icache_it' signal. The right interface connects to the 'Main AHB' via a 'Master1 port AHB'. The label 'ICACHE' is at the bottom left of the main block, and the reference 'MSv69711V2' is at the bottom right.

ICACHE block diagram showing internal components and external interfaces.

8.4.2 ICACHE reset and clocks

The ICACHE is clocked on the Cortex®-M33 C-AHB bus clock.

When the ICACHE reset signal is released, a cache invalidate procedure is automatically launched, making the ICACHE busy (ICACHE_SR = 0x0000 0001).

When this procedure is finished:

Note: When disabled, the ICACHE is bypassed: slave input requests are forwarded to the master port.

8.4.3 ICACHE TAG memory

The ICACHE TAG memory contains:

There is one valid bit per cache line (per way).

The valid bit is set when a cache line is refilled (after a miss).

Valid bits are reset in any of the below cases:

When a cacheable transaction is received at the execution input port, its AHB address (HADDR_in) is split into the following fields (see Table 46 for B and W definitions):

The following table gives a summary of the ICACHE main parameters for TAG memory dimensioning. Figure 19 shows the functional view of TAG and data memories, for an n-way set associative ICACHE.

Table 46. TAG memory dimensioning parameters
for n-way set associative operating mode (default)

ParameterValueExample
Cache sizeS Kbytes = s bytes (s = 1024 × S)8 Kbytes = 8192 bytes
Cache number of waysn2
Cache line sizeL-byte = l-bit (l = 8 × L)16-byte = 128-bit
Number of cache lines (per way)LpW = s/(n × L) lines / way256 lines / way
Address byte offset sizeB = log₂(L) bit4-bit
Address way index sizeW = log₂(LpW) bit8-bit
TAG address sizeT = (32-W-B) bit20-bit

Figure 19. ICACHE TAG and data memories functional view

Figure 19. ICACHE TAG and data memories functional view: Diagram showing AHB_address (HADDR_in) split into TAG (T-bit), Index (W-bit), and Offset (B-bit). Shows pLRU-t block with way selection (for replacement), TAG memory (n ways, TAG_Way0 to TAG_Way(n-1), V0 to Vn-1, LpW lines / way) with equality comparisons, and Data memory (Data_Way0 to Data_Way(n-1), LpW lines / way, l-bit) outputting Cache hit/miss in Way0 and Way(n-1).

MSv48192V2

Figure 19. ICACHE TAG and data memories functional view: Diagram showing AHB_address (HADDR_in) split into TAG (T-bit), Index (W-bit), and Offset (B-bit). Shows pLRU-t block with way selection (for replacement), TAG memory (n ways, TAG_Way0 to TAG_Way(n-1), V0 to Vn-1, LpW lines / way) with equality comparisons, and Data memory (Data_Way0 to Data_Way(n-1), LpW lines / way, l-bit) outputting Cache hit/miss in Way0 and Way(n-1).

8.4.4 Direct-mapped ICACHE (1-way cache)

The default configuration (at reset) is an n-way set associative cache (WAYSEL = 1 in ICACHE_CR), but the user can configure the ICACHE as direct mapped by writing WAYSEL = 0 (only possible when the cache is disabled, EN = 0 in ICACHE_CR).

The following table gives a summary of ICACHE main parameters for TAG memory when the direct-mapped cache operating mode is selected.

Table 47. TAG memory dimensioning parameters for direct-mapped cache mode

ParameterValueExample
Cache sizeS Kbytes = s bytes (s = 1024 x S)8 Kbytes = 8192 bytes
Cache number of ways11
Cache line sizeL-byte = l-bit (l = 8 x L)16-byte = 128-bit
Number of cache linesLpW = s / L lines512 lines
Address byte offset sizeB = log2(L) bit4-bit
Address way index sizeW = log2(LpW) bit9-bit
TAG address sizeT = (32 - W - B) bit19-bit

All cache operations (such as read, refill, invalidation) remain the same in the direct-mapped configuration. The only difference is the absence of a replacement algorithm in case of line eviction (as explained in Section 8.4.7): only one way (the unique one) is possible for any data refill.

8.4.5 ICACHE enable

To activate the ICACHE, the EN bit must be set to 1 in ICACHE_CR.

When the ICACHE is disabled, it is bypassed and all transactions are copied from the slave port to the master port in the same clock cycle.

It is recommended to initialize or modify the main memory content (region to be later cached) with the ICACHE disabled, and to enable the ICACHE only when this region remains unchanged (an enabled ICACHE detects cacheable write transactions as errors).

To ensure performance determinism, it is recommended to wait for the end of a potential cache invalidate procedure before enabling the ICACHE. This procedure occurs when the hardware reset signal is released, when CACHEINV is set, or when EN is cleared in ICACHE_CR. During the procedure, BUSYF is set in ICACHE_SR, and once finished, BUSYF is cleared and BSYENDF is set in the same register (raising the ICACHE interrupt if enabled on such a busy end condition).

The software must test BUSYF and/or BSYENDF values before enabling the ICACHE. Else, if the ICACHE is enabled before the end of an invalidate procedure, any cache access (while BUSYF = 1) is treated as noncacheable, and its performance depends on the main memory access time.

The ICACHE is by default disabled at boot.

8.4.6 Cacheable and noncacheable traffic

The ICACHE is developed for the Cortex®-M33 core. It is placed on the C-AHB bus, and thus caches the code memory region, ranging from address 0x0000 0000 to 0x1FFF FFFF of the memory map.

An incoming memory request to the ICACHE is defined as cacheable according to its AHB transaction memory lookup attribute, as shown in Table 48. This AHB attribute depends on the MPU (memory protection unit) programming for the addressed region.

Table 48. ICACHE cacheability for AHB transaction

AHB lookup attributeCacheability
1Cacheable
0Noncacheable

In the case of a noncacheable access (either a noncacheable read or a noncacheable write), the ICACHE is bypassed, meaning that the AHB transaction is propagated unchanged to the master output port.

The bypass does not increase the latency of the access to the targeted memory.

In the case of a cacheable access, the ICACHE behaves as explained in Section 8.4.7.

Cacheable memory regions are defined and programmed by the user in the MPU that is responsible for the generation of the AHB attribute signals for any transaction addressing a given region.

8.4.7 Cacheable accesses

When the ICACHE receives a cacheable transaction from the Cortex®-M33, the ICACHE checks if the address requested is present in its TAG memory, and if the corresponding cache line is valid.

There are then three alternatives:

In the case of cache refill (due to cache miss), the ICACHE selects which cache line is written with the refill data:

If ever the cache line where the refill data must be written is already valid, the targeted cache line must be invalidated first. This is true whatever the direct map or n-way set associative cache mode.

8.4.8 ICACHE maintenance

The software can invalidate the whole content of the ICACHE by programming CACHEINV in the ICACHE_CR register.

When CACHEINV = 1, the ICACHE control logic sets the BUSYF flag in ICACHE_SR and launches the invalidate cache operation, resetting each TAG valid bit to 0 (one valid bit per cache line). CACHEINV is automatically cleared.

Once the invalidate operation is finished (all valid bits reset to 0), the ICACHE automatically clears BUSYF, and sets BSYENDF in the ICACHE_SR register.

If enabled on this flag condition (BSYENDIE = 1 in ICACHE_IER), the ICACHE interrupt is raised. Then, the (empty) cache is available again.

8.4.9 ICACHE performance monitoring

The ICACHE provides the following monitors for performance analysis:

Upon reaching their maximum values, these monitors do not wrap over.

Hit and miss monitors can be enabled and reset by software allowing the analysis of specific pieces of code.

The software can perform the following tasks:

To reduce power consumption, these monitors are disabled (stopped) by default.

8.4.10 ICACHE boot

The ICACHE is disabled (EN = 0 in ICACHE_CR) at boot.

Once the boot is finished, the ICACHE can be enabled (software setting EN = 1 in ICACHE_CR).

8.5 ICACHE low-power modes

At device level, using the ICACHE reduces the power consumption by fetching instructions from the internal ICACHE most of the time, rather than from the bigger and then more power consuming main memories.

Applications with lower performance profile (in terms of hit ratio) and stringent power consumption constraints may benefit from the lower power consumption of an ICACHE configured as direct mapped. This single-way cache configuration is obtained by programming WAYSEL = 0 in ICACHE_CR (see Figure 19). The power consumption is reduced by accessing, for each request, only the necessary cut of TAG and data memories. The cache effect still improves fetch performance, even if for most code execution, it is less efficient than with an n-way set associative cache mode.

8.6 ICACHE error management and interrupts

If an unsupported cacheable write request is detected (functional error), the ICACHE generates an error by setting the ERRF flag in ICACHE_SR. An interrupt is generated if the corresponding interrupt enable bit is set (ERRIE = 1 in ICACHE_IER).

The other possible interrupt generation is at the end of a cache invalidation operation. When the cache-busy state is finished, the ICACHE sets the BSYENDF flag in ICACHE_SR. An interrupt is generated if the corresponding interrupt enable bit is set (BSYENDIE = 1 in ICACHE_IER).

All ICACHE interrupt sources raise the same and unique interrupt signal, icache_it, and then use the same interrupt vector.

Table 49. ICACHE interrupts

Interrupt vectorInterrupt eventEvent flagEnable control bitInterrupt clear method
ICACHEFunctional errorERRF in ICACHE_SRERRIE in ICACHE_IERSet CERRF to 1 in ICACHE_FCR
End of busy state (invalidate finished)BSYENDF in ICACHE_SRBSYENDIE in ICACHE_IERSet CBSYENDF to 1 in ICACHE_FCR

The ICACHE also propagates all AHB bus errors (such as address decoding issues) from the master1 port back to the execution port.

8.7 ICACHE registers

8.7.1 ICACHE control register (ICACHE_CR)

Address offset: 0x000

Reset value: 0x0000 0004

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.MISSM
RST
HITM
RST
MISSM
EN
HITM
EN
rwrwrwrw
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.WAY
SEL
CACHE
INV
EN
rwwrw

Bits 31:20 Reserved, must be kept at reset value.

Bit 19 MISSMRST: miss monitor reset

Bit 18 HITMRST: hit monitor reset

ST logo
ST logo

Bit 17 MISSMEN: miss monitor enable

Bit 16 HITMEN: hit monitor enable

Bits 15:3 Reserved, must be kept at reset value.

Bit 2 WAYSEL: cache associativity mode selection

This bit allows user to choose ICACHE set-associativity. It can be written by software only when cache is disabled (EN = 0).

Bit 1 CACHEINV: cache invalidation

Set by software and cleared by hardware when the BUSYF flag is set (during cache maintenance operation). Writing 0 has no effect.

Bit 0 EN: enable

8.7.2 ICACHE status register (ICACHE_SR)

Address offset: 0x004

Reset value: 0x0000 0001

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ERRFBSYENDFBUSYF
rrr

Bits 31:3 Reserved, must be kept at reset value.

Bit 2 ERRF: cache error flag

Bit 1 BSYENDF: busy end flag

Bit 0 BUSYF: busy flag

8.7.3 ICACHE interrupt enable register (ICACHE_IER)

Address offset: 0x008

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ERRIEBSYEN
DIE
Res.
rwrw

Bits 31:3 Reserved, must be kept at reset value.

Bit 2 ERRIE: interrupt enable on cache error

Set by software to enable an interrupt generation in case of cache functional error (cacheable write access)

0: interrupt disabled on error

1: interrupt enabled on error

Bit 1 BSYENDIE: interrupt enable on busy end

Set by software to enable an interrupt generation at the end of a cache invalidate operation.

0: interrupt disabled on busy end

1: interrupt enabled on busy end

Bit 0 Reserved, must be kept at reset value.

8.7.4 ICACHE flag clear register (ICACHE_FCR)

Address offset: 0x00C

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CERRFCBSY
ENDF
Res.
ww

Bits 31:3 Reserved, must be kept at reset value.

Bit 2 CERRF: clear cache error flag

Set by software.

0: no effect

1: clears ERRF flag in ICACHE_SR

Bit 1 CBSYENDF: clear busy end flag

Set by software.

0: no effect

1: clears BSYENDF flag in ICACHE_SR.

Bit 0 Reserved, must be kept at reset value.

8.7.5 ICACHE hit monitor register (ICACHE_HMONR)

Address offset: 0x010

Reset value: 0x0000 0000

31302928272625242322212019181716
HITMON[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
HITMON[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 HITMON[31:0]: cache hit monitor counter

8.7.6 ICACHE miss monitor register (ICACHE_MMONR)

Address offset: 0x014

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
MISSMON[15:0]
rrrrrrrrrrrrrrrr

Bits 31:16 Reserved, must be kept at reset value.

Bits 15:0 MISSMON[15:0]: cache miss monitor counter

8.7.7 ICACHE register map

Table 50. ICACHE register map and reset values

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x000ICACHE_CRResResResResResResResResResResResResMISSMRSTHITMRSTMISSMENHITMENResResResResResResResResResResResResResWAYSELCACHEINVEN
Reset value0000100
0x004ICACHE_SRResResResResResResResResResResResResResResResResResResResResResResResResResResResResResERRFBSYENDFBUSYF
Reset value001
0x008ICACHE_IERResResResResResResResResResResResResResResResResResResResResResResResResResResResResResERRIEBSYENDIERes
Reset value00
0x00CICACHE_FCRResResResResResResResResResResResResResResResResResResResResResResResResResResResResResCERRFCBSYENDFRes
Reset value00
0x010ICACHE_HMONRHITMON[31:0]
Reset value00000000000000000000000000000000
0x014ICACHE_MMONRResResResResResResResResResResResResResResResResMISSMON[15:0]
Reset value0000000000000000

Refer to Section 2.2 for the register boundary addresses.