Complete the code to set the base address of an MPU region.
MPU->RNR = [1]; // Select region numberThe MPU Region Number Register (RNR) is set to select which region to configure. Here, setting it to 3 selects region 3.
Complete the code to enable an MPU region.
MPU->RASR = (1 << [1]); // Enable region
The enable bit for the MPU region is bit 0 in the Region Attribute and Size Register (RASR). Setting bit 0 to 1 enables the region.
Fix the error in setting the region size to 256 bytes.
MPU->RASR = ([1] << 1) | (1 << 0); // Set size and enable
The size field in RASR uses the formula: SIZE = log2(region size) - 1. For 256 bytes, log2(256) = 8, so SIZE = 7. Shifting 7 left by 1 positions it correctly in bits [5:1] of RASR, and OR with (1 << 0) enables the region.
Fill both blanks to configure an MPU region with size 512 bytes and full access permission.
MPU->RASR = ([1] << 1) | ([2] << 24) | (1 << 0);
The size field is set by (log2(size) - 1). For 512 bytes, log2(512) = 9, so size = 8. The access permission field (AP) is bits 24-26; full access is represented by 3.
Fill all three blanks to create a dictionary comprehension that maps region numbers to their sizes in bytes, filtering only regions larger than 256 bytes.
region_sizes = { [1]: 1 << ([2] + 1) for [3], [2] in regions.items() if (1 << ([2] + 1)) > 256 }This comprehension creates a dictionary where keys are region numbers and values are sizes calculated as 2^(size_code + 1). It filters regions with sizes greater than 256 bytes.
