Programming the MPU

The MPU of Cortex-M microcontrollers support up to eight different programmable regions. A function that enables the MPU and sets up all the regions can be implemented and invoked at the beginning of the program. The MPU registers are mapped in HAL libraries, but in this case, we decided to define our own version and access them directly:

#define MPU_BASE 0xE000ED90#define MPU_TYPE (*(volatile uint32_t *)(MPU_BASE + 0x00))#define MPU_CTRL (*(volatile uint32_t *)(MPU_BASE + 0x04))#define MPU_RNR (*(volatile uint32_t *)(MPU_BASE + 0x08))#define MPU_RBAR (*(volatile uint32_t *)(MPU_BASE + 0x0c))#define MPU_RASR (*(volatile uint32_t *)(MPU_BASE + 0x10))

In our example, we used the following defined bit-field value definitions ...

Get Embedded Systems Architecture now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.