I want to add a protection to a region of a memory, starting from 0x20000000. The size of the region is 64 bytes. Permission is read only, no flag set except xn. Here's how I think it should be,
#define MPU_CTRL (*((volatile unsigned long*) 0xE000ED94)) // MPU Control register
#define MPU_RNR (*((volatile unsigned long*) 0xE000ED98)) // MPU Region Number register
#define MPU_RBAR (*((volatile unsigned long*) 0xE000ED9C)) // MPU Region Base Address Register
#define MPU_RASR (*((volatile unsigned long*) 0xE000EDA0)) // MPU Region attributes and size register
void Registers_Init(void)
{
//MPU Configuring
MPU_RNR = 0x00000000; // use region 0
MPU_RBAR = 0x20000000; // base address is 0x20000000
MPU_RASR = 0x1608FF0B; // enable bit=1, 64 bytes,not subregions, s=c=b=0, xn=1, permission= ro/ro.
MPU_CTRL = 0x00000005; // enable memory protection unit,guaranteeing default priviliged access
}
int main()
{
Registers_Init();
return 0;
}
Is this correct? Am I doing it wrong? Please guide.