Skip to content

Commit 5c89e1f

Browse files
authored
Merge pull request #3108 from pan-/nrf52_sleep_clean_fpu_irq
Fix sleep function for NRF52.
2 parents d7c02a1 + 501a00b commit 5c89e1f

File tree

1 file changed

+9
-0
lines changed
  • targets/TARGET_NORDIC/TARGET_NRF5

1 file changed

+9
-0
lines changed

targets/TARGET_NORDIC/TARGET_NRF5/sleep.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
// In this case, bits which are equal to 0 are the bits reserved in this register
2424
#define SCB_ICSR_RESERVED_BITS_MASK 0x9E43F03F
2525

26+
#define FPU_EXCEPTION_MASK 0x0000009F
27+
2628
void sleep(void)
2729
{
2830
// ensure debug is disconnected if semihost is enabled....
@@ -31,6 +33,13 @@ void sleep(void)
3133
// the processor from disabled interrupts.
3234
SCB->SCR |= SCB_SCR_SEVONPEND_Msk;
3335

36+
#ifdef NRF52
37+
/* Clear exceptions and PendingIRQ from the FPU unit */
38+
__set_FPSCR(__get_FPSCR() & ~(FPU_EXCEPTION_MASK));
39+
(void) __get_FPSCR();
40+
NVIC_ClearPendingIRQ(FPU_IRQn);
41+
#endif
42+
3443
// If the SoftDevice is enabled, its API must be used to go to sleep.
3544
if (softdevice_handler_isEnabled()) {
3645
sd_power_mode_set(NRF_POWER_MODE_LOWPWR);

0 commit comments

Comments
 (0)