cancel
Showing results for 
Search instead for 
Did you mean: 

Cortex-M3 Memory Protection Configuration(MPU)

Muzahir Hussain
Associate III
Posted on November 12, 2017 at 17:55

I want to protect a memory region from writing. I've configured MPU, but it is not generating any faults. The base address of the region that I want to protect is 0x20000000. The region size is 64 bytes.

Here's how I did it,

//Memory Protection Unit Registers

#define MPU_CTRL (*((volatile unsigned long*) 0xE000ED94)) #define MPU_RNR (*((volatile unsigned long*) 0xE000ED98))

#define MPU_RBAR (*((volatile unsigned long*) 0xE000ED9C))

#define MPU_RASR (*((volatile unsigned long*) 0xE000EDA0))

#define SCB_SHCSR (*((volatile unsigned long*) 0xE000ED24))

void Registers_Init(void) { //MPU Configuring MPU_RNR = 0x00000000; //region is 0 MPU_RBAR = 0x20000000; //base address is 0x20000000 MPU_RASR = 0x1608FF0B; // enable bit=1, 64 bytes, no subregions, s=c=b=0, xn=1, permission=ro,ro SCB_SHCSR |= 0x00010000; // enable MemManage Fault

MPU_CTRL = 0x00000005; // enable memory protection unit,guaranteeing default priviliged access

}

void MemManage_Handler(void)

{ __asm( 'MOV R4, 0x77777777\n\t' 'MOV R5, 0x77777777\n\t' ); } void HardFault_Handler(void) { __asm( 'MOV R4, 0x77777777\n\t' 'MOV R5, 0x77777777\n\t' ); } int main(void) { Registers_Init();

while(1)

{ __asm( 'LDR R0, =0x20000000\n\t' 'MOV R1, 0x77777777\n\t' 'STR R1, [R0,#0]' ); } return (1); }

void SystemInit(void)

{ }

So, in main function, I am writing in restricted area i.e. 0x20000000, but MPU is not generating any fault and instead of calling MemManage_Handler()or HardFault_Handler(), it writes successfully.

Why is that? Please help.

The micro controller I am using is STM32F103RB.

#mpu #stm32f103rb #memory-protection #stm32 #cortex-m3
3 REPLIES 3
David SIORPAES
ST Employee
Posted on November 13, 2017 at 10:02

I am afraid that microcontroller has no MPU implemented.

Check MPU Type register @ 0xe000ed If bits 15:8 read 0 (as in my Nucleo-F103) there's no MPU.

See attaches ST-Link screenshots comparing F103 with F

________________

Attachments :

mpu-no.png : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HyJ3&d=%2Fa%2F0X0000000b5o%2F9CYC8oKr0KvVCua8Z9eswKbjOf5d46LRGeYs1TsOpx8&asPdf=false

mpu-yes.png : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HyIt&d=%2Fa%2F0X0000000b5k%2Fc82S9SO2LLPP5qgYz9ES0nO6glMvxj6cBEYVT6Xpo6c&asPdf=false
175129CGIL2