This is a basic example of the MMU in an application.
When you create a new project, mmu_page_table.c with the following contents will be generated in the src folder directly under the project. If you want to change the settings for the virtual page table, please edit this file.
#define R_MMU_UNCACHE_FLASH_OFFESET 0x10000000
#define R_MMU_UNCACHE_DDR_OFFESET 0x40000000
#define R_MMU_PHYSICAL_FLASH_START 0x20000000
#define R_MMU_PHYSICAL_FLASH_END 0x2FFFFFFF
#define R_MMU_PHYSICAL_DDR_START 0x40000000
#define R_MMU_PHYSICAL_DDR_END 0x7FFFFFFF
#define R_MMU_UNCACHE_FLASH_START 0x30000000
#define R_MMU_UNCACHE_FLASH_END 0x3FFFFFFF
#define R_MMU_UNCACHE_DDR_START 0x80000000
#define R_MMU_UNCACHE_DDR_END 0xBFFFFFFF
r_mmu_pgtbl_cfg_t const g_mmu_pagetable_array[] =
{
{0x00000000, 0x00000000, 0x00200000, R_MMU_PG_ATTRIBUTE_NORMAL_CACHEABLE},
{0x00200000, 0x00200000, 0x0FE00000, R_MMU_PG_ATTRIBUTE_ACCESS_FAULT },
{0x10000000, 0x10000000, 0x10000000, R_MMU_PG_ATTRIBUTE_DEVICE },
{0x20000000, 0x20000000, 0x10000000, R_MMU_PG_ATTRIBUTE_NORMAL_CACHEABLE},
{0x30000000, 0x20000000, 0x10000000, R_MMU_PG_ATTRIBUTE_NORMAL_UNCACHE },
{0x40000000, 0x40000000, 0x40000000, R_MMU_PG_ATTRIBUTE_NORMAL_CACHEABLE},
{0x80000000, 0x40000000, 0x40000000, R_MMU_PG_ATTRIBUTE_NORMAL_UNCACHE },
{0xC0000000, 0xC0000000, 0x40000000, R_MMU_PG_ATTRIBUTE_ACCESS_FAULT },
{0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }
};
fsp_err_t R_MMU_VAtoPA (
mmu_ctrl_t *
const p_api_ctrl, uint64_t vaddress, uint64_t * p_paddress)
{
if ((R_MMU_UNCACHE_FLASH_START <= vaddress) && (vaddress <= R_MMU_UNCACHE_FLASH_END))
{
*p_paddress = vaddress - R_MMU_UNCACHE_FLASH_OFFESET;
}
else if ((R_MMU_UNCACHE_DDR_START <= vaddress) && (vaddress <= R_MMU_UNCACHE_DDR_END))
{
*p_paddress = vaddress - R_MMU_UNCACHE_DDR_OFFESET;
}
else
{
*p_paddress = vaddress;
}
return err;
}
fsp_err_t R_MMU_PAtoVA (
mmu_ctrl_t *
const p_api_ctrl, uint64_t paddress, uint64_t * p_vaddress)
{
if ((R_MMU_PHYSICAL_FLASH_START <= paddress) && (paddress <= R_MMU_PHYSICAL_FLASH_END))
{
*p_vaddress = paddress + R_MMU_UNCACHE_FLASH_OFFESET;
}
else if ((R_MMU_PHYSICAL_DDR_START <= paddress) && (paddress <= R_MMU_PHYSICAL_DDR_END))
{
*p_vaddress = paddress + R_MMU_UNCACHE_DDR_OFFESET;
}
else
{
*p_vaddress = paddress;
}
return err;
}
g_mmu_pagetable_array contains a table of virtual to physical translation rules. In this table, please specify 2MB boundary values for address and size.
R_MMU_VAtoPA is a function that translates from a virtual address to a physical address. R_MMU_PAtoVA is a function that translates from a physical address to a virtual address.
If you have changed g_mmu_pagetable_array, please modify these functions to meet the new memory translation rules as well.