Skip to content

Commit 24f002d

Browse files
c1728p90xc0170
authored andcommitted
Clear caches before RAM execution in MPU test
Ensure that code written to ram is flushed and that caches are cleared before attempting to executing from ram. This fixes CI failures on the MPU test when it is built for Cotex-M7 devices such as the NUCLEO-F746ZG.
1 parent 09b1a90 commit 24f002d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

TESTS/mbed_hal/mpu/main.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ uint32_t real_hard_fault_handler;
4141
static volatile uint16_t data_function = ASM_BX_LR;
4242
static volatile uint16_t bss_function;
4343

44+
static void clear_caches()
45+
{
46+
#if defined(__CORTEX_M7)
47+
/* Data cache clean and invalid */
48+
SCB_CleanInvalidateDCache();
49+
50+
/* Instruction cache invalid */
51+
SCB_InvalidateICache();
52+
#endif
53+
54+
__ISB();
55+
__DSB();
56+
57+
}
58+
4459
static void call_mem(const volatile uint16_t *mem_function)
4560
{
4661
// or the address with 1 to ensure the thumb bit is set
@@ -112,6 +127,7 @@ void mpu_fault_test_data()
112127
void mpu_fault_test_bss()
113128
{
114129
bss_function = ASM_BX_LR;
130+
clear_caches();
115131
mpu_fault_test(&bss_function);
116132
}
117133

@@ -120,6 +136,7 @@ void mpu_fault_test_stack()
120136
uint16_t stack_function;
121137

122138
stack_function = ASM_BX_LR;
139+
clear_caches();
123140
mpu_fault_test(&stack_function);
124141
}
125142

@@ -129,6 +146,7 @@ void mpu_fault_test_heap()
129146

130147
TEST_ASSERT_NOT_EQUAL(NULL, heap_function);
131148
*heap_function = ASM_BX_LR;
149+
clear_caches();
132150
mpu_fault_test(heap_function);
133151

134152
free(heap_function);

0 commit comments

Comments
 (0)