Sony's Developer World forum

    • Home
    • Forum guidelines

    Upcoming maintenance 

     

    Dear Customers and Partners.

    This website will be undergoing scheduled maintenance on June 14, 2023. Please be aware there may be disruption to the developer portal website and associated services during the scheduled maintenance period.

    This upgrade is essential to ensure the continued performance, reliability, and security of Developer World.

    We apologize for any inconvenience.

     

     

    MultiCore MP_RECV_POLLING not working

    Spresense
    2
    8
    2291
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      Jamu last edited by

      Hi,

      After several tries within the arduino IDE I can't get the MessageHello to work. The MessageData example does work and looked at the differences.

      I found out that the MessageHello example makes use of

      MP.RecvTimeout(MP_RECV_POLLING);
      

      When I tried to add this Polling part to the working example I got the same problem.

      MP.Send error = -11
      

      is the error I get. I can't find anything in any documentation or what so ever. I have tried to use the polling system in my own written code as well but got the same error.

      I need the polling system for my project for the communication between the cores. Is there anything I am overlooking?

      Thanks in advance.

      1 Reply Last reply Reply Quote
      • C
        CamilaSouza DeveloperWorld last edited by

        Hello, Jamu!
        I'm going to ask a few follow up questions to see if we are able to get to the bottom of your problem.

        1. Could you send me the whole output you see in the serial terminal?
        2. What is the memory configuration under Tools -> Memory?
        3. Could you send source code for your modified MessageData example?
        J 1 Reply Last reply Reply Quote
        • J
          Jamu @CamilaSouza last edited by

          Could you send me the whole output you see in the serial terminal?

          The output is the picture underneath.

          7c1b88aa-4d3e-4345-949d-6624b2eeef0b-image.png

          What is the memory configuration under Tools -> Memory?

          768KB (default)

          Could you send source code for your modified MessageData example?

          UNCHANGED MAIN

          #ifdef SUBCORE
          #error "Core selection is wrong!!"
          #endif
          
          #include <MP.h>
          
          int subcore = 1; /* Communication with SubCore1 */
          
          void setup()
          {
            int ret = 0;
          
            Serial.begin(115200);
            while (!Serial);
          
            /* Launch SubCore1 */
            ret = MP.begin(subcore);
            if (ret < 0) {
              printf("MP.begin error = %d\n", ret);
            }
          
            randomSeed(100);
          }
          
          void loop()
          {
            int      ret;
            uint32_t snddata;
            uint32_t rcvdata;
            int8_t   sndid = 100; /* user-defined msgid */
            int8_t   rcvid;
          
            snddata = random(32767);
          
            /* Echo back from SubCore */
          
            printf("Send: id=%d data=0x%08lx\n", sndid, snddata);
          
            ret = MP.Send(sndid, snddata, subcore);
            if (ret < 0) {
              printf("MP.Send error = %d\n", ret);
            }
          
            /* Timeout 1000 msec */
            MP.RecvTimeout(1000);
          
            ret = MP.Recv(&rcvid, &rcvdata, subcore);
            if (ret < 0) {
              printf("MP.Recv error = %d\n", ret);
            }
          
            printf("Recv: id=%d data=0x%08lx : %s\n", rcvid, rcvdata,
                   (snddata == rcvdata) ? "Success" : "Fail");
          
            delay(1000);
          }
          

          CHANGED SUBCORE
          The change is highlighted in with item

          #if (SUBCORE != 1)
          #error "Core selection is wrong!!"
          #endif
          
          #include <MP.h>
          
          void setup()
          {
            int ret = 0;
          
            ret = MP.begin();
            if (ret < 0) {
              errorLoop(2);
            }
          **MP.RecvTimeout(MP_RECV_POLLING);**
          }
          
          void loop()
          {
            int      ret;
            int8_t   msgid;
            uint32_t msgdata;
          
            /* Echo back */
          
            ret = MP.Recv(&msgid, &msgdata);
            if (ret < 0) {
              errorLoop(3);
            }
          
            ret = MP.Send(msgid, msgdata);
            if (ret < 0) {
              errorLoop(4);
            }
          }
          
          void errorLoop(int num)
          {
            int i;
          
            while (1) {
              for (i = 0; i < num; i++) {
                ledOn(LED0);
                delay(300);
                ledOff(LED0);
                delay(300);
              }
              delay(1000);
            }
          }
          

          EXTRA
          The same results happens with the other example code "MessageHello" created by sony. Code downbelow

          #include <MP.h>
          
          #define MSGLEN      64
          #define MY_MSGID    10
          struct MyPacket {
            volatile int status; /* 0:ready, 1:busy */
            char message[MSGLEN];
          };
          
          #ifdef SUBCORE
          
          #if   (SUBCORE == 1)
          #define SUBID "Sub1"
          #elif (SUBCORE == 2)
          #define SUBID "Sub2"
          #elif (SUBCORE == 3)
          #define SUBID "Sub3"
          #elif (SUBCORE == 4)
          #define SUBID "Sub4"
          #elif (SUBCORE == 5)
          #define SUBID "Sub5"
          #endif
          
          MyPacket packet;
          
          void setup()
          {
            memset(&packet, 0, sizeof(packet));
            MP.begin();
          }
          
          void loop()
          {
            int        ret;
            static int count = 0;
          
            if (packet.status == 0) {
          
              /* status -> busy */
              packet.status = 1;
          
              /* Create a message */
              snprintf(packet.message, MSGLEN, "[%s] Hello %d", SUBID, count++);
          
              /* Send to MainCore */
              ret = MP.Send(MY_MSGID, &packet);
              if (ret < 0) {
                printf("MP.Send error = %d\n", ret);
              }
            }
          
            delay(500);
          }
          
          #else  /* MAINCORE */
          
          void setup()
          {
            int ret = 0;
            int subid;
          
            Serial.begin(115200);
            while (!Serial);
          
            /* Boot SubCore */
            for (subid = 1; subid <= 5; subid++) {
              ret = MP.begin(subid);
              if (ret < 0) {
                printf("MP.begin(%d) error = %d\n", subid, ret);
              }
            }
          
            /* Polling */
            MP.RecvTimeout(MP_RECV_POLLING);
          }
          
          void loop()
          {
            int      ret;
            int      subid;
            int8_t   msgid;
            MyPacket *packet;
          
            /* Receive message from SubCore */
            for (subid = 1; subid <= 5; subid++) {
              ret = MP.Recv(&msgid, &packet, subid);
              if (ret > 0) {
                printf("%s\n", packet->message);
                /* status -> ready */
                packet->status = 0;
              }
            }
          }
          
          #endif
          

          Hope this helps, thank you in advance

          1 Reply Last reply Reply Quote
          • C
            CamilaSouza DeveloperWorld last edited by

            Hey, Jamu!

            As we can see from the MessageHello example, the polling command (MP.RecvTimeout(MP_RECV_POLLING);) is in the code for the maincore, not the subcore.
            So could you try to leave the subcore code to the Message data example unchanged and instead change the maincore code to add the polling command?
            Please let me know how that worked out for you.

            J 1 Reply Last reply Reply Quote
            • J
              Jamu @CamilaSouza last edited by

              @CamilaSouza Hi Camila!

              I've tried this as well but it gave the same result. As well as that the MessageHello example (with the MP_RECV_POLLING on the main core) gives the same error. Sadly it did not work for me.

              C 1 Reply Last reply Reply Quote
              • C
                CamilaSouza DeveloperWorld @Jamu last edited by

                @Jamu

                I'm having trouble reproducing your problem on my end.

                One thing that I noticed is that the output from your terminal looks different than mine.
                This is what my terminal looks like with the application (MessageData) working correctly:

                Send: id=100 data=0x0000159d
                Recv: id=100 data=0x0000159d : Success
                Send: id=100 data=0x000004e3
                Recv: id=100 data=0x000004e3 : Success
                Send: id=100 data=0x00004606
                Recv: id=100 data=0x00004606 : Success

                This is what it looks like when I try to force an error:

                Send: id=100 data=0x000052f2
                MP.Recv error = -116
                Recv: id=0 data=0x00000000 : Fail
                Send: id=100 data=0x00006e77
                MP.Recv error = -116
                Recv: id=0 data=0x00000000 : Fail
                Send: id=100 data=0x00005ab6
                MP.Recv error = -116
                Recv: id=0 data=0x00000000 : Fail

                You see that either way I get the message with Send: id=xxx data=xxxxxxx and Recv: id=xxx data=xxxxxx

                So a couple of things I'm thinking:
                I'd like to see your terminal when you have MessageData working perfectly and see if it is exactly like mine. Could you send me a picture?
                (This is me trying to investigate if your flash is still intact, otherwise we could try and format it)

                Another thing is you could try to connect to the board using minicom
                minicom -D /dev/ttyUSB0 -b 115200
                We can see board initialization messages here, so we can check if your board is initializing correctly.

                J 1 Reply Last reply Reply Quote
                • J
                  Jamu @CamilaSouza last edited by Jamu

                  @CamilaSouza said in MultiCore MP_RECV_POLLING not working:

                  Could you send me a picture?

                  c6effb81-e0b2-49cc-9a33-65d95909489d-image.png

                  This is the working output that seems as expected

                  EDIT

                  After changing adding MP_RECV_POLLING I get this error:

                  2597a299-3057-4bea-8906-375f15103a6a-image.png

                  C 1 Reply Last reply Reply Quote
                  • C
                    CamilaSouza DeveloperWorld @Jamu last edited by

                    @Jamu

                    Ok. So this exact error happens to me when I put the line MP.RecvTimeout(MP_RECV_POLLING); on the setup of my Sub1 code.
                    When I put this line only on the setup of my Main code it works perfectly.

                    I know you said you already tried it, but I'll ask you to try again and make sure the polling is happening only in the main core. I'm also providing code for both cores so you can see where in the code I made the change.

                    MAIN:

                    /*
                     *  Main.ino - MP Example to communicate message data
                     *  Copyright 2019 Sony Semiconductor Solutions Corporation
                     *
                     *  This library is free software; you can redistribute it and/or
                     *  modify it under the terms of the GNU Lesser General Public
                     *  License as published by the Free Software Foundation; either
                     *  version 2.1 of the License, or (at your option) any later version.
                     *
                     *  This library is distributed in the hope that it will be useful,
                     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
                     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
                     *  Lesser General Public License for more details.
                     *
                     *  You should have received a copy of the GNU Lesser General Public
                     *  License along with this library; if not, write to the Free Software
                     *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
                     */
                    
                    #ifdef SUBCORE
                    #error "Core selection is wrong!!"
                    #endif
                    
                    #include <MP.h>
                    
                    int subcore = 1; /* Communication with SubCore1 */
                    
                    void setup()
                    {
                      int ret = 0;
                    
                      Serial.begin(115200);
                      while (!Serial);
                    
                      /* Launch SubCore1 */
                      ret = MP.begin(subcore);
                      if (ret < 0) {
                        printf("MP.begin error = %d\n", ret);
                      }
                      randomSeed(100);
                      MP.RecvTimeout(MP_RECV_POLLING);
                    }
                    
                    void loop()
                    {
                      int      ret;
                      uint32_t snddata;
                      uint32_t rcvdata;
                      int8_t   sndid = 100; /* user-defined msgid */
                      int8_t   rcvid;
                    
                      snddata = random(32767);
                    
                      /* Echo back from SubCore */
                    
                      printf("Send: id=%d data=0x%08lx\n", sndid, snddata);
                    
                      ret = MP.Send(sndid, snddata, subcore);
                      if (ret < 0) {
                        printf("MP.Send error = %d\n", ret);
                      }
                    
                      /* Timeout 1000 msec */
                      MP.RecvTimeout(1000);
                    
                      ret = MP.Recv(&rcvid, &rcvdata, subcore);
                      if (ret < 0) {
                        printf("MP.Recv error = %d\n", ret);
                      }
                    
                      printf("Recv: id=%d data=0x%08lx : %s\n", rcvid, rcvdata,
                             (snddata == rcvdata) ? "Success" : "Fail");
                    
                      delay(1000);
                    }
                    
                    

                    SUBCORE1

                    /*
                     *  Sub1.ino - MP Example to communicate message data
                     *  Copyright 2019 Sony Semiconductor Solutions Corporation
                     *
                     *  This library is free software; you can redistribute it and/or
                     *  modify it under the terms of the GNU Lesser General Public
                     *  License as published by the Free Software Foundation; either
                     *  version 2.1 of the License, or (at your option) any later version.
                     *
                     *  This library is distributed in the hope that it will be useful,
                     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
                     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
                     *  Lesser General Public License for more details.
                     *
                     *  You should have received a copy of the GNU Lesser General Public
                     *  License along with this library; if not, write to the Free Software
                     *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
                     */
                    
                    #if (SUBCORE != 1)
                    #error "Core selection is wrong!!"
                    #endif
                    
                    #include <MP.h>
                    
                    void setup()
                    {
                      int ret = 0;
                    
                      ret = MP.begin();
                      if (ret < 0) {
                        errorLoop(2);
                      }
                    }
                    
                    void loop()
                    {
                      int      ret;
                      int8_t   msgid;
                      uint32_t msgdata;
                    
                      /* Echo back */
                    
                      ret = MP.Recv(&msgid, &msgdata);
                      if (ret < 0) {
                        errorLoop(3);
                      }
                    
                      ret = MP.Send(msgid, msgdata);
                      if (ret < 0) {
                        errorLoop(4);
                      }
                    }
                    
                    void errorLoop(int num)
                    {
                      int i;
                    
                      while (1) {
                        for (i = 0; i < num; i++) {
                          ledOn(LED0);
                          delay(300);
                          ledOff(LED0);
                          delay(300);
                        }
                        delay(1000);
                      }
                    }
                    
                    1 Reply Last reply Reply Quote
                    • First post
                      Last post
                    Developer World
                    Copyright © 2021 Sony Group Corporation. All rights reserved.
                    • Contact us
                    • Legal