2008-05-06 18:12:37     SPI Chip Select Problems

Document created by Aaronwu Employee on Aug 8, 2013
Version 1Show Document
  • View in full screen mode

2008-05-06 18:12:37     SPI Chip Select Problems

Cameron Barfield (UNITED STATES)

Message: 55586   

 

Sort of a continuation of my previous post.

 

On our custom board (based on BF537 stamp reference design), we have an m25p128 SPI flash on SPI 0 CS 1. We just added another entry to stamp.c (copied m25p80 and changed the flash size) and use the m25p80 driver.

 

We also have an LCD (Samsung S6B0724) on SPI 0 CS 7. We've written our own driver for this.

 

The flash is working great on its own. The LCD is working great on its own. The problem is that if the flash is mounted (the SPI device actually opened) and we write to the LCD, both chip select lines toggle in sync with each other.

 

If I access the flash without having opened the LCD, the LCD's chip select line idles as it should.

 

If I access the flash with having opened the LCD, the LCD's chip select line idles as it should.

 

If I open and write to the LCD without having mounted the flash, the flash's chip select line idles as it should.

 

If I open and write to the LCD with having mounted the flash, the flash's chip select line toggles in sync with the LCD's chip select line.

 

I've added quite a few printks at various places in the LCD driver, and it definitely knows its supposed to use CS 7 and not CS 1 (spi->chip_select == 7 every time I check it).

 

Two of us have been banging our heads on this for quite a while now and any ideas would be appreciated. If you need to see the code, let me know (can't release the LCD interface to the public; NDAs, etc.).

 

 

 

 

 

 

QuoteReplyEditDelete

 

 

2008-05-09 03:47:23     Re: SPI Chip Select Problems

Norbert van Bolhuis (NETHERLANDS)

Message: 55658   

 

I'm investigating chip_select behaviour too.

 

Did you investigate (put printk's in) spi_bfin5xx.c ?

 

Assuming PFx is configured for SPI_SELECT function (MUX=00, FER=1), it all depends

 

on the SPI_FLAG setting. I guess your CPHA=0, in this case the SPI hardware controls

 

SPI_SELECT and toggles it for every tranferred word (that seems to be my problem).

 

Maybe more than one FLSx bit is set in the SPI_FLAG register while doing

 

your SPI transfer for LCD, this would explain the synchronous SPI_SELECT line behaviour

 

(for LCD *and* flash).

 

 

QuoteReplyEditDelete

 

 

2008-05-09 11:46:09     Re: SPI Chip Select Problems

Cameron Barfield (UNITED STATES)

Message: 55678   

 

I'll take a look at the SPI_FLAG. I'd started to dig deeper, but got sidetracked by some other projects.

 

I'm still new to the whole linux hardware driver scene, but I'd imagine that if this were the problem I'd see the flash's chip select toggle regardless of whether or not the flash driver had been opened.

 

 

QuoteReplyEditDelete

 

 

2008-05-09 13:37:04     Re: SPI Chip Select Problems

Cameron Barfield (UNITED STATES)

Message: 55682   

 

Added some printk statements to cs_active() and cs_deactive in spi_bfin5xx.c

 

Here's the printout for mounting the flash (before the LCD driver is opened):

 

        cs_active: flag=ff02

        cs_active: chip->flag=fd02

        cs_active: writing flag fd02

        cs_active: flag=fd02

        cs_active: chip->flag=fd02

        cs_active: writing flag fd02

        cs_active: flag=fd02

        cs_active: chip->flag=fd02

        cs_active: writing flag fd02

        cs_deactive: flag=fd02

        cs_deactive: chip->flag=fd02

        cs_deactive: writing flag ff02

        cs_deactive: flag=ff02

        cs_deactive: chip->flag=fd02

        cs_deactive: writing flag ff02

 

A bit odd that it activates three times and deactivates twice, but I don't imagine it causing any problems.

 

 

Here's the printout for writing to the LCD after mounting the flash:

 

        cs_active: flag=ff82

        cs_active: chip->flag=7f80

        cs_active: writing flag 7f82

        cs_active: flag=7f82

        cs_active: chip->flag=7f80

        cs_active: writing flag 7f82

        cs_deactive: flag=7f82

        cs_deactive: chip->flag=7f80

        cs_deactive: writing flag ff82

        cs_deactive: flag=ff82

        cs_deactive: chip->flag=7f80

        cs_deactive: writing flag ff82                                                                                                                    

 

In both instances, it appears that the spi_bfin5xx driver is reading and writing the correct values to and from the SPI_FLG register. If I'm reading page 10-42 of the hardware reference manual correctly, SSEL 1 and 7 are enabled, but the LCD is only turning on and off SSEL 7.

 

 

QuoteReplyEditDelete

 

 

2008-05-09 14:02:27     Re: SPI Chip Select Problems

Mike Frysinger (UNITED STATES)

Message: 55685   

 

what are your SPI settings for each device in your board resources file ?  if CPHA is 0, then the SPI_FLG should not be setting both FLS1 and FLS7 at the same time (0x82).

QuoteReplyEditDelete

 

 

2008-05-09 14:20:28     Re: SPI Chip Select Problems

Cameron Barfield (UNITED STATES)

Message: 55687   

 

.mode is set to SPI_MODE_3 for the flash, and it looks like we forgot to set it for the LCD.

 

I'll play around with the mode settings for the LCD, but how would setting the phase affect which chip select lines are toggled?

 

 

 

 

QuoteReplyEditDelete

 

 

2008-05-09 14:30:35     Re: SPI Chip Select Problems

Mike Frysinger (UNITED STATES)

Message: 55688   

 

i dont believe the modes need to be the same for every device.  the bus driver should reconfigure things automatically when switching communication between devices.

 

regardless though, i dont think it makes sense for any of the FLS bits to be set simultaneously.  so it may be a bug in the SPI bus driver.  Bryan will have to take a look.

QuoteReplyEditDelete

 

 

2008-05-09 14:49:12     Re: SPI Chip Select Problems

Cameron Barfield (UNITED STATES)

Message: 55691   

 

I set the mode to SPI_MODE_3 for the LCD (what it should have been) and the chip select line stopped toggling, but I get the same output from my printk statements.

 

I think the cs_active() and cs_deactive functions are behaving correctly:

 

 

 

     cs_active: flag=ff82

 

     cs_active: writing flag 7f82

 

"I want to write to the LCD, so activate the LCD chip select line. I don't want to activate the other chip select lines, but I don't want to flat out disable them either. That's why I'll respect the lower byte that's already in the register."

 

That logic makes sense to me, anyway.

 

I realize it's probably a pretty bad thing to run an SPI device without setting an SPI mode, but I still don't see why changing that affects whether or not the driver toggles other chip select lines. That sounds like a bug, but I'm pretty sure it's not in spi_bfin5xx.

 

 

QuoteReplyEditDelete

 

 

2008-05-09 14:57:11     Re: SPI Chip Select Problems

Mike Frysinger (UNITED STATES)

Message: 55692   

 

i think you'd see the same behavior if you had one operating in mode 3 or mode 1, and another operating in mode 0 or mode 2.  your observation is probably indicative of the intention: for CPHA=1, you can get away with toggling FLG while leaving FLS, but for CPHA=0, you have to toggle FLS as FLG is driven completely by hardware.

QuoteReplyEditDelete

 

 

2008-09-25 02:12:17     Re: SPI Chip Select Problems

Mike Frysinger (UNITED STATES)

Message: 62677   

 

if you guys are still having SPI CS issues with trunk, please follow up here:

http://blackfin.uclinux.org/gf/tracker/4097

 

a dev looked into the issue and was unable to reproduce things

QuoteReplyEditDelete

 

 

2008-10-15 19:26:08     Re: SPI Chip Select Problems

Steve Strobel (UNITED STATES)

Message: 63729   

 

Mike Frysinger wrote:

 

> if you guys are still having SPI CS issues with trunk, please follow up here:

> http://blackfin.uclinux.org/gf/tracker/4097

> a dev looked into the issue and was unable to reproduce things

I am seeing behavior very similar to what Cameron reported (on apparently similar hardware), and just posted a followup in the tracker. Is it also helpful to post a note here, or will postings to the tracker be noticed? Steve

QuoteReplyEditDelete

 

 

2008-10-15 21:18:00     Re: SPI Chip Select Problems

Mike Frysinger (UNITED STATES)

Message: 63731   

 

keep all info on the tracker item please ... much easier to coordinate that way

Attachments

    Outcomes