我想为内存区域添加保护,从 0x20000000 开始。该区域的大小为 64 字节。权限是只读的,除了 xn 没有设置标志。我觉得应该是这样的
#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;
}
这个对吗?我做错了吗?请指导。