Go Down

Topic: sysTickHook (Read 704 times) previous topic - next topic

weird_dave

I can't seem to get sysTickHook() to work.
The code below never prints "Tick". Google suggests I need to wrap extern "C"{} around the function, but that gives me a compile error stating that the function is already defined.
Code: [Select]
int hooktimer = 1000;

void setup() {
  Serial.begin(250000);
}

void loop() {
}

int sysTickHook(void)
{
  if (--hooktimer == 0) {
    Serial.println("Tick");
    hooktimer = 1000;
  }
  return 0;
}

It appears I may not be the only one with this problem:
https://forum.arduino.cc/index.php?topic=380196.0

phr3ak

The original SysTick_Handler from cortex_handlers.c is overdefined in Arduino15\packages\arduino\hardware\sam\1.6.7\cores\arduino\main.cpp and it does not take care about sysTickHook

MustafaAlotbah

It is already defined before, but a weak definition "__attribute__((weak))", you can redefine it with your own code in C.
".ino" extensions are treated like C++ where you can't redefine those functions. The approach for that is by using C language inside as follows

Code: [Select]

#ifdef __cplusplus
extern "C" {
#endif

// C code

int sysTickHook() {

           // your code

}

// more C code

#ifdef __cplusplus
}
#endif

Go Up