Hi, everyone .
I want to connect a spi device with dm355,are there any demo about how to use spi interface ?If not ,can you give some guide on how to use it?
Thanks.
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi, everyone .
I want to connect a spi device with dm355,are there any demo about how to use spi interface ?If not ,can you give some guide on how to use it?
Thanks.
there is an SPI contorller driver located under
.../ti-davinci/drivers/spi
and there is an SPI-based EEPROM block driver which uses the SPI controller driver located under
.../ti-davinci/arch/arm/mach-davinci
the SPI EEPROM block driver provides a /dev/mtdx device node for user space applications to use. Depending on what type of SPI device you plan on including in your design, you may have to need to do something similar; either way, the above directories should serve as good reference code to start from.
Please note that the SPI EEPROM driver for DM355 EVM is included with the DVSDK software. Your can also read more information on this SPI driver in the LSP 2.0 Data Manual (SPRS496.pdf) included in the DVSDK. This document has a brief description of the software architecture, features/constraints, as well as performance benchmarks for this SPI driver. Let us know if this helps and if there is anything else we can assist you with.
Juan,
I'm using the DM355 EVM Board. DVSDK_1_30_00_40.
Thanks for the info. I have read the relevant documents. I have built the SPI driver as a loadable module and checked that it is present using cat /proc/modules, both the SPI modules and the AT25xxA_eeprom are present.
root@192.168.0.203:~# cat /proc/modules
g_file_storage 28980 0 - Live 0xbf016000
musb_hdrc 28516 1 g_file_storage, Live 0xbf00e000
at25xxA_eeprom 4996 0 - Live 0xbf00b000
davinci_spi_master 13276 0 - Live 0xbf006000
spi_bitbang 5728 0 - Live 0xbf003000
davinci_spi_bitbang 6432 1 davinci_spi_master, Live 0xbf000000
I have also checked to see which mtd device the eeprom has been allocated.
root@192.168.0.203:~# cat /proc/mtd
dev: size erasesize name
mtd0: 003c0000 00020000 "bootloader"
mtd1: 00040000 00020000 "params"
mtd2: 00400000 00020000 "kernel"
mtd3: 20000000 00020000 "filesystem1"
mtd4: 5f800000 00020000 "filesystem2"
mtd5: 00002000 00000010 "spi_eeprom"
As a simple test I have used echo 1234 > /dev/mtd5 to write to the eeprom device. And cat /dev/mtd5 to read. Using a logic analyser I can see that the chip select and the SPI bus is in fact doing what I want.
The echo writes data to the EEPROM using the SPI bus, as requested. Subsequent reads, correctly read the data just written. The problem is this read data does not get back to the SPIBUF in the recieve code and gets reported as zero.
The write with debug switched on...
root@192.168.0.203:~# echo 1234 > /dev/mtd5
[Ei davinci_spi_chipselect-121]
[Ex davinci_spi_chipselect-133]
[Ei davinci_spi_bufs_pio-399]
chipselect=0, bytes_per_word=1, t->len=1, conv=1
data to be TX = 0x6
writing into DATA1 register val = 0x10fe0006
***I have transmited...on iteration 1 and buf_val = 0x80000000***
[Ex davinci_spi_bufs_pio-644]
[Ei davinci_spi_chipselect-121]
[Ex davinci_spi_chipselect-133]
[Ei davinci_spi_chipselect-121]
[Ex davinci_spi_chipselect-133]
[Ei davinci_spi_bufs_pio-399]
chipselect=0, bytes_per_word=1, t->len=3, conv=1
data to be TX = 0x2
writing into DATA1 register val = 0x10fe0002
***I have transmited...on iteration 1 and buf_val = 0x80000000***
data to be TX = 0x0
writing into DATA1 register val = 0x10fe0000
***I have transmited...on iteration 2 and buf_val = 0x80000000***
data to be TX = 0x0
writing into DATA1 register val = 0x10fe0000
***I have transmited...on iteration 3 and buf_val = 0x80000000***
[Ex davinci_spi_bufs_pio-644]
[Ei davinci_spi_bufs_pio-399]
chipselect=0, bytes_per_word=1, t->len=5, conv=1
data to be TX = 0x31
writing into DATA1 register val = 0x10fe0031
***I have transmited...on iteration 1 and buf_val = 0x80000000***
data to be TX = 0x32
writing into DATA1 register val = 0x10fe0032
***I have transmited...on iteration 2 and buf_val = 0x80000000***
data to be TX = 0x33
writing into DATA1 register val = 0x10fe0033
***I have transmited...on iteration 3 and buf_val = 0x80000000***
data to be TX = 0x34
writing into DATA1 register val = 0x10fe0034
***I have transmited...on iteration 4 and buf_val = 0x80000000***
data to be TX = 0xa
writing into DATA1 register val = 0x10fe000a
***I have transmited...on iteration 5 and buf_val = 0x80000000***
[Ex davinci_spi_bufs_pio-644]
[Ei davinci_spi_chipselect-121]
[Ex davinci_spi_chipselect-133]
But read response is....
root@192.168.0.203:/opt/hello# cat /dev/mtd5
[Ei davinci_spi_chipselect-121]
[Ex davinci_spi_chipselect-133]
[Ei davinci_spi_bufs_pio-399]
chipselect=0, bytes_per_word=1, t->len=3, conv=1
data to be TX = 0x3
writing into DATA1 register val = 0x10fe0003
***I have transmited...on iteration 1 and buf_val = 0x80000000***
data to be TX = 0x0
writing into DATA1 register val = 0x10fe0000
***I have transmited...on iteration 2 and buf_val = 0x80000000***
data to be TX = 0x0
writing into DATA1 register val = 0x10fe0000
***I have transmited...on iteration 3 and buf_val = 0x80000000***
[Ex davinci_spi_bufs_pio-644]
[Ei davinci_spi_bufs_pio-399]
chipselect=0, bytes_per_word=1, t->len=32, conv=1
In receive
flg_val=0x00000000 & buf_val=0x00000000
While loop count =14
I have got it after 1 iteration buf_val=0x00000000
flg_val=0x00000000
flg_val=0x00000000 & buf_val=0x00000000
While loop count =15
I have got it after 2 iteration buf_val=0x00000000
flg_val=0x00000000
flg_val=0x00000000 & buf_val=0x00000000
While loop count =15
I have got it after 3 iteration buf_val=0x00000000
flg_val=0x00000000
flg_val=0x00000000 & buf_val=0x00000000
While loop count =15
I have got it after 4 iteration buf_val=0x00000000
flg_val=0x00000000
flg_val=0x00000000 & buf_val=0x00000000
While loop count =15
I have got it after 5 iteration buf_val=0x00000000
flg_val=0x00000000
The code in the recieve path is as below...
#if 0
while (davinci_spi->base->SPIBUF &
SPI_SPIBUF_RXEMPTY_MASK) ;
flg_val = davinci_spi->base->SPIFLG;
buf_val = davinci_spi->base->SPIBUF;
#else
buf_val = davinci_spi->base->SPIBUF;
while (buf_val & SPI_SPIBUF_RXEMPTY_MASK){
loopCount++;
buf_val = davinci_spi->base->SPIBUF;
}
flg_val = davinci_spi->base->SPIFLG;
#endif
DEBUG_SPI("flg_val=0x%08X & buf_val=0x%08x\n", flg_val,buf_val);
DEBUG_SPI("While loop count =%d\n",loopCount);
davinci_spi->get_rx(buf_val, davinci_spi);
//davinci_spi->get_rx(0x41,davinci_spi);
DEBUG_SPI("I have got it after %d iteration buf_val=0x%08X\n flg_val=0x%08X\n",i, buf_val, flg_val);
So maybe is was an amonolly due to the command line interpretation, having not used this driver before. So I wrote a standalone app to open the device and read / write data. Same response. Write / Read at the SPIBus is working but doesn't get read correctly from an open file descriptor on the relevant device.
If I change the receive code to force an 'A' return value, then this gets correctly reported by the cat command, and printed on the screen.
Here's my standalone app which gives the same results....
readdata.c
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
int main(){
int eepromfd;
unsigned char loop;
unsigned char data[16];
eepromfd = open("/dev/mtd5",O_RDWR );
if(eepromfd == -1){
printf("cannot open mtd5\n");
return -1;
}
printf("fd is %d\n",eepromfd);
printf("No of Bytes Read = %d\n",read(eepromfd,data,16));
for(loop=0;loop<16;loop++){
if((loop%8)==0){
printf("\n");
}
printf("%02X ",data[loop]);
}
printf("\n");
close(eepromfd);
return 0;
}
writedata.c
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
int main(){
int eepromfd;
unsigned char loop;
unsigned char datain[128];
eepromfd = open("/dev/mtd5",O_RDWR );
if(eepromfd == -1){
printf("cannot open mtd5\n");
return -1;
}
printf("fd is %d\n",eepromfd);
for(loop=0;loop<128;loop++){
datain[loop]=loop;
}
write(eepromfd,datain,128);
printf("Datain Written\n");
close(eepromfd);
return 0;
}
Is it that the interrupt responsible for loading the recieved serial data into SPIBUF is not working??
Any help at this point would be appreciated. As I have run out of ideas now, and getting nowhere with my current approach.
Richard.
Ok,
Problem now resolved. We currently use GPIO32 for output, having looked through the datasheet, there's a typo in SPRUFB3 page 127 which incorrectly instructs to set pinmux 4 bit 1 to 1 for GIO[32].
We think this should really be GIO[102]. Anyhow, this resulted in setting the pinmux4 to 0x00000002 during gpio setup and consequently SPI0_SDI was set as an output.
When using the logic analyser all signals still looked ok as bizarrely the EEPROM was able to drive the SDI line anyway. So from a hardware point of view everything looked fine.
So SPI is now working as intended.
RT
Richard, this is great news. Also, thank you for the feedback on the document; I will investigate and get it corrected appropriately.
Richard:
I was confused about the drivers TI provided,so I wrote a spi driver myself ,and it works well.
If I knew this document(sprs496.pdf) earlier,everything would be much eaiser.Thanks a lot.