5 Replies Latest reply on Dec 16, 2014 8:40 AM by KurtE

    Edison/Arduino USB in server mode - Serial object?  How to debug crash?

    KurtE

      I thought i would finally try out my Port of the Arduino version of the Hexapod code.  I now have Edison mounted on a PhantomX robot, I am using a USB HUB with currently two devices (A USB2AX - servo adapter for AX12 servos, and a USB sound adapter).

       

      I downloaded the program using the WIFI hack so I left the switch for USB to use it as a server.  Program downloaded and crashed.  I tried running it from a putty window and it quickly ended with a segmentation fault.  So it brought to mind a couple of questions, which I will try to answer myself, but help would be appreciated.

       

      a) With USB in server mode, You probably do not have a valid Serial object (My code does use this for debug terminal.  I know I should detect and do something.  So first wondering how the Serial object is configured at this point (does not exist?)  Can I do if(!Serial()) ...

       

      b) Probably need to setup sketch to optionally do debug to a socket or the like...

       

      c) If I try to run /sketch/sketch.elf, I just get a segmentation fault.  How can I setup to find out where. gdb complains that /sketch/sketch is not a ...

      root@Edison:~/Raspberry_Pi/Phoenix_float/PhantomX# gdb /sketch/sketch.elf

      GNU gdb (GDB) 7.6.2

      Copyright (C) 2013 Free Software Foundation, Inc.

      License GPLv3+: GNU GPL version 3 or later....

      This is free software: you are free to change and redistribute it.

      There is NO WARRANTY, to the extent permitted by law.  Type "show copying"

      and "show warranty" for details.

      This GDB was configured as "i586-poky-linux".

      For bug reporting instructions, please see:

      ...

      "/sketch/sketch.elf": not in executable format: File truncated

       

      d) How to get a dump ...  I tried:

      ulimit -c unlimited

        • 1. Re: Edison - Arduino - Arduino IDE - Can you use USB?
          jwestervelt

          I believe that if you leave the switch as-is, where you can program sketches through the USB, that the arduino code will have access to the usb serial port.  I seem to recall having the serial monitor work from within the arduino IDE, but I would honestly need to go back to verify if this is the case or not.  Putting the switch into "server" mode, I believe, would cause the Edison to treat that port as a standard USB port and it would not function as a serial port.

           

          I think /dev/ttyGS0 is the serial port available to the arduino sketch.

          • 2. Re: Edison - Arduino - Arduino IDE - Can you use USB?
            jwestervelt

            For what it is worth, I am doing the following within my sketch and getting output via the USB serial port:

             

            system("echo test > /dev/ttyGS0");

             

            Not sure if that is going to work for you.  I'll poke around with serial later if need be.

            • 3. Re: Edison - Arduino - Arduino IDE - Can you use USB?
              KurtE

              Thanks, I have not had much chance to play on this today,

               

              I know from earlier tests that you can use USB devices.   So the real question can an Arduino program detect if you are in USB Client or Server mode?

               

              I don't notice any differences in the list of ttyDevices regardless of the position of the switch.  (Other than USB2AX device creates /dev/ttyACM0

               

              Also sort of interesting I believe the Serial object does not go directly to /dev/ttyGS0, I believe it is created from the first argument passed in to the program, which I believe by default is something like: /dev/pts/0

               

              I will also dig more

               

              I can always simply change my sketch that some stuff gets displayed on Tft display, maybe have touch button, that when pressed uses the Serial2 object or the like.

               

              Alternatively maybe figure out how to setup a socket, that a program on the PC can connect to.  Would be nice if I could make it somehow compatible with a TTY object, such that maybe you can connect to it with something like Puty maybe with a different port number or the like.

               

              Now back to playing...

              • 4. Re: Edison - Arduino - Arduino IDE - Can you use USB?
                jwestervelt

                This may or may not be of interest to you, but you can use threading in intel's Arduino IDE.  I am doing this with one of my robotics programs.  It kinda makes up for the fact that the Edison isn't really a realtime device at the moment. 

                 

                example...

                 

                void *blinkAnLED(void *) {

                  while (1) {

                    digitalWrite(13,HIGH);

                    delay(500);

                    digitalWrite(13,LOW);

                    delay(500);

                  }

                }   

                 

                setup() {

                  pthread_t ledBlinker;

                  pthread_create(&ledBlinker, NULL, blinkAnLED, NULL);

                }

                 

                loop() {

                  doOtherStuff();
                }

                • 5. Re: Edison - Arduino - Arduino IDE - Can you use USB?
                  KurtE

                  Thanks again,

                   

                  Yep, I am pretty familiar with using threads, also use some of the mutexes and the like.    As for not a real time device...  Yep - It is not an RTOS (wonder if there will be one?), Also there are for sure some performance issues associated with IO.  SPI currently appears to not run more than about 6.25mhz which is bad enough, but also there is a delay between bytes.  Reads/Writes to IO pins are not too bad, but switching things like pin Direction or to enable/disable PU/PD are real slow.  On different threads, I have made changes to underlying Arduino code for pinMode and in some cases sped them up maybe 250%, but still slow... Developers at Intel know about the changes so hopefully these can be incorporated.  So again hopefully the next release things will continue to improve. 

                   

                  I probably gave a bad title to this thread.

                  Probably should have been more like:

                  Edison/Arduino - USB in server mode - How to detect, debug Crashes...   will see if I can edit title ...

                   

                  That is if you are an Arduino program can you detect if Serial object is valid.  That is if the USB switch is in Server mode, Can I detect it?  What happens if I try to read or write to the Serial object.  As far as I could tell, The Serial object is true in either case?  Need to still dig to see where that is defined.  This is if you have code like:

                  if (Serial) {

                  Where is the Serial variable defined.  Is it hard coded, or does it change depending on the position of the switch.  Again from the thread: Using Serialx on Edison

                  the Serial object is based on /dev/ttyGS0.  So far it appears to me, like this device is created regardless of the position of the switch.  Also looking at the IDE code it appears like the serial object is actually created from the 1st parameter passed to the app, which looking at ps output looks like: /dev/pts/0   Which my guess is it is talking through some other process to the actual device.

                   

                  The second part of my question was.  I was finding that my Arduino sketch appears to have crashed.  That is if you so something like:

                  ps | grep sketch

                  The sketch showed up in a zombie state.  So How do I debug where it crashed?   It did not appear to generate any dump.  Is there a way to get a crash dump?  Also can I run it through a debugger like GDB?  I tried loading it, but it complains not valid file.

                   

                  Thanks again.

                   

                  P.S - Will probably go back to debug my Linux version of the program.  Maybe should try setting up an Eclipse version of it, but would need to learn a few more things on working with Eclipse, like can it download over wifi?  Can I do source level debugging (over wifi or other (again USB in server mode)?  Can I have it build multiple like projects.  That is I have my own Arduino like support library and the like.   Also if I am using things like asoundlib, espeak, how to setup the IDE to grab the appropriate headers and libraries...  But that probably should be it's own topic.