jefflab
November 14, 2018, 9:24pm
1
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?
jefflab
November 14, 2018, 11:36pm
3
@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?
jefflab
November 15, 2018, 1:04am
5
It has been a while since we chose this implementation path, so the details are a bit fuzzy.
Trying to reconstruct our reasoning:
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.
We wanted to use “Stop Mode” mode instead of “Sleep Mode” because it uses less power. From the STM reference manual:
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?
jefflab
November 15, 2018, 1:32am
6
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.
jefflab
November 15, 2018, 1:44am
8
@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 .
jefflab
November 15, 2018, 1:46am
9
@jefflab , the library is also available on the Web IDE.
jefflab
November 15, 2018, 1:56am
11
@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!
jefflab
November 15, 2018, 2:25am
14
@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:
#elif defined(STM32F10X_MD) //Core
if (!sysIntSetupDone) {
sysIntSetupDone = true;
if (!attachSystemInterrupt(SysInterrupt_TIM2_Update, Wiring_TIM2_Interrupt_Handler_override)) ; //error
if (!attachSystemInterrupt(SysInterrupt_TIM3_Update, Wiring_TIM3_Interrupt_Handler_override)) ; //error
if (!attachSystemInterrupt(SysInterrupt_TIM4_Update, Wiring_TIM4_Interrupt_Handler_override)) ; //error
}
#elif defined(STM32F2XX) && defined(PLATFORM_ID) //Photon
if (!sysIntSetupDone) {
sysIntSetupDone = true;
if (!attachSystemInterrupt(SysInterrupt_TIM3_Update, Wiring_TIM3_Interrupt_Handler_override)) ; //error
if (!attachSystemInterrupt(SysInterrupt_TIM4_Update, Wiring_TIM4_Interrupt_Handler_override)) ; //error
if (!attachSystemInterrupt(SysInterrupt_TIM5_Update, Wiring_TIM5_Interrupt_Handler_override)) ; //error
if (!attachSystemInterrupt(SysInterrupt_TIM6_Update, Wiring_TIM6_Interrupt_Handler_override)); //error
if (!attachSystemInterrupt(SysInterrupt_TIM7_Update, Wiring_TIM7_Interrupt_Handler_override)); //error
}
#endif
}
~IntervalTimer() { end(); }
I’ll give it a try tomorrow. This has been tremendously helpful. Thanks!