10 Replies Latest reply on May 7, 2016 7:31 AM by mikejames

    Yocto 3 seems to have broken SPI even worse than 2

    mikejames

      The new update including mraa and Eclipse have changed the way SPI is handled and not all for the better.

      If you connect MOSI to MISO for a loop back and do:

      const struct sched_param priority={1};
      sched_setscheduler(0,SCHED_FIFO,&priority);

          mraa_spi_context spi = mraa_spi_init(0);

          mraa_spi_mode(spi,  MRAA_SPI_MODE0 );

          mraa_spi_frequency(spi,10000);

          mraa_spi_lsbmode(spi, 0);

          mraa_spi_bit_per_word(spi,8);

       

        uint8_t buf[1000];

        uint8_t recv[1000];

        int i

        for(i=0;i<1000;i++)buf[i]=i;

       

      int n=1000;

      mraa_result_t res=mraa_spi_transfer_buf (spi, buf, recv,n);

        for(i=0;i<n;i++){

          if(recv[i]!=buf[i])printf("error %d , %d,%d \n",recv[i],buf[i],i);

        }

          mraa_spi_stop(spi);

        return MRAA_SUCCESS;

      }

       

      That is send 1000 bytes round the loopback it works for earlier versions of Yocto but it prints errors for after the second byte for the new version.

      If you reduce n to 3 then it works i.e. you can send 3 bytes correctly but not more. This seems to happen irrespective of the clock speed.

        • 1. Re: Yocto 3 seems to have broken SPI even worse than 2
          mikejames

          I should have made clear that its the Intel IoT Developer Kit 3.0 and the new firmware that I'm using.

          And it the mini expansion board not Arduino board that is in use.

          • 2. Re: Yocto 3 seems to have broken SPI even worse than 2
            Intel Corporation
            This message was posted on behalf of Intel Corporation

            Hi mikejames,

            Thank you for reporting this issue. We'll review this and come back with an update as soon as possible.

            Regards,
            Diego

            • 3. Re: Yocto 3 seems to have broken SPI even worse than 2
              Chunguang

              Hello James,

              Our team works for Edison platform(BSP related). But we are not familiar with MRAA coding, Can you provide completed code, and it will help us to reproduce issue more easier.

               

              Thanks very much!

              • 4. Re: Yocto 3 seems to have broken SPI even worse than 2
                Chunguang.Chen

                We reproduced this issue.

                The root cause is that the frequency you set for SPI is too small10K). Recommend you to set this value more than 1MHz, and the MAX value can be supported to 24MHz

                    mraa_spi_frequency(spi,10000);  --->Change value from 10000 to 1000000, it works

                 

                The transfer method in Yocto release 2 is using Polling, and it can not satisfy high performance required.

                And now we enabled DMA transferring, the transfer performance can be improved a lot, but it also require to using more higher clock frequency.

                 

                Hope it can help you, thanks~

                • 5. Re: Yocto 3 seems to have broken SPI even worse than 2
                  mikejames

                  I've tried it at a range of speeds up to 24 Mhz and more - and I get the same wrong behaviour.

                  What version of the software are you using?

                  • 6. Re: Yocto 3 seems to have broken SPI even worse than 2
                    Chunguang.Chen

                    I don't know what exact version you have on you side.

                    Edison source code is fully open sourced, In order to keep the some code base, I suggest you following below steps to pull the latest Edison source code, and have a try with clock frequency 1MHz.

                     

                     

                    Quick Start

                    ===========

                     

                    1- Prepare your workspace:

                    $ mkdir my_Edison_Workspace

                     

                    2- Get this layer:

                    $ git clone git://git.yoctoproject.org/meta-intel-edison

                     

                    3- Make things easier with 'make':

                    $ ln -s meta-intel-edison/utils/Makefile.mk Makefile

                     

                    4- Download all the needed dependencies:

                    $ make setup

                     

                    5- Build Intel Edison Yocto distribution:

                    $ make edison-image

                     

                    6- Flash the board:

                    $ make flash

                    • 7. Re: Yocto 3 seems to have broken SPI even worse than 2
                      Chunguang.Chen

                      The test environment we adopted is that:

                      0. Loopback MOSI to MISO

                       

                      1. Copy source code below, and save as file "test-spi.c" and then push it to edison board

                       

                      2. Login Edison by UART or SSH, and then Build code with the command here:

                      gcc -o test-spi  test-spi.c -lmraa

                       

                      3. Run executable binary

                         ./test-spi

                       

                      ---------------------------------------Source Code------------------------------------

                      #include <mraa.h>

                      int main()

                      {

                         const struct sched_param priority={1};

                        sched_setscheduler(0,SCHED_FIFO,&priority);

                          mraa_spi_context spi = mraa_spi_init(0);

                          mraa_spi_mode(spi,  MRAA_SPI_MODE0 );

                          mraa_spi_frequency(spi,1000000);

                          mraa_spi_lsbmode(spi, 0);

                          mraa_spi_bit_per_word(spi,8);

                        uint8_t buf[1000];

                        uint8_t recv[1000];

                        int i;

                        for(i=0;i<1000;i++)

                          buf[i]=i;

                      int n=100;

                      mraa_result_t res=mraa_spi_transfer_buf (spi, buf, recv,n);

                        for(i=0;i<n;i++){

                          if(recv[i]!=buf[i])printf("error Rev: %d , Send: %d, NO: %d \n",recv[i], buf[i], i);

                          else

                          printf("----OK---- %d , %d,%d \n",recv[i],buf[i],i);

                        }

                          mraa_spi_stop(spi);

                        return MRAA_SUCCESS;

                      }

                      • 8. Re: Yocto 3 seems to have broken SPI even worse than 2
                        mikejames

                        I cant see any difference between your code and the one I'm trying

                        but I copy and pasted it and it behaves exactly like my code.

                         

                        I am using the latest OS image that is available and I cant do anything else other than use the publicly available image for the project.

                        In addition I am restricted to a Windows development system so building the OS isn't easy.

                        It seems to me that the only possibility is that you are using something ahead of the current release which still leaves everyone installing the official release with a big SPI problem.

                        You need to realize that unlike Intel engineers most of us simply use and often have to use the official release on the download page.
                        What this means is that SPI might not be broken in a future version of the OS - but currently it is.

                        • 9. Re: Yocto 3 seems to have broken SPI even worse than 2
                          Chunguang.Chen

                          The main difference is changing spi frequency from 10KHz you used to 1MHz. Others are the same.

                          mraa_spi_frequency(spi,10000); 10KHz

                          mraa_spi_frequency(spi,1000000); 1MHz

                           

                          Are you downloading the edison release from this link ?

                          IoT - Intel® Edison Board Download | Intel® Developer Zone

                           

                          In that page, it provided Release 3.0 Yocto complete image.

                          Intel® Edison Board Firmware Software Release 3.0
                          Release 3.0 Yocto* complete image
                          http://iotdk.intel.com/repos/3.0/sources

                          I flashed this image to Edison Arduino board, and checked the release version as below:

                          root@edison:~# cat /etc/version

                          201603141535

                           

                          And then tried it again as the steps I provided to you, and the result is seems good. Please help double check it again, thanks~

                           

                          The test environment we adopted is that:

                          0. Loopback MOSI to MISO

                           

                          1. Copy source code below, and save as file "test-spi.c" and then push it to edison board

                           

                          2. Login Edison by UART or SSH, and then Build code with the command here:

                          gcc -o test-spi  test-spi.c -lmraa

                           

                          3. Run executable binary

                             ./test-spi

                          • 10. Re: Yocto 3 seems to have broken SPI even worse than 2
                            mikejames

                            I decided that the only way to settle the matter was a complete fresh start.

                            I downloaded the image and installed it again - although as far as I can tell the image was the same as the one I was already using.

                            Even so - yes you are correct when the clock speed is 1Mhz or higher the program works.

                            It fails however if you increase the buffer to 5K but this isn't unreasonable and yes you can most certainly use the Edison SPI bus for real tasks.

                            For clock rates lower than 1Mhz I have implemented a software emulation and that works well for devices that can't go as fast as 1Mhz - which is the problem I had in the first place.

                             

                            Thank you for your efforts.