Hi, I am developing on a FRDM-K66F and I am trying to trap floating point exception by generating an interrupt.
I understand that it should be a usage fault interrupt that will be triggered.
The sample code below show that I am enabling the usage_fault interrupt, I set a priority then I enable all possible floating point exceptions in the Interrupt Status Register (MCM_ISCR) .
If I run this part of code, after the div/0 I see that the MCM detect it because if I read MCM_ISCR back I see 0x9F120200, FDZC is now set as well as the FPSCR[DZC].
Question: What am I missing to generate the interrupt? Code goes through, never calling the ISR (which is a while(1) for now.
float toto=1.0;
SCB->SHCSR|=SCB_SHCSR_USGFAULTENA_Msk |SCB_SHCSR_BUSFAULTENA_Msk |SCB_SHCSR_MEMFAULTENA_Msk;
NVIC_SetPriority (UsageFault_IRQn,0x08);
*(uint8_t *)0xe0080010=(uint8_t)0x9F;
toto=toto/0.0F;
Thanks
Solved! Go to Solution.
Hello
Please add these lines to enable the registers:
NVIC_EnableIRQ(UsageFault_IRQn);
SCB->CCR |= (SCB_CCR_DIV_0_TRP_Msk);
SCB->SHCSR|= SCB_SHCSR_USGFAULTENA_Msk |SCB_SHCSR_BUSFAULTENA_Msk |SCB_SHCSR_MEMFAULTENA_Msk;
The reason why the interruption is not detected is the line "toto=toto/0.0F;"
If you add this function to your code we can see that the Usage fault is called:
static int _DivideByZero(void) {
int r;
volatile unsigned int a;
volatile unsigned int b;
a = 1.0;
// movs r3, #1 <- Load dividend
b = 0.0;
// movs r3, #0 <- Load divisor
r = a / b;
// udiv r3, r2, r3 <- divide by 0 raises fault exception
return r;
}
If you have more questions do not hesitate to ask me.
Best regards,
Omar
Hello
Please add these lines to enable the registers:
NVIC_EnableIRQ(UsageFault_IRQn);
SCB->CCR |= (SCB_CCR_DIV_0_TRP_Msk);
SCB->SHCSR|= SCB_SHCSR_USGFAULTENA_Msk |SCB_SHCSR_BUSFAULTENA_Msk |SCB_SHCSR_MEMFAULTENA_Msk;
The reason why the interruption is not detected is the line "toto=toto/0.0F;"
If you add this function to your code we can see that the Usage fault is called:
static int _DivideByZero(void) {
int r;
volatile unsigned int a;
volatile unsigned int b;
a = 1.0;
// movs r3, #1 <- Load dividend
b = 0.0;
// movs r3, #0 <- Load divisor
r = a / b;
// udiv r3, r2, r3 <- divide by 0 raises fault exception
return r;
}
If you have more questions do not hesitate to ask me.
Best regards,
Omar