1

I am running a code in Cooja simulator on Contiki and I got the following error message:

Executing MSP430X instruction but MCU is not a MSP430X

I want to broadcast a structure named ReqMsg. The structure.h file has been defined as below:

   typedef struct {

    int id ;

    int t1 ;

    int t2 ;

    char op[4];

    char E[2][2][4];

    char S[2][2][4];

    char type[20];

}EventPattern; 

typedef struct {

    int id;

    EventPattern epin;

    EventPattern epout;

    EventPattern epresolved;

    int remainEnergy;

}ReqMsg;

I gave values to ReqMsg r as below :

    EventPattern ep1 = {1, 1, 20,{{"a"} , {"b"}} ,{"seq"},{{"seq","a"},{"seq", "b"}}, "re"};
    EventPattern ep2 = {2, 1, 20,{{"a"} , {"b"}} ,{"seq"},{{"seq","a"},{"seq", "b"}}, "re"};
    EventPattern ep3 = {3, 1, 20,{{"a"} , {"b"}} ,{"seq"},{{"seq","a"},{"seq", "b"}}, "re"};
    ReqMsg r = {1, ep1, ep2, ep3, 5};

and to broadcast the ReqMsg I used packetbuffer as below :

    const ReqMsg *req = &r;
    const void *reqAdd = &req;
    packetbuf_copyfrom(reqAdd, 6);
    broadcast_send(&broadcast);

I changed the buflen parameter in packetbuf_copyfrom macro to 8, 10, 255 and 3512. the error message for all the values where the same. The Contiki error log in the simulation is :

    Executing MSP430X instruction but MCU is not a MSP430X
    Stack Trace: number of calls: 2 PC: $00002
    InterruptVectors (memset.c) called from PC: $062ca (elapsed: 5)
    rtimer_run_next (memset.c) called from PC: $05b38 (elapsed: 24)
    *** Interrupt 6 from PC: $042b8

and the java error log is :

    org.contikios.cooja.ContikiError
at org.contikios.cooja.mspmote.MspMote.execute(MspMote.java:341)
at org.contikios.cooja.mspmote.MspMote.execute(MspMote.java:298)
at org.contikios.cooja.motes.AbstractWakeupMote$1.execute(AbstractWakeupMote.java:47)
at org.contikios.cooja.Simulation.run(Simulation.java:280)
at java.lang.Thread.run(Thread.java:745)
Caused by: se.sics.mspsim.core.EmulationException: Executing MSP430X 
instruction but MCU is not a MSP430X
at se.sics.mspsim.core.MSP430Core.emulateOP(MSP430Core.java:1079)
at se.sics.mspsim.core.MSP430.stepMicros(MSP430.java:253)
at org.contikios.cooja.mspmote.MspMote.execute(MspMote.java:337)
... 4 more

Please help me to solve this problem.

kfx
  • 8,136
  • 3
  • 28
  • 52
mahshid
  • 41
  • 7

1 Answers1

0

The "Executing MSP430X instruction" error typically shows up when there is memory corruption, and as a result the MCU starts trying to execute as instructions some memory addresses that do not contain actual instructions.

In your code:

const ReqMsg *req = &r;
const void *reqAdd = &req;
packetbuf_copyfrom(reqAdd, 6);

the variable reqAdd contains the address of the req variable. Instead, you want to to set to the address of the variable r, which is equal to the value of req:

const void *reqAdd = req;

Even better idea is to simply do

packetbuf_copyfrom(req, 6);

or

packetbuf_copyfrom(&r, 6);

since there is no real need for the extra variables.

kfx
  • 8,136
  • 3
  • 28
  • 52
  • copyfrom macro has been defined in contiki and the signature is packetbuf_copyfrom(const void *from, uint16_t len).. – mahshid Dec 15 '18 at 18:29
  • [Conversions to `void *` are implicit in C](https://stackoverflow.com/a/1736841/2435820). You already are using this fact in your code, in the line which assigns value to `reqAdd`. – kfx Dec 15 '18 at 20:39
  • Also, `packetbuf_copyfrom` is a function, not a macro. – kfx Dec 15 '18 at 20:40
  • I did not know the difference between macro and function. I searched about it. thank you – mahshid Dec 16 '18 at 03:15
  • Did this answer solve your problem? If so, please accept it. – kfx Dec 17 '18 at 11:59
  • thank you for your answer but it is not solved yet. it's major problem is about the size of the reqAdd. the size is equal to 1 byte. so I've changed the buf size parameter in copyfrom function from 6 to 1 and also I've changed it to 8. both new sizes did not worked well. – mahshid Dec 17 '18 at 12:16
  • *size of the reqAdd [..] is equal to 1 byte* - this is not true. – kfx Dec 17 '18 at 12:22
  • *both new sizes did not worked well* - please provide a [mcve] how did they not worked. By the way, your `ReqMsg` is too large to be sent at once. The default packetbuf size is only 128 bytes. – kfx Dec 17 '18 at 12:23
  • so I should fragment the packet. thank you. I'll try this solution. – mahshid Dec 17 '18 at 12:26
  • If you only want to send the first six bytes of the packet, it should work as is. – kfx Dec 17 '18 at 14:07