2
votes

I am using TFT LCD screen (ILI9163c) which is connected with athros AR9331 module with spi pins. Athros AR9331 is running with OpenWRT linux distribution. So, I am driving my LCD with spidev0.1 using my C application code.

Athros AR9331 board is using same SPI pins for driving flash memory on board, which is handled from kernel.

I have separate chip select pin for LCD to give proper data recognizance for LCD by making it low and high from code, but still sometimes LCD screen affected with garbage when some data transferred (using other script or application) on flash while LCD printing is on going from my code.

I have control on LCD chip select from code but not for flash. so in this case what should i do to handle a situation when operation for both flash and LCD is going parallel.

This is my function code for sending data on LCD using SPIdev0.1.

    void spi_transactor(unsigned int wlength,
                        unsigned int rlength,
                        const unsigned char write_data,
                        int mode)
    {
       int ret;
       struct spi_ioc_transfer xfer[4];
       unsigned char init_reg[1];

       init_reg[0] = write_data;

       if (mode)
       {
          gpio_set_value(_rs, 1);  // DATA 
       }
       else
       {
          gpio_set_value(_rs, 0);  // COMMAND
       }

       memset(xfer, 0, sizeof xfer);

       xfer[0].bits_per_word = 8;
       xfer[0].tx_buf = (unsigned long) &init_reg[0];
       xfer[0].rx_buf = 0;                        //( unsigned long ) &buf_rx[0];
       xfer[0].len = wlength + rlength;
       xfer[0].delay_usecs = 0;
       xfer[0].speed_hz = speedx;               
       //xfer[0].speed_hz = 40000000;            // 40MHZ

 gpio_set_value(_CS, 0);          // SET ChipSELECT LOW    
       ret = ioctl(spi_fd, SPI_IOC_MESSAGE(1), &xfer);     
 gpio_set_value(_CS, 1);          // SET ChipSELECT HIGH 

       (void) ret;
       //DEBUG_PRINT("%d\n",ret);
       //if (ret <= 0) ; 
       //DEBUG_PRINT("ERROR: %s\n", strerror(errno));

    }

i think it can be possible if we can configure my gpio as Chipselect in spidev0.1 driver in kernel... But how i can configure gpio as chipselect in kernel ?

1
Obviously you cannot use both on the same bus at the same time. What you mean by parallel in "what should i do to handle a situation when operation for both flash and LCD is going parallel."?user694733
@user694733 In my device, multiple scripts and codes are running in background (i.e system_logs, certificates_update scripts, FW update scripts etc.) from startup. this codes writes data on flash at random time. so, issue is occurring while i'm printing some image on display and same time data is transferred in flash file from one of the scripts.Logan859
This sounds more like normal concurrency issue, than anything hardware specific. You could replace SPI with any other shared resource, and this will become generic problem. I don't know enough of embedded Linux to answer, but I guess that normal threading tools that offer resource locking/sharing (such as mutexes, semaphores and queues) are what you need.user694733
@Logan859: please show the code that writes to the spidev device. In particular, how do you drive the CS lines and which kernel interface is used for transfers.A.K.
'I have control on LCD chip select from code' - I think this is the problem. You should configure the CS line in the spi device so the kernel knows how to multiplex messages.A.K.

1 Answers

0
votes

i found something similar to this, here...

openWRT custom chipselect GPIO

just registered general GPIO-pin as CS1 for LCD from spi driver and finally i solved my issue.

Thank you @A.K , @user694733