Sorry, you need to enable JavaScript to visit this website.

spi device clock problem

Unsolved
14 posts / 0 new
umer.sabeen's picture
umer.sabeen
Junior(0)
spi device clock problem

Hello
I am working with 7z020 board and using vivado 2015.2 version as well as petalinux 2015.2
I want to send /receive data from spi device, (in half duplex mode)for this purpose,I made the following connections.

set_property PACKAGE_PIN R19 [get_ports SPI0_MOSI_O]
set_property PACKAGE_PIN D18 [get_ports SPI0_SCLK_O]
set_property PACKAGE_PIN L21 [get_ports SPI0_SS_O]

set_property PACKAGE_PIN E21 [get_ports SPI1_MISO_I]
set_property PACKAGE_PIN L18 [get_ports SPI1_SCLK_O]
set_property PACKAGE_PIN F18 [get_ports SPI1_SS_O]

SPI1_SS_O and SPI0_SS_O is always high as I was expecting (will be low during transfer)
but cannot see clock at L18(FMC H4 pin) and D18(FMC G2 pin)
then I tried predefined softwarelike spidev_test.c i made it simple I was trying to run the
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <malloc.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <signal.h>
#include <linux/spi/spidev.h>

#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

static void pabort(const char *s)
{
perror(s);
abort();
}

static const char *device = "/dev/spidev2.0";
static uint8_t mode;
static uint8_t bits = 1;
static uint32_t speed = 18000000;
//static uint16_t delay;

static void transfer(int fd)
{
int ret,i;
uint8_t tx[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x40, 0x00, 0x00, 0x00, 0x00, 0x95,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xAD,
0xF0, 0x0D,
};
uint8_t rx[ARRAY_SIZE(tx)] = {0, };
struct spi_ioc_transfer tr = {
.tx_buf = (unsigned long)tx,
.rx_buf = (unsigned long)rx,
.len = ARRAY_SIZE(tx),
.delay_usecs = 50,
.speed_hz = speed,
.bits_per_word = bits,
.cs_change=1,
};

ret = ioctl(fd, SPI_IOC_MESSAGE(0), &tr);
if (ret < 0)
{
printf("return=%d\n",ret);
pabort("can't send spi message");
}
printf("\nreceive data");
for (ret = 0; ret < ARRAY_SIZE(tx); ret++)
{
if (!(ret % 6))
puts("");
printf("%.2X ", rx[ret]);
}

}

int main(int argc, char *argv[])
{
int ret = 0;
//int i;
int fd;

fd = open(device, O_RDWR);
if (fd < 0)
pabort("can't open device");

mode = SPI_MODE_1;
bits = 1;
speed = 180000000;

/*
* spi mode
*/
ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
if (ret == -1)
pabort("can't set spi mode");

ret = ioctl(fd, SPI_IOC_RD_MODE, &mode);
if (ret == -1)
pabort("can't get spi mode");

/*
* bits per word
*/
ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
if (ret == -1)
pabort("can't set bits per word");

ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
if (ret == -1)
pabort("can't get bits per word");

/*
* max speed hz
*/
ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
if (ret == -1)
pabort("can't set max speed hz");

ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
if (ret == -1)
pabort("can't get max speed hz");

printf("spi mode: %d\n", mode);
printf("bits per word: %d\n", bits);
printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000);
printf("Now transfer data\n");
transfer(fd);

close(fd);

return ret;
}
then i got he following results
spi mode: 1
bits per word: 1
max speed: 180000000 Hz (180000 KHz)
Now transfer data

trying to transfer data

receive data data
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00
where i am doing mistake? why i cant get clock?
Anyone help me
thanks in advance

TroutChaser's picture
TroutChaser
Moderator(18)
Hello,

Hello,
 
Do you know that your hardware design has included the SPI controller and is working correctly? I would suggest exporting your design to the SDK and use the 'Import Examples' link available in the system.mss file to run a simple bare metal example on your hardware to make sure that works before attempting to use it at the OS level.
 
-Gary

umer.sabeen's picture
umer.sabeen
Junior(0)
working with EMIO not MIO

Hello
Did you mean SPI controllers are QSPI?? Quad SPI flash is active in my system
I am trying to use EMIO with SPI
Can I use spips examples??

TroutChaser's picture
TroutChaser
Moderator(18)
If you have enabled the SPI 0

If you have enabled the SPI 0 and/or SPI 1 controller in your Zynq Processing System and connected to the package pins via EMIO then yes, you could us the ps_spi examples. If you look at your project in the SDK and open the system.mss file you should see a link to 'Documentation' and 'Import Examples' next to the ps7_spi controller entry.
 
-Gary

umer.sabeen's picture
umer.sabeen
Junior(0)
For this

For this
I have changed the FSBL(standalone)
and use xspips.c as standalone O/S in new application
but i am using petalinux so I made boot.bin with this fsbl and generate boot.bin
then switch on the board, boot from sd card and boot properly but
mount /dev/mmcb0pk1 /mnt
/mnt/xspips.elf
it gives me illegal instruction error .
is this error because , the sd card is not FAT32 foramtt?thanks

umer.sabeen's picture
umer.sabeen
Junior(0)
One more thing I want to

One more thing I want to mention here for this example our constraint file look like
set_property PACKAGE_PIN R19 [get_ports SPI0_MOSI_O]
set_property PACKAGE_PIN E21 [get_ports SPI0_MISO_I]
set_property PACKAGE_PIN D18 [get_ports SPI0_SCLK_O]
set_property PACKAGE_PIN L21 [get_ports SPI0_SS_O]

TroutChaser's picture
TroutChaser
Moderator(18)
Hello,

Hello,
 
Standalone or 'bare metal' means not using an OS at all. So no PetaLinux. That means there are no Linux type functions like 'mount'.
 
While you could generate an FSBL and an executable .elf file and a bitstream to build a bootable .bin file to run your 'bare metal' spi code I would suggest just using the SDK to load the code via JTAG since you are just trying to test the operation of your hardware.
 
If you are not sure how to do this you could take a look at one of the tutorials available. The most basic is probably the four tutorial set for the MicroZed ( just target the ZedBoard instead) available here: http://zedboard.org/support/design/1519/10
 
If you have the time the Avnet Developing Zynq Software and Hardware Speedway Workshops will give you an in depth understanding of how the Zynq device and the tools work:
http://zedboard.org/support/trainings-and-videos
 
Adam Taylor has a really good set of blog posts that illustrate how to use the Vivado and SDK tool suite to implement a varied set of Zynq functions: http://microzed.org/content/microzed-chronicles
 
-Gary

umer.sabeen's picture
umer.sabeen
Junior(0)
spiPsSelfTestExample() FAILED

Hi
thanks for your response. It really helping me,
As you suggest I tried to do the same but I got the error
Process STDIO not connected to console.
If you'd like to see UART output in this console, please modify STDIO settings in the Run/Debug configuration.
with the help of forum disussion i solved it and got another error
connect STDIO to console :Jtag uart

error opening jtag uart @ localhost-1 I was trying to solve it , the programm run and i got the following result (Idont know how it run, because again i am facing the same problem, and according to forum discussion sdk->xilinxtools->configuration of jtag I cannot find this option in sdk2015.2. any other solution?)

http://s19.postimg.org/8q4292p2r/spi_not_working.png
clearly shows that spiPsSelfTestExample() FAILED

I am using picocom.
is it my fault? or the board has some?
In my opinion I just download the .bit file so error may be in the .bit file.
have a look on the following pictures which shows my project

http://s19.postimg.org/hh6hplj03/ps7_as.png

http://s19.postimg.org/l8g2bwwoj/1_myproject.png

http://s19.postimg.org/n1nkdz78z/2_myproject.png

http://s19.postimg.org/px0nkub8z/3_myproject.png

If you need to know more about my project , ask me.
thanks

umer.sabeen's picture
umer.sabeen
Junior(0)
spiPsSelfTestExample() FAILED

Hi
thanks for your response. It really helping me,
As you suggest I tried to do the same but I got the error
Process STDIO not connected to console.
If you'd like to see UART output in this console, please modify STDIO settings in the Run/Debug configuration.
with the help of forum disussion i solved it and got another error
connect STDIO to console :Jtag uart

error opening jtag uart @ localhost-1 I was trying to solve it , the programm run and i got the following result (Idont know how it run, because again i am facing the same problem, and according to forum discussion sdk->xilinxtools->configuration of jtag I cannot find this option in sdk2015.2. any other solution?)

http://s19.postimg.org/8q4292p2r/spi_not_working.png
clearly shows that spiPsSelfTestExample() FAILED

I am using picocom.
is it my fault? or the board has some?
In my opinion I just download the .bit file so error may be in the .bit file.
have a look on the following pictures which shows my project

http://s19.postimg.org/hh6hplj03/ps7_as.png

http://s19.postimg.org/l8g2bwwoj/1_myproject.png

http://s19.postimg.org/n1nkdz78z/2_myproject.png

http://s19.postimg.org/px0nkub8z/3_myproject.png

If you need to know more about my project , ask me.
thanks

TroutChaser's picture
TroutChaser
Moderator(18)
You seem to be trying to

You seem to be trying to solve several problems at one time, which is always difficult. I am not sure what is causing your STDIO UART issue, but I suspect you made an error at some point in the process. I don't think you want to try to use the JTAG UART since the ZedBoard has UART1 connected to the USB UART available.
 
I would suggest starting with a basic ZedBoard design, like the ones in the MicroZed tutorials above, and get 'hello world' working. Once you have your basic design working with UART connected to your terminal then go back and add the SPI interface to your design. The pictures you posted show that you have connected SPI0_MOSI_O to SPI0_MISO_I which does not make sense and would not work with the constraints you listed above. You should bring the MOSI and MISO signals out as well. 
 
Once you have updated your hardware and exported the new design to the SDK then you can add the ps spi example code and see if the signals work for you.
 
I would really suggest you spend some time going through the Speedway Workshops listed above to get a better understanding of how the system works.
 
-Gary

umer.sabeen's picture
umer.sabeen
Junior(0)
you are right

you are right
I was doing the same I want to bring the MOSI and MISO but I cannot see any data (I made my own software on c). So I decided to check it with following software
https://raw.githubusercontent.com/raspberrypi/linux/rpi-3.10.y/Documenta...
for this i decided to connect both together so that i can see transmitted and received data.
(I will change it again and will back to you soon)

umer.sabeen's picture
umer.sabeen
Junior(0)
error in resetting target

Hello again
I tried alot but I could get even hello world on my screen I get this error

http://s19.postimg.org/5w1tydks3/error.jpg

I just follow eah and every step of the above mention document.
can you help me?

umer.sabeen's picture
umer.sabeen
Junior(0)
error in resetting target

Hello again
I tried alot but I could get even hello world on my screen I get this error

http://s19.postimg.org/5w1tydks3/error.jpg

I just follow eah and every step of the above mention document.
can you help me?

TroutChaser's picture
TroutChaser
Moderator(18)
Hello,

Hello,
 
I will be out of the office until next week.
 
I suggest you go back to the bare metal example and verify that your hardware works before trying to debug hardware, drivers, and Linux level functions (ioctl) all at the same time.
 
-Gary