2 Replies Latest reply on Jun 7, 2016 8:42 AM by Intel Corporation

    MCU program segfault -- Unhandled exception/interrupt occurred!

    NathanM

      I'm trying to find out the cause of my MCU project crashing, I assume, it's ViperOS task, but I'm unable to find any help with the documentation provided by the MCU SDK as to how to determine what the source of the problem is.

      Pretty much what I have right now is my MCU project waits on receiving a "go" command from Linux side and then setups up GPIO pins direction and just acks any further "go" commands:

      #include "mcu_api.h"
      #include "mcu_errno.h"
      #include <stdint.h>
      #include <string.h>
      
      typedef enum eGPIOs
      {
          GPIO_15 = 15,    //
          GPIO_44 = 44,    // IR sensor
          GPIO_45 = 45,    // button
          GPIO_46 = 46,    //
          GPIO_47 = 47,    //
          GPIO_48 = 48,    //
          GPIO_49 = 49     //
      } eGPIOs;
      
      // GPIOs to be configured for interrupts
      typedef struct tGPIOInt
      {
          int         gpio;
          int         mode;
          uint32_t    timestamp;    // time since last interrupt, non-zero when pending
      } tGPIOInt;
      
      tGPIOInt GPIOs_Int[] =
      {
      //    { GPIO_15, 0, 0 },  //
          { GPIO_44, 0, 0 },    // IR sensor
          { GPIO_45, 0, 0 },    // button
          { GPIO_46, 0, 0 },    //
          { GPIO_47, 0, 0 },    //
          { GPIO_48, 0, 0 },    //
          { GPIO_49, 0, 0 }     //
      };
      
      #define GPIO_INT_COUNT    (sizeof(GPIOs_Int) / sizeof(GPIOs_Int[0]))
      
      
      uint8_t buffer[8];
      
      void mcu_main()
      {
          int      size;
      
      
          debug_print(DBG_INFO, "waiting on go...\n");
      
          // wait for host processor to be ready for us to run
          while (1)
          {
              size = host_receive(buffer, sizeof(buffer));
              if((size > 0) && memmem(buffer, size, "go\n", 3))
                  break;
      
              // check again in 1 second
              mcu_sleep(100);
          }
      
          debug_print(DBG_INFO, "go command received! Setting up GPIOs.\n");
          mcu_sleep(50); // 500ms wait
      
          // setup GPIO interrupts
          for(size_t i=0; i<GPIO_INT_COUNT; i++)
          {
              gpio_setup(GPIOs_Int[i].gpio, 0);
          }
      
          debug_print(DBG_INFO, "GPIOs setup, registering ISRs.\n");
          mcu_sleep(50); // 500ms wait
          
          // do nothing for now
          
          // loop forever
          while (1)
          {
              // wake-up every 100ms and check if any interrupts fired
              mcu_sleep(10 /* X 10ms */);
              
              // do nothing for now
              
              // see if host processor is wanting our attention
              size = host_receive(buffer, sizeof(buffer));
              if((size > 0) && memmem(buffer, size, "go\n", 3))
              {
                  debug_print(DBG_INFO, "acknowledging go command.\n");
                  mcu_sleep(50); // 500ms wait
              }
          }
      }
      

       

      The problem is that as soon as I give the go command:

      # echo "go" > /dev/ttymcu0
      

       

      I get this dumped into the USB serial console (Note: Neither the faulting address nor context ID ever changes between program code changes):

      ***** Unhandled exception/interrupt occurred! *****
      Current context ID   = 0xff10fb34
      Faulting instruction address = 0x00000023
      Fatal task error! Aborting task.
      
      

       

      And all I get is this from the debug serial:

      # cat /dev/ttymcu1
      ( INFO): waiting on go...
      
      

       

      So it appears to crash before the second debug_print() is reached. I put a mcu_sleep() for half a second after each debug_print() just in case that pipe was buffered and didn't get flushed to Linux side until after a couple of ViperOS task context switches.

       

      Anybody from Intel have any ideas as to how to fix this crashing issue?