3 Replies Latest reply on Oct 21, 2014 9:32 AM by mikalhart

    Trace support for Arduino programs?

    KurtE

      While looking through the sources ...\hardware\arduino\edison\core\arduino plus the variants, I noticed that a lot of the code has trace support.  It looks like you can modify the main program that call trace_init, to pass in an IP address to will create a socket to log the data out.

       

      Was wondering if there was a simple data logger program setup for this?

       

      And/Or is there a way to setup your run such that the data that is sent to stderr/stdout shows up somewhere.

       

      Thanks

        • 1. Re: Trace support for Arduino programs?
          mikalhart

          Not sure if this is what you are looking for, but we send serial debug traces over the same serial port the kernel uses for debug spew--the connector at the edge of the board--using code like this:

           

          RingBuffer rx_buffer_dbg;

          TTYUARTClass console(&rx_buffer_dbg, 3, false); // Linux debug port

          ...

          void setup()

          {

             delay(10000); // wait for boot to complete...!

             console.begin(115200);

             ...

             console.println("Hello, world!");

             ...

          }

          • 2. Re: Trace support for Arduino programs?
            KurtE

            Thanks, I have not tried using the debug terminal yet from an Arduino like program yet, but it is great to know that I can.

             

            I think I will answer my own question:

            As I mentioned, in the first post, I noticed that a lot of the code (arduino IDE ...)  was sprinkled with calls to a trace facility. example from sysfs.c

             

            int sysfsGpioSetDrive(unsigned int gpio, unsigned int mode)

            {

                FILE *fp = NULL;

                int ret = 0;

                char value[8] = "";

                char fs_path[SYSFS_BUF] = "";

             

                trace_debug("%s: gpio%u, mode=%u", __func__, gpio, mode);

             

                /* Set GPIO direction  */

                snprintf(fs_path, sizeof(fs_path), LINUX_GPIO_DRIVE_FMT, gpio);

                if (NULL == (fp = fopen(fs_path, "rb+"))) {

                    trace_error("err set drive fs_path=%s\n", fs_path);

            ...

             

            You will notice call to trace_debug and later to trace_error.  I was wondering about how Serial1 setup the IO pins associated with it, so I was tracing through the code as to compare how it differed from what the MRAA was doing.  I was noticing that it was alling off to this set drive function, yet I did not find any value in the GPIOnn pin definitions. 

             

            I then noticed that trace.c was setup to allow you to write to a UART or to IP address.  There is define for Journal, but did not find code for it.  Noticed in main.c, that it init it for UART

            // TODO: derive trace level and optional IP from command line

                trace_init(VARIANT_TRACE_LEVEL, 0);

                trace_target_enable(TRACE_TARGET_UART);

             

            Note: the trace_init call creates a thread and a pipe and the like such that it is always there and running   But where was the data going?  I noticed in trace.c that most messages went to STDOUT and errors went to STDERR

             

            Finally I looked more carefully at the start of main and found that it created files for STDOUT and STDERR

             

            So short answer is:

                Trace messages go to: /tmp/log.txt

                Error messages go to: /tmp/log_er.txt

             

            So answer to what I was looking for:

            sysfs-error: err set drive fs_path=/sys/class/gpio/gpio214/drive

            sysfs-error: err set drive fs_path=/sys/class/gpio/gpio214/drive

            sysfs-error: err set drive fs_path=/sys/class/gpio/gpio249/drive

            sysfs-error: err set drive fs_path=/sys/class/gpio/gpio217/drive

            sysfs-error: sysfsGpioSetCurrentPinmux: gpio131, mode=3

            sysfs-error: err set drive fs_path=/sys/class/gpio/gpio214/drive

            There is no drive setting for these IO pins.

             

            Thanks

            • 3. Re: Trace support for Arduino programs?
              mikalhart

              Ah!  And that's good to know too.  Thanks.