RetroBSD

2.11BSD operating system for microcontrollers
It is currently Sat Jul 11, 2020 12:11 pm

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: SPI driver in 375 issue
PostPosted: Mon Sep 21, 2015 6:26 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
With latest 375 fub auto:
Not sure this is a bug - with 369 I ran this code:
Code:
/*  spimes.c
 *  Pito 4/2014 & 9/2015 - just an example on SPI drivers speed measurement
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/spi.h>
#include <sys/time.h>

// Fubarino SD 795 board @80MHz
// SPI2 is the SDcard

#define SPI_DEVNAME         "/dev/spi3" // dummy SPI chip is connected to SPI3
#define SPI_KHZ             20000       // Clock speed 20 MHz
#define SPI_SELPIN          0x0105      // select pin A5

static int spi;                         // SPI driver descriptor

struct timeval  time_info;

void chip_init()
{
    int i, failed;

    spi = open (SPI_DEVNAME, O_RDWR);
    if (spi < 0) {
        perror (SPI_DEVNAME);
        exit (-1);
    }

    ioctl (spi, SPICTL_SETRATE, SPI_KHZ);
    ioctl (spi, SPICTL_SETSELPIN, SPI_SELPIN);

}

unsigned chip_write_byte (unsigned addr, unsigned char byte)
{
    unsigned char data[4];

    data[0] = 0xF0;
    data[1] = addr >> 8;
    data[2] = addr;
    data[3] = byte;
    ioctl (spi, SPICTL_IO8(4), data);
    return 1;
}


int main(){

   int i;
   long t_start, t_end, millis;
   
   chip_init();
   
   printf("START...\r\n");
   
   gettimeofday(&time_info, 0);
   t_start = time_info.tv_sec * 1000000L + time_info.tv_usec;
   
   for(i=0;i<1000000;i++){   
   chip_write_byte(0x5555, 0xAA);
   }
     
   gettimeofday(&time_info, 0);
   t_end = time_info.tv_sec * 1000000L + time_info.tv_usec;
   
   millis = (t_end - t_start) / 1000L;
   
   printf("1mil 4bytes transfers @ 20MHz SPI\r\n");
   printf("Elapsed= %ld msec\r\n", millis);
   printf("SPI speed %ld kbytes/sec\r\n",4*1000000L/millis);
   printf("...STOP\r\n");
   
   return 0;
}

With 375 I get (compiled with SmallerC):
Code:
# ls
spimes.c
# cc -o spimes spimes.c
# ./spimes
/dev/spi3: Operation not supported by device
# ./spimes    <<< with spi1
/dev/spi1: Operation not supported by device
#
#


PS: I can see a lot of changes in SPI driver in 375, almost rewritten :)

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Mon Sep 21, 2015 7:26 pm 
Committer
User avatar

Joined: Wed Oct 10, 2012 11:01 pm
Posts: 1081
Location: Sunnyvale, CA
Port spi3 is not present in the default kernel configuration for Fubarino board. As you can see from fubarino/Config, only spi2 is enabled, and it's occupied by SD card:
Code:
# SPI ports
controller      spi2                        # SD card

# microSD card
device          sd0     at spi2 pin RG9     # select pin

You need to add a line "controller spi3" to the Config file, then run "make reconfig; make" to build the kernel.

May be it makes sense to enable spi3 and uart2 by default. And to disable glcd driver, to avoid any conflict.

Well yes, SPI driver has been extensively modified. Not rewritten though: essentially I just removed all the stuff related to internal descriptor allocation, and replaced it with "spiio" data structure supplied by caller.


Top
 Profile  
 
PostPosted: Mon Sep 21, 2015 7:41 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
Quote:
May be it makes sense to enable spi3 and uart2 by default. And to disable glcd driver, to avoid any conflict.

Why it worked yesterday? I did measurements of the SPI3, ie. 186kb/sec (5MHz SPI) to 254kB/sec (20MHz SPI). And 316kB/sec with 32b SPI..

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Mon Sep 21, 2015 7:53 pm 
Committer
User avatar

Joined: Wed Oct 10, 2012 11:01 pm
Posts: 1081
Location: Sunnyvale, CA
Yesterday it was a bug.
Now it works exactly as expected. :)


Top
 Profile  
 
PostPosted: Mon Sep 21, 2015 7:58 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
Yesterday it was an undocumented feature :P
Plz be so kind and try to enable spi3 and uart2 (I do not have dev env instld here on the company ntbk)..

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Mon Sep 21, 2015 8:13 pm 
Committer
User avatar

Joined: Wed Oct 10, 2012 11:01 pm
Posts: 1081
Location: Sunnyvale, CA
OK, done: see autobuild rev376 when available.
I don't have Fubarino at hand, so I tested it with SDXL board.
Seems to work properly.


Top
 Profile  
 
PostPosted: Tue Sep 22, 2015 7:19 am 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
v376 fub:
With SPI3 and 8bit:
Code:
# cc -o spimes spimes.c
# ./spimes
START...
1mil 4bytes transfers @ 20MHz SPI
Elapsed= 14635 msec
SPI speed 273 kbytes/sec
...STOP
#

It seems it is 9% faster than on Sunday :)

And with 32b write:
Code:
# ./spimes
START...
1mil 4bytes transfers @ 20MHz SPI
Elapsed= 13025 msec
SPI speed 307 kbytes/sec
..


PS: I must admit the work with retrobsd and fubarino is a pleasure today.
Working under win7:
1. download autobuild
2. flash unix.hex with pic32prog
3. format the sdcard with SDformatter
4. write filesystem with WinDiskImager to the sdcard
5. boot retrobsd
6. edit with emg (paste .c source via TeraTerm into emg)
7. compile with SmallerC
8. run
All done in about 3minutes.

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Mon Sep 28, 2015 7:17 pm 
Committer
User avatar

Joined: Wed Oct 10, 2012 11:01 pm
Posts: 1081
Location: Sunnyvale, CA
Pito wrote:
PS: I must admit the work with retrobsd and fubarino is a pleasure today.
Working under win7:
1. download autobuild
2. flash unix.hex with pic32prog
3. format the sdcard with SDformatter
4. write filesystem with WinDiskImager to the sdcard
5. boot retrobsd
6. edit with emg (paste .c source via TeraTerm into emg)
7. compile with SmallerC
8. run
All done in about 3minutes.

Finally we are close to what I'd imagined when I started the project five years ago. :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron




Powered by phpBB® Forum Software © phpBB Group

BSD Daemon used with permission