Skip to content

Commit 47ac8ef

Browse files
c1728p90xc0170
authored andcommitted
Fix MPU test when MemManage fault enabled
Hook both the HardFault and the MemManage IRQs since it is up to the target to determine which fault is enabled.
1 parent 58ed5c2 commit 47ac8ef

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

TESTS/mbed_hal/mpu/main.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131
using namespace utest::v1;
3232

3333
#define HARDFAULT_IRQn ((IRQn_Type)-13)
34+
#define MEMFAULT_IRQn ((IRQn_Type)-12)
3435

3536
// Assembly return instruction: bx lr
3637
#define ASM_BX_LR 0x4770
3738

3839
volatile uint32_t fault_count;
3940
uint32_t real_hard_fault_handler;
41+
uint32_t real_mem_fault_handler;
4042

4143
static volatile uint16_t data_function = ASM_BX_LR;
4244
static volatile uint16_t bss_function;
@@ -154,18 +156,21 @@ void mpu_fault_test_heap()
154156

155157
utest::v1::status_t fault_override_setup(const Case *const source, const size_t index_of_case)
156158
{
157-
// Save old hard fault handler and replace it with a new one
159+
// Save old fault handlers and replace it with a new one
158160
real_hard_fault_handler = NVIC_GetVector(HARDFAULT_IRQn);
161+
real_mem_fault_handler = NVIC_GetVector(MEMFAULT_IRQn);
159162
NVIC_SetVector(HARDFAULT_IRQn, (uint32_t)&hard_fault_handler_test);
163+
NVIC_SetVector(MEMFAULT_IRQn, (uint32_t)&hard_fault_handler_test);
160164

161165
return greentea_case_setup_handler(source, index_of_case);
162166
}
163167

164168
utest::v1::status_t fault_override_teardown(const Case *const source, const size_t passed, const size_t failed,
165169
const failure_t reason)
166170
{
167-
// Restore real hard fault handler
171+
// Restore real fault handlers
168172
NVIC_SetVector(HARDFAULT_IRQn, real_hard_fault_handler);
173+
NVIC_SetVector(MEMFAULT_IRQn, real_mem_fault_handler);
169174

170175
return greentea_case_teardown_handler(source, passed, failed, reason);
171176
}

0 commit comments

Comments
 (0)