Skip to content

Commit ec424b7

Browse files
tgorochowikgalak
authored andcommitted
arch: arm: mpu: nxp: disable mpu before reprogramming
This is needed, because an interrupt can happen after the main/static MPU region is disabled and before it is re-enabled. This region gets implicitly disabled inside the _region_init call, when its configuration registers change: SYSMPU->WORD[index][0] = region_base; SYSMPU->WORD[index][1] = region_end; SYSMPU->WORD[index][2] = region_attr; SYSMPU->WORD[index][3] = SYSMPU_WORD_VLD_MASK; The TRM says this about the WORD0, WORD1 and WORD2 registers: Writes to this register clear the region descriptor’s valid bit (RGDn_WORD3[VLD]). And thus if an interrupt happens after writing to WORD0 and before writing VLD to WORD3 again, the code executes with enabled and yet misconfigured MPU. Fixes #13482 Signed-off-by: Tomasz Gorochowik <[email protected]>
1 parent b0c71af commit ec424b7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

arch/arm/core/cortex_m/mpu/nxp_mpu.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,16 @@ static int _mpu_configure_dynamic_mpu_regions(const struct k_mem_partition
327327
{
328328
/* Reset MPU regions inside which dynamic memory regions may
329329
* be programmed.
330+
*
331+
* Re-programming these regions will temporarily leave memory areas
332+
* outside all MPU regions.
333+
* This might trigger memory faults if ISRs occurring during
334+
* re-programming perform access in those areas.
330335
*/
336+
arm_core_mpu_disable();
331337
_region_init(mpu_config.sram_region, (const struct nxp_mpu_region *)
332338
&mpu_config.mpu_regions[mpu_config.sram_region]);
339+
arm_core_mpu_enable();
333340

334341
u32_t mpu_reg_index = static_regions_num;
335342

0 commit comments

Comments
 (0)