13 Replies Latest reply on Sep 16, 2015 11:31 AM by arfoll

    Can't use GPIO 77 with MRAA

    jamesod

      I'm having a bit of trouble understanding what is going on here. I am using many of the Edison pins as GPIO, and I am initializing them using the MRAA numbers given in this table: mraa: Intel Edison

       

      I am using GPIO-42,40,81,83,80,82,43,78, and 79 without problems, but when I try to use 77 in the same way it does not work.

      According to that table, GPIO-77 = MRAA 39. However when I do this:

       

      mraa::Gpio* ADE_Reset = new mraa::Gpio(39);
      

       

      I get this error on the console:

       

      terminate called after throwing an instance of 'std::invalid_argument'

        what():  Invalid GPIO pin specified

      Aborted

       

      What am I missing here?

        • 1. Re: Can't use GPIO 77 with MRAA
          Intel_Peter

          Hello jamesod,

           

          First I would like to ask you which board are you using? If my assumption is not mistaken you are using a Mini Breakout Board, right?

          Anyway, I just tried it on both boards (Mini Breakout Board & Arduino Expansion Board), and I used MRAA pin 39 (GPIO77) on a simple script similar to a blink. It compiled without any issues on both boards, so I'm thinking this might be related to the MRAA version. I tested it with version 0.7.2. Which one are you using?

           

          Peter.

          • 2. Re: Can't use GPIO 77 with MRAA
            jamesod

            Peter,

             

            I have tried on both the Mini Breakout Board, the Sparkfun Console board, and my own board.

             

            I am using Mraa version 0.7.3. When I flashed the latest Edison image, version 0.7.2 was included, but when I tried to run my program from Eclipse, it said that the version was outdated or something and asked if I wanted to sync versions. I did.

             

            Is this a problem?

            • 3. Re: Can't use GPIO 77 with MRAA
              Intel_Peter

              I doubt it. I just updated my MRAA version just to be sure, and still I got no issues. Can I see your code? I'd like to compile it on my Edison to see if there's a difference or if I get the same result.

               

              Peter.

              • 4. Re: Can't use GPIO 77 with MRAA
                jamesod

                I've tried just using the blink example that is provided with the Eclipse IoT DevKit:

                 

                #include "mraa.hpp"
                
                
                #include <iostream>
                #include <unistd.h>
                
                
                int main()
                {
                  // select onboard LED pin based on the platform type
                  // create a GPIO object from MRAA using it
                  mraa_platform_t platform = mraa_get_platform_type();
                  mraa::Gpio* d_pin = NULL;
                  switch (platform) {
                       case MRAA_INTEL_GALILEO_GEN1:
                            d_pin = new mraa::Gpio(3, true, true);
                            break;
                       case MRAA_INTEL_GALILEO_GEN2:
                            d_pin = new mraa::Gpio(13, true, false);
                            break;
                       case MRAA_INTEL_EDISON_FAB_C:
                            d_pin = new mraa::Gpio(39, true, false);
                            break;
                       default:
                            std::cerr << "Unsupported platform, exiting" << std::endl;
                            return MRAA_ERROR_INVALID_PLATFORM;
                  }
                  if (d_pin == NULL) {
                       std::cerr << "Can't create mraa::Gpio object, exiting" << std::endl;
                       return MRAA_ERROR_UNSPECIFIED;
                  }
                
                
                  // set the pin as output
                  if (d_pin->dir(mraa::DIR_OUT) != MRAA_SUCCESS) {
                       std::cerr << "Can't set digital pin as output, exiting" << std::endl;
                  return MRAA_ERROR_UNSPECIFIED;
                  }
                
                
                  // loop forever toggling the on board LED every second
                  for (;;) {
                  d_pin->write(1);
                  sleep(1);
                  d_pin->write(0);
                  sleep(1);
                  }
                
                
                  return MRAA_SUCCESS;
                }
                

                 

                Same result

                • 5. Re: Can't use GPIO 77 with MRAA
                  jamesod

                  Could this be a hardware issue?

                  If I try this from the console:

                   

                  root@Edison4:~# echo 77 > /sys/class/gpio/export

                   

                  I get:

                   

                  -sh: echo: write error: Device or resource busy

                  • 6. Re: Can't use GPIO 77 with MRAA
                    Intel_Peter

                    I just tried compiling that code with the command "g++ test.cpp -lmraa" and the compiler threw no error. Why don't you try it this way? If you get the same result as me you can create an executable file with the command "g++ test.cpp -o test -lmraa". And that file can be executed with "./test".


                    Peter.

                    • 7. Re: Can't use GPIO 77 with MRAA
                      jamesod

                      Just retried with a different edison to check hardware. Same problem. I will try compiling from the command line like you suggest when I get back to the office tommorow.

                      • 8. Re: Can't use GPIO 77 with MRAA
                        jamesod

                        Tried compiling on command line. It compiles without a problem, but when I run it I get the same Invalid GPIO pin specified error:

                         

                        root@edison:~/test# g++ MraaTest.cpp -o test -lmraa

                        root@edison:~/test# ./test

                        terminate called after throwing an instance of 'std::invalid_argument'

                          what():  Invalid GPIO pin specified

                        Aborted

                         

                        I'm out of ideas. This has happened on two different Edisons both with the latest image. Unfortunately I have some boards on the way that will require this pin to be used so it is too late now to change I/O. I need to get this to work.

                        • 9. Re: Can't use GPIO 77 with MRAA
                          Intel_Peter

                          I'm not sure what's causing this; arfoll might have an idea.

                          arfoll, what do you think about this?

                           

                          Peter.

                          • 10. Re: Can't use GPIO 77 with MRAA
                            arfoll

                            It's probably not clear on the table but GPIO-77 is reserved for the SD card driver so is held by the kernel (see the table it says 'SD'). That means you have to unload the SDIO kernel module before you can use it. Unfortunately the edison kernel is not compiled that way by default so you haev to recompile the kernel and not compile in the sd modules.

                             

                            You can see in /sys/kernel/debug/gpio that gpio-77 is held by sd-cd in-hi.

                            • 11. Re: Can't use GPIO 77 with MRAA
                              jamesod

                              Thanks for the explanation arfoll, but I'm still a bit confused here. Of the pins listed in /sys/kernel/debug/gpio that are also in the table here: mraa/edison.md at master · intel-iot-devkit/mraa · GitHub, there are only four that don't work.

                              The pins that are commented out below do not work.

                              //GP40 = new mraa::Gpio(82, true, false);
                                GP42 = new mraa::Gpio(50, true, false);
                                GP43 = new mraa::Gpio(38, true, false);
                                //GP77 = new mraa::Gpio(39, true, false);
                                GP78 = new mraa::Gpio(52, true, false);
                                GP79 = new mraa::Gpio(53, true, false);
                                GP80 = new mraa::Gpio(54, true, false);
                                GP81 = new mraa::Gpio(55, true, false);
                                GP82 = new mraa::Gpio(40, true, false);
                                GP83 = new mraa::Gpio(41, true, false);
                                //GP111 = new mraa::Gpio(9, true, false);
                                GP128 = new mraa::Gpio(13, true, false);
                                GP129 = new mraa::Gpio(25, true, false);
                                GP130 = new mraa::Gpio(26, true, false);
                                GP131 = new mraa::Gpio(35, true, false);
                                //GP134 = new mraa::Gpio(44, true, false);
                              

                               

                              Is it documented anywhere that these pins don't work with the edison kernel? If so I couldn't find it. I can't figure out why some of these work and some don't. Nothing is mentioned in the  Edison Compute Module Hardware Guide, nothing indicates here: mraa/edison.md at master · intel-iot-devkit/mraa · GitHub that the pins won't work, and some of the reserved pins in /sys/kernel/debug/gpio are able to be used with MRAA. So how is someone to know unless they try them all? I used half a dozen pins from the mraa table and just assumed they were all ok.

                               

                              Now I'm stuck with a couple of bad options to fix this and still hit my deadline. I was planning on recompiling the kernel eventually, but that was something I didn't want to get into until I got my proof of concept prototype finished. Now I have to do it immediately, or hack up traces on my board....

                               

                              Thanks for your help. I'm just growing frustrated with the Edison.

                              • 12. Re: Can't use GPIO 77 with MRAA
                                k4mcv

                                Thanks arfoll for the answer, I would never have guessed that this was the issue. Like jamesod, I already built my PCB assuming the sd pins could be used for gpio, and so I need to get this working.

                                 

                                While trying to recompile the kernel, in the menuconfig window (as described on the last page of the bsp guide), I selected exclude on the "MMC/SD/SDIO card support" line in the Device Drivers section. However, when I try to run bitbake, I get the following errors:

                                 

                                arch/x86/built-in.o: In function `wifi_platform_data_fastirq':

                                /media/kushal/scratch/edison-src/out/linux64/build/tmp/work/edison-poky-linux/linux-yocto/3.10.17-r0/linux/arch/x86/platform/intel-mid/device_libs/platform_wifi.c:76: undefined reference to `sdhci_pdata_set_quirks'

                                drivers/built-in.o:(.data+0xbddc): undefined reference to `mmc_emergency_init'

                                drivers/built-in.o:(.data+0xbde0): undefined reference to `mmc_emergency_write'

                                 

                                I guess it makes sense that the sd and mmc functions are undefined because I removed the MMC/SD/SDIO support module. But, then how am I supposed to recompile the kernel without the SD modules like you suggested?

                                • 13. Re: Can't use GPIO 77 with MRAA
                                  arfoll

                                  Sadly looks like you're going to have to patch the kernel to get this working. Sorry I don't really know enough to understand why the requierment is there.