Embedded Design Handbook

ID 683689
Date 8/28/2023
Public
Document Table of Contents

4.3.2.2.3. MPU Register Details

This section describes the register maps, the meanings of the register fields, and how the register fields are used.

When you initialize the MPU you use two registers: mpubase and mpuacc.

Register mpubase Usage

Table 18.  mpubase Control Register Fields
Bit Fields
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
BASE3
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BASE3 0 INDEX2 D
Table 19.  mpubase Control Register Field Descriptions
Field Description Access Reset Available
BASE BASE is the base memory address of the region identified by the INDEX and D fields. Read/Write 0 Only with MPU
INDEX INDEX is the region index number. Read/Write 0 Only with MPU
D D is the region access bit. When D =1, INDEX refers to a data region. When D = 0, INDEX refers to an instruction region. Read/Write 0 Only with MPU

You specify an MPU region by writing a value representing the region's base address to the BASE field, a unique index to the INDEX field, and the region type (data or instruction) to field D.

The BASE field represents the region's base address, in the form described by the equation below. The BASE field can only represent addresses aligned to an integer multiple of <min_region>. For example, if the minimum region size is 16 kilobytes (KB), regions can be located at addresses such as 0x0, 0x4000, 0x8000, ... .

Equation 1. Base Address Computation

BASE = <base address>/<min_region>

For example, if the region starts at 0x1000 and the minimum region size is 256 bytes, set the BASE field to 0x10, which is 0x1000/256.

The INDEX field provides a unique identifier for the region. INDEX also specifies the priority of the region. The lower the index value, the higher the region’s priority.

Use the D field to specify the region type: data or instruction.

Register mpuacc Usage

mpuacc has two possible layouts, depending on the Platform Designer generation-time option Use limit for region range, as described in Adding the MPU Hardware section. This option controls whether the mpuacc register contains a MASK or LIMIT field. The table below shows the layout of the mpuacc register with the MASK field.

Table 20.  mpuacc Control Register Fields for MASK Variation
Bit Fields
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MASK[n-1:p]4
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MASK[n-1:p]4 0 MT PERM RD WR
Table 21.  mpuacc Control Register Fields for LIMIT Variation
Bit Fields
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LIMIT[n:p]4
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LIMIT[n:p]4 0 MT PERM RD WR
Table 22.  mpuacc Control Register Field Descriptions
Field Description Access Reset Available
MASK MASK specifies the size of the region. Read/Write 0 Only with MPU
LIMIT LIMIT specifies the upper address limit of the region. Read/Write 0 Only with MPU
MT (MT) Memory Type:
  • 0 = peripheral (non-cacheable, non-write bufferable)
  • 1 = normal (cacheable, write bufferable)
  • 2 = device (non-cacheable, write bufferable)
  • 3 = reserved
Read/Write 0 Only with MPU
PERM PERM specifies the access permissions for the region. Read/Write 0 Only with MPU
RD RD is the read region flag. When RD = 1, wrctl instructions to the mpuacc register perform a read operation. Write 0 Only with MPU
WR WR is the write region flag. When WR = 1, wrctl instructions to the mpuacc register perform a write operation. Write 0 Only with MPU

If the mpuacc register is configured with the MASK field, the MASK field represents the size of your region. The value of MASK is defined in the equation below.

Equation 2. Computing Region Mask

MASK = 0xFFFFFF << log2 ( <region_size> >> 8 )

The table below lists every possible MASK value for an MPU configured with a256-byte minimum region size.

Table 23.  MASK Region Size Encodings
MASK Encoding Region Size
0xFFFFFF 256 bytes
0xFFFFFE 512 bytes
0xFFFFFC 1 KB
0xFFFFF8 2 KB
0xFFFFF0 4 KB
0xFFFFE0 8 KB
0xFFFFC0 16 KB
0xFFFF80 32 KB
0xFFFF00 64 KB
0xFFFE00 128 KB
0xFFFC00 256 KB
0xFFF800 512 KB
0xFFF000 1 MB
0xFFE000 2 MB
0xFFC000 4 MB
0xFF8000 8 MB
0xFF0000 16 MB
0xFE0000 32 MB
0xFC0000 64 MB
0xF80000 128 MB
0xF00000 256 MB
0xE00000 512 MB
0xC00000 1 GB
0x800000 2 GB
0x000000 4 GB

If the mpuacc register is configured with the LIMIT field, LIMIT represents the address immediately following the upper end of your region. For example, suppose the MPU’s minimum region size is 256 bytes, and you need to set up the following region:

  • The region starts at 0x1000
  • The region ends at 0x1FFF

To set up the desired region, configure mpubase.BASE and mpuacc.LIMIT as shown in the following list:

  • Set mpubase.BASE to 0x10, which is 0x1000/256 or (0x1000 >> 8)
  • Set mpuacc.LIMIT to 0x20, which is 0x2000/256 or (0x2000 >> 8)

Use the C field to specify whether a data region is to be cached. Usually, you set C for memory regions and clear it for regions representing registers or general-purpose memory-mapped I/O.

The PERM field defines the permissions for the region, as shown in the two tables below.

Table 24.  Instruction Region Permission Encodings
PERM Encoding Supervisor Permissions User Permissions
000 None None
001 Execute None
010 Execute Execute
Table 25.  Data Region Permission Encodings
PERM Encoding Supervisor Permissions User Permissions
000 None None
001 Read None
010 Read Read
100 Read/Write None
101 Read/Write Read
110 Read/Write Read/Write

Defining Regions with mpubase and mpuacc

The mpubase register works in conjunction with the mpuacc register to set and retrieve MPU region information. Use the RD and WR fields of mpuacc to instruct the MPU to perform an MPU region read or write, as shown in the following list:

  • Set mpuacc.RD = 1 to perform an MPU region read operation.
  • Set mpuacc.WR = 1 to perform an MPU region write operation.
Note: Simultaneously setting both the RD and WR fields to 1 results in undefined behavior.

An MPU region must be disabled if it is not in use. To disable a region, software sets up the following conditions:

  • mpubase.BASE is any nonzero value.
  • If the MPU is configured to define region size by mask, mpuacc.MASK represents 0x100000000, which is 232 (the size of the Nios® II address space). For example, if the minimum region size is 256, or 0x100 bytes, mpuacc.MASK is 0x100000000 / 0x100, or 0x10000000.
  • If the MPU is configured to define region size by limit, mpuacc.LIMIT = 0.
2 This field size is variable. Unused upper bits must be written as zero.
3 This field size is variable. Unused upper bits and unused lower bits must be written as zero.
4 This field size is variable. Unused upper bits and unused lower bits must be written as zero.