Save ROM by specifying initial MPU state

We can omit the need for the "change MPU state" calls from simple images
by specifying the initial state at init.
pull/9064/head
Kevin Bracey 2018-12-10 14:24:17 +02:00 committed by Cruz Monrreal II
parent bb4cb774a2
commit 4d9f218ab2
3 changed files with 16 additions and 10 deletions

View File

@ -78,7 +78,8 @@ void mbed_mpu_init()
(3 << MPU_RBAR_AP_Pos) | // RO allowed by all privilege levels
(0 << MPU_RBAR_XN_Pos); // Execute Never disabled
MPU->RLAR = (0x1FFFFFFF & MPU_RLAR_LIMIT_Msk) | // Last address is 0x1FFFFFFF
(region << MPU_RLAR_AttrIndx_Pos); // Attribute index - configured to be the same as the region number
(region << MPU_RLAR_AttrIndx_Pos) | // Attribute index - configured to be the same as the region number
(1 << MPU_RLAR_EN_Pos); // Region enabled
region = 1;
MPU->RNR = region;
@ -90,7 +91,8 @@ void mbed_mpu_init()
(1 << MPU_RBAR_AP_Pos) | // RW allowed by all privilege levels
(1 << MPU_RBAR_XN_Pos); // Execute Never enabled
MPU->RLAR = (0x3FFFFFFF & MPU_RLAR_LIMIT_Msk) | // Last address is 0x3FFFFFFF
(region << MPU_RLAR_AttrIndx_Pos); // Attribute index - configured to be the same as the region number
(region << MPU_RLAR_AttrIndx_Pos) | // Attribute index - configured to be the same as the region number
(1 << MPU_RLAR_EN_Pos); // Region enabled
region = 2;
MPU->RNR = region;
@ -102,7 +104,8 @@ void mbed_mpu_init()
(1 << MPU_RBAR_AP_Pos) | // RW allowed by all privilege levels
(1 << MPU_RBAR_XN_Pos); // Execute Never enabled
MPU->RLAR = (0x7FFFFFFF & MPU_RLAR_LIMIT_Msk) | // Last address is 0x7FFFFFFF
(region << MPU_RLAR_AttrIndx_Pos); // Attribute index - configured to be the same as the region number
(region << MPU_RLAR_AttrIndx_Pos) | // Attribute index - configured to be the same as the region number
(1 << MPU_RLAR_EN_Pos); // Region enabled
region = 3;
MPU->RNR = region;
@ -114,7 +117,8 @@ void mbed_mpu_init()
(1 << MPU_RBAR_AP_Pos) | // RW allowed by all privilege levels
(1 << MPU_RBAR_XN_Pos); // Execute Never enabled
MPU->RLAR = (0x9FFFFFFF & MPU_RLAR_LIMIT_Msk) | // Last address is 0x9FFFFFFF
(region << MPU_RLAR_AttrIndx_Pos); // Attribute index - configured to be the same as the region number
(region << MPU_RLAR_AttrIndx_Pos) | // Attribute index - configured to be the same as the region number
(1 << MPU_RLAR_EN_Pos); // Region enabled
// Enable the MPU
MPU->CTRL =

View File

@ -64,8 +64,8 @@ extern "C" {
* Initialize the MPU
*
* Initialize or re-initialize the memory protection unit.
* It is implementation defined what region are protected
* by the MPU after initialization.
* After initialization or re-initialization, ROM and RAM protection
* are both enabled.
*/
void mbed_mpu_init(void);
@ -75,7 +75,9 @@ void mbed_mpu_init(void);
* This function is used to mark all of ROM as read and execute only.
* When enabled writes to ROM cause a fault.
*
* @param enable true to disable execution in ram, false otherwise
* By default writes to ROM are disabled.
*
* @param enable true to disable writes to ROM, false otherwise
*/
void mbed_mpu_enable_rom_wn(bool enable);
@ -85,7 +87,9 @@ void mbed_mpu_enable_rom_wn(bool enable);
* This function is used to mark all of RAM as execute never.
* When enabled code is only allowed to execute from flash.
*
* @param enable true to disable execution in ram, false otherwise
* By default execution from RAM is disabled.
*
* @param enable true to disable execution from RAM, false otherwise
*/
void mbed_mpu_enable_ram_xn(bool enable);

View File

@ -88,8 +88,6 @@ uint32_t mbed_stack_isr_size = 0;
void mbed_init(void)
{
mbed_mpu_init();
mbed_mpu_enable_ram_xn(true);
mbed_mpu_enable_rom_wn(true);
mbed_cpy_nvic();
mbed_sdk_init();
mbed_rtos_init();