Enable RTC_WKUP_IRQHandler from application?

Is it possible to enable use of the RTC_WKUP_IRQHandler without modifying particle firmware?

Looking at the source code, it doesn’t seem to be enabled:

Is there a way to enable this from Application code without modifying the firmware? If yes, how?

@jefflab, what do you plan on doing with that handler?

@peekay123 We use it to wake up at exactly 1Hz from low power sleep.

@jefflab, have you thought of using timed System.sleep() for that?

It has been a while since we chose this implementation path, so the details are a bit fuzzy.

Trying to reconstruct our reasoning:

  1. Any form of System.sleep(POWER_MODE, seconds) won’t achieve exactly 1 second intervals because the interval will be 1 second + processing time between sleeping. We need a RTC to achieve 1Hz interrupts.

  2. We wanted to use “Stop Mode” mode instead of “Sleep Mode” because it uses less power. From the STM reference manual:

  1. To wake from Stop mode using an RTC, we found this instruction in the STM manual:

This always felt unecessarily hard. Is there any easier way to do this using System.sleep with a wakeup pin?

I just realized one more critical clue…

We need the ISR to continue at a 1Hz, even when we spend minutes uploading data.

The ISR sticks data into a buffer, and then the main thread comes along and processes it after sending the modem.

I think a solution using sleep would not allow background ISR processing when the main thread is uploading data via the modem.

Please correct me if I’m wrong.

@jefflab, I think you are trying to sleep when you can’t. The modem still needs to be serviced by the DeviceOS stack during transmission so you can’t sleep until the transmission is complete. As for the ISR, you can either use a “true” ISR via a hardware timer (SparkIntervalTimer) or using a Software Timer which is accurate to 1ms. You need to rethink your low power approach I believe.

@peekay123 I agree that I probably need a true hardware timer.

Can you point me to documentation for the SparkIntervalTimer you referred to? I don’t see it in the Electron Reference Documentation or the Particle Firmware Source Code.

Oops, I just saw your repo: https://github.com/pkourany/SparkIntervalTimer


@jefflab, the library is also available on the Web IDE.

@peekay123 Am I correct that the SparkIntervalTimer doesn’t solve the original question of how to trigger the RTC_WKUP_IRQHandler without changes to the OS firmware?

@jefflab, that is correct. I still think you need to rethink your sleeping approach. You can’t be sending data while the process is asleep!

@peekay123 Thanks. I’m actually not trying to sleep while sending. Here is what I’m doing:

  • Sample a sensor every second
  • Sleep for the remainder of the second until next interrupt
  • Once a day, upload the data, while continuing to sample that sensor in the background using an ISR

Looking at your code, I think this is the trick I need to connect up that ISR handle from user code:

I’ll give it a try tomorrow. This has been tremendously helpful. Thanks!