SparkIntervalTimer

Hi,

I’m trying to make timer interrupts by using the SparkIntervalTimer library found on the cloud. My code looks like this:

// This #include statement was automatically added by the Particle IDE.
#include "SparkIntervalTimer/SparkIntervalTimer.h"

IntervalTimer myTimer;

void blink(void);



void setup() {
    myTimer.begin(blink, 5000, hmSec);
}

void blink(void) {
    Spark.publish("hello", "5");
}

void loop() {
    
}

And I am getting these compilation errors:

SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::start_SIT(uint16_t, bool)':
SparkIntervalTimer/SparkIntervalTimer.cpp:178:10: warning: statement has no effect [-Wunused-value]
    scale == uSec;    // Default to microseconds
          ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::interrupt_SIT(action)':
SparkIntervalTimer/SparkIntervalTimer.cpp:261:15: warning: variable 'TIMx' set but not used [-Wunused-but-set-variable]
  TIM_TypeDef* TIMx;
               ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::resetPeriod_SIT(uint16_t, bool)':
SparkIntervalTimer/SparkIntervalTimer.cpp:305:26: warning: unused variable 'timerInitStructure' [-Wunused-variable]
  TIM_TimeBaseInitTypeDef timerInitStructure;
                          ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::start_SIT(uint16_t, bool)':
SparkIntervalTimer/SparkIntervalTimer.cpp:191:43: warning: 'TIMx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  TIM_ITConfig(TIMx, TIM_IT_Update, ENABLE);
                                           ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::stop_SIT()':
SparkIntervalTimer/SparkIntervalTimer.cpp:247:18: warning: 'TIMx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  TIM_DeInit(TIMx);
                  ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::resetPeriod_SIT(uint16_t, bool)':
SparkIntervalTimer/SparkIntervalTimer.cpp:336:23: warning: 'TIMx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  TIMx->PSC = prescaler;
                       ^
../../../build/target/user/platform-6/libuser.a(particle-ktbox.o): In function `__static_initialization_and_destruction_0':
particle-ktbox.cpp:4: undefined reference to `SystemCoreClock'
particle-ktbox.cpp:4: undefined reference to `Wiring_TIM2_Interrupt_Handler'
particle-ktbox.cpp:4: undefined reference to `Wiring_TIM3_Interrupt_Handler'
particle-ktbox.cpp:4: undefined reference to `Wiring_TIM4_Interrupt_Handler'
../../../build/target/user/platform-6/libuser.a(SparkIntervalTimer.o): In function `Wiring_TIM2_Interrupt_Handler_override':
SparkIntervalTimer/SparkIntervalTimer.cpp:37: undefined reference to `TIM_GetITStatus'
SparkIntervalTimer/SparkIntervalTimer.cpp:39: undefined reference to `TIM_ClearITPendingBit'
../../../build/target/user/platform-6/libuser.a(SparkIntervalTimer.o): In function `Wiring_TIM3_Interrupt_Handler_override':
SparkIntervalTimer/SparkIntervalTimer.cpp:47: undefined reference to `TIM_GetITStatus'
SparkIntervalTimer/SparkIntervalTimer.cpp:49: undefined reference to `TIM_ClearITPendingBit'
../../../build/target/user/platform-6/libuser.a(SparkIntervalTimer.o): In function `Wiring_TIM4_Interrupt_Handler_override':
SparkIntervalTimer/SparkIntervalTimer.cpp:57: undefined reference to `TIM_GetITStatus'
SparkIntervalTimer/SparkIntervalTimer.cpp:59: undefined reference to `TIM_ClearITPendingBit'
../../../build/target/user/platform-6/libuser.a(SparkIntervalTimer.o): In function `IntervalTimer::start_SIT(unsigned short, bool)':
SparkIntervalTimer/SparkIntervalTimer.cpp:163: undefined reference to `RCC_APB1PeriphClockCmd'
SparkIntervalTimer/SparkIntervalTimer.cpp:153: undefined reference to `RCC_APB1PeriphClockCmd'
SparkIntervalTimer/SparkIntervalTimer.cpp:158: undefined reference to `RCC_APB1PeriphClockCmd'
SparkIntervalTimer/SparkIntervalTimer.cpp:189: undefined reference to `TIM_TimeBaseInit'
SparkIntervalTimer/SparkIntervalTimer.cpp:190: undefined reference to `TIM_Cmd'
SparkIntervalTimer/SparkIntervalTimer.cpp:191: undefined reference to `TIM_ITConfig'
SparkIntervalTimer/SparkIntervalTimer.cpp:200: undefined reference to `NVIC_Init'
../../../build/target/user/platform-6/libuser.a(SparkIntervalTimer.o): In function `IntervalTimer::stop_SIT()':
SparkIntervalTimer/SparkIntervalTimer.cpp:240: undefined reference to `TIM_Cmd'
SparkIntervalTimer/SparkIntervalTimer.cpp:244: undefined reference to `NVIC_Init'
SparkIntervalTimer/SparkIntervalTimer.cpp:247: undefined reference to `TIM_DeInit'
collect2: error: ld returned 1 exit status
make: *** [b6cc983af97e12c7345eaae9484624c7abc8ee1af7a119aba287c76d0932.elf] Error 1
Error: Could not compile. Please review your code.

If I try this line instead of my old line: myTimer.begin(blink(), 5000, hmSec);

I get this error message:
 
particle-ktbox.cpp: In function 'void setup()':
particle-ktbox.cpp:11:39: error: invalid use of void expression
 void blink(void);
                                       ^

make[1]: *** [../build/target/user/platform-6particle-ktbox.o] Error 1
make: *** [user] Error 2

I will appreciate any help on this.

Best Regards,
Mohammed

@mohammedmidhat, the current library is not compatible with the Photon and as soon as the new firmware version is released (0.4.4rc?), I will be releasing a new version of SparkIntervalTimer. :smile:

2 Likes

Thank you @peekay123, do you think of any other solution for making a timer with the Photon for now?

Best,
Mohammed

@mohammedmidhat, the new firmware will be released this week!

1 Like

Thank you very much @peekay123.

Hi @peekay123, I noticed in your last commit Aug 21 that you added Photon support. I am still getting linking errors on the TIMx symbols…are your photon support changes working?

Thanks,
Colin

SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::interrupt_SIT(action)':
SparkIntervalTimer/SparkIntervalTimer.cpp:261:15: warning: variable 'TIMx' set but not used [-Wunused-but-set-variable]
  TIM_TypeDef* TIMx;
               ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::resetPeriod_SIT(uint16_t, bool)':
SparkIntervalTimer/SparkIntervalTimer.cpp:305:26: warning: unused variable 'timerInitStructure' [-Wunused-variable]
  TIM_TimeBaseInitTypeDef timerInitStructure;
                          ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::start_SIT(uint16_t, bool)':
SparkIntervalTimer/SparkIntervalTimer.cpp:191:43: warning: 'TIMx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  TIM_ITConfig(TIMx, TIM_IT_Update, ENABLE);
                                           ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::stop_SIT()':
SparkIntervalTimer/SparkIntervalTimer.cpp:247:18: warning: 'TIMx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  TIM_DeInit(TIMx);
                  ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::resetPeriod_SIT(uint16_t, bool)':
SparkIntervalTimer/SparkIntervalTimer.cpp:336:23: warning: 'TIMx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  TIMx->PSC = prescaler;
                       ^
../../../build/target/user/platform-6/libuser.a(treadmill.o): In function `__static_initialization_and_destruction_0':
treadmill.cpp:174: undefined reference to `Wiring_TIM2_Interrupt_Handler'
treadmill.cpp:174: undefined reference to `Wiring_TIM3_Interrupt_Handler'
treadmill.cpp:174: undefined reference to `Wiring_TIM4_Interrupt_Handler'
collect2: error: ld returned 1 exit status
make: *** [b73d42f72c0d304b288f92787719593929076cf4dbb8c6f1a379c3b5e6f2.elf] Error 1

@guru_florida,

The Photon compatible SparkIntervalTimer library is now available in the web IDE and here on my githut. Sorry for the delay!!

4 Likes

Thanks @peekay123, I reimported the project in the web IDE, and I’ve confirmed I have the latest code with the scale == uSec fix. I’ve even forked your project and tried importing that but I get the same linking errors. Any ideas?

treadmill.cpp:174: undefined reference to `Wiring_TIM2_Interrupt_Handler'
treadmill.cpp:174: undefined reference to `Wiring_TIM3_Interrupt_Handler'
treadmill.cpp:174: undefined reference to `Wiring_TIM4_Interrupt_Handler'

I also get all the TIMx may be uninitialized as well.

@guru_florida, are you compiling for a Core or Photon target?

Photon

Make sure you use the latest version from the web IDE. By default it shown me the 1.2.0. After refreshing the list, I can see the 1.3.2

[edit] I have the same error as you. However I am not sure the compiler is using the version 1.3.2. How to check this??

@guru_florida, @Fabien, it seems something is odd with the IDE. When I load the library this morning, it is showing up a the old version. When I reload the new version, it says that version already exists but then, the new version show up!! When I load it and compile, it gives an error on a line which should compile. If I delete the line, save, reinsert the line save and compile again, it works! I’ll ping the folks at Particle to see what gives. In the meantime, I HIGHLY recommend using the Particle DEV and downloading the code directly from github. :slight_smile:

Thanks @peekay123! The IDE has been a crap-shoot for me overall. So buggy. I keep trying it thinking, “well they’ll have it all sorted out by now…” 2 years later and…nope. :frowning:

I have local dev for core already, I’ll move to that for Photon as well. Thanks for your support! Great library, no surprise it’s about 5th from the top.

1 Like

@peekay123 excellent news about the new library, haven’t had enough time and i’m just checking… Great work!

1 Like