PlatformIO Community

Need help with trying to set a Contiki timer -> Core 1 panic'ed (LoadProhibited)

I’m trying to set a timer using the ContikiCoreForArduino library. The reason for using this library is because I’m experimenting with protothreads so I’m including that library already anyway.

According to the documentation it should be fairly straightforward, but when I try to set the timer I’m getting a Core panic.

I’m not new to software development, but I did just start tinkering with embedded development, PlatformIO and cpp so forgive me if I’m missing the obvious here. Platform is espressif32, framework is arduino.

This is my code:

#include <Arduino.h>
#include "contiki.h"

static struct timer t;
static struct pt pt1;

static int protothreadFunction(struct pt *pt)
{
  static int i = 0;
  PT_BEGIN(pt);

  while (1)
  {
    PT_WAIT_UNTIL(pt, timer_expired(&t));
    Serial.println(i);
    timer_set(&t, 1000);
  }
  PT_END(pt);
}

void setup()
{
  Serial.begin(115200);
  Serial.println("Program start, setting timer");
  timer_set(&t, 1000);
  Serial.println("Timer set");
  PT_INIT(&pt1);
}

void loop()
{
  protothreadFunction(&pt1);
}

Which results in this:

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5828
entry 0x400806ac
Program start, setting timer
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x400e91ef  PS      : 0x00060130  A0      : 0x800d0cc8  A1      : 0x3ffb1f20
A2      : 0x00000000  A3      : 0x3f4012ce  A4      : 0x0000001c  A5      : 0x0000ff00
A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x800d0f3d  A9      : 0x3ffb1f00
A10     : 0x00000002  A11     : 0x3f4012ce  A12     : 0x00000002  A13     : 0x0000ff00
A14     : 0x00ff0000  A15     : 0xff000000  SAR     : 0x0000001f  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xffffffff

Backtrace: 0x400e91ef:0x3ffb1f20 0x400d0cc5:0x3ffb1f40 0x400d0c79:0x3ffb1f60 0x400d0c01:0x3ffb1f80 0x400d1e0b:0x3ffb1fb0 0x40088215:0x3ffb1fd0

Rebooting...

Any help or suggestions are most appreciated, thanks!

Will call

with clock_time() being

In your case timer is still NULL because you do not call the low-level initialization which will call clock_start().

As seen in this example

You need to call it explicitly.

1 Like

That’s brilliant! Thanks for the solution and the quick response! I had no idea clock_start() was needed explicitly, but makes sense now.