8 Replies Latest reply on Dec 11, 2014 4:15 AM by xthunderheartx

    Am I using mraa_uart_init() wrong?

    xthunderheartx

      I'm trying to get uart0 working from a C program so that I can talk to a socketmodem.  I found the following example code on github:

       

      #include "stdio.h"
      //! [Interesting]
      #include "mraa.h"
      
      
      int
      main(int argc, char **argv)
      {
          mraa_uart_context uart;
          uart = mraa_uart_init(0);
      
      
          if (uart == NULL) {
              fprintf(stdout, "UART failed to setup\n");
          }
      
      
          mraa_deinit();
          return 0;
      }
      

       

      The call to mraa_uart_init(0) always returns a null.  That can't be good.  Is there some other step required?

        • 1. Re: Am I using mraa_uart_init() wrong?
          CMata_Intel

          Hi xthunderheartx;

           

          Some users have had problems with this because they download the image from that blog, did you download it from the blog or you download it from the Intel website? Also, you could try with this one [mraa.c] and let me know, I'll try to investigate more in the meantime.

           

          Regards;

          CMata

          • 2. Re: Am I using mraa_uart_init() wrong?
            xthunderheartx

            Thanx for the reply CMata_Intel,

             

            I got the Linux image from the Intel IOTDK site.  I did notice that libmraa has been updated since the IOTDK was released.  My image had libmraa.so.0.4.5.  I updated it to 5.2 with opkg on the target itself but now I need to figure out how to update it under my development kit.  Not sure what the process for that is ...

             

            The mraa.c you referenced is the current version on github and I did look at that briefly, but did not have time to determine if that is indeed the version of mraa.c associated with version 4.5 of the library.  I want to get the newest version up and running so I can turn on debugging using mraa_set_log_level(int).  That is actually how I realized I had an older version of the library because when I added a call to it I got an unresolved symbol error from the linker.

             

            Anyway I will continue investigating and any help you can give would be appreciated.

             

            Thx,

             

            Dallas

            • 3. Re: Am I using mraa_uart_init() wrong?
              xthunderheartx

              Solved this one myself I think.  Posted here about it: https://software.intel.com/en-us/forums/topic/535463.

               

              Basically it looks like the pin mapping for the uart doesn't get initialized properly if the board is a GEN2 (revg).  CMata_Intel if you have a chance to look at what I found I'd appreciate it.  I opened an issue on github with more detail: https://github.com/intel-iot-devkit/mraa/issues/36.

               

               

              Thanks,

               

              Dallas

              • 4. Re: Am I using mraa_uart_init() wrong?
                KurtE

                A couple things I would check.  I don't think that MRAA is being initialized.  Not sure if it is expected that all of the different object class init's should implicitly initialize the system or not.

                One thing you might try is to call:

                    mraa_init();

                Before your call: mraa_uart_init(0); 

                 

                Also I don't think it will matter here, but there detection code does:

                if (strncmp(line, "GalileoGen2", 10) == 0) {

                But I think I count 11 characters, but should still match.

                 

                But then more importantly looking at the sources, none of the UART stuff is defined for Gen2...  All of the other board defines have something like:

                b->uart_dev_count = 1;
                b->def_uart_dev = 0;
                b->uart_dev[0].rx = 0;
                b->uart_dev[0].tx = 1;

                 

                But the Gen2 does not.  In addition to the above the actual pins (0, 1) need to have additional information.  Like for the G1, they have stuff like:

                b->pins[0].uart.parent_id = 0;
                b->pins[0].uart.mux_total = 1;
                b->pins[0].uart.mux[0].pin = 40;
                b->pins[0].uart.mux[0].value = 0;

                 

                I might be able to guess the setup, but the G2 pins have additional stuff on them, so would need to figure out the right mux value(s).

                • 5. Re: Am I using mraa_uart_init() wrong?
                  xthunderheartx

                  Yeah Kurt that first bit about element 0&1 of the UART array being uninitialized is the immediate problem for sure.  And I did put a call to mraa_int() at the top of my test code to start with, though I neglected to mention it.  I'm fairly certain it is not needed though.  I think it is fairly clear that the uninitialized UART array will cause mraa_uart_init() to bail ugly via mraa_setup_uart.  I detailed this on github and in some other posts.

                   

                  I missed the bit about the additional stuff wired to pin 0 &1.  I'll look closer.  Problem is though that I haven't figured out how to compile the libmraa under the IOTDK. The instructions for building on the repository are not for that environment (which I have lamented elsewhere).  I got a response from Brendan over on the IoT forum regarding that subject but I think he misunderstood me.  He though I wanted to compile using the IOTDK IDE (Eclipse) when what I meant was I wanted to use the toolchain from the IOTDK.  I'm looking into getting that to work now.

                   

                  Thx for the reply and verification of my thinking.  If you have any additional insight please do share it with me.

                   

                  Dallas

                  • 6. Re: Am I using mraa_uart_init() wrong?
                    xthunderheartx

                    Tom Ingleby fixed this up over on github.  With the changes he made I was able to expose UART0 with a call to mraa_init_uart(0).  Then access to /dev/ttyS0 via termios worked normally.  The changes can be pulled from repo now and will be incorporated into libmraa.0.5.3 looks like.

                     

                    Dallas

                    • 7. Re: Am I using mraa_uart_init() wrong?
                      firmwarengineer

                      Hi,

                       

                      Any sample codes to use the UART0?

                      I saw only simple setup in the github.

                      • 8. Re: Am I using mraa_uart_init() wrong?
                        xthunderheartx

                        It is actually very easy to use once you set it up via libmraa.  After that you can just use the termios to talk to it.  There are many examples of using termios on the net if you haven't used it before. I think the man page even has sample code.  But if that doesn't work for you I can put something up here for ya.