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.

RTOS/AM3359: PRU SPI very slow

Part Number: AM3359
Other Parts Discussed in Thread: ADS8688

Tool/software: TI-RTOS

Hi TI,

   beaglebone black, processor SDK RTOS 4.2.0.9, ccs 7.4

I ported PRU-SPI to TI-RTOS from ///github.com/.../

However, my PRU-SPI runs quite slow, only about 1Mbps.

I have added the following function to pru_spi.c. Note __delay_cycles(DELAY_CNT) helps to settle down the bit-transfer.

#define DELAY_CNT 20

uint8_t pru_spi_writertestonly(volatile uint32_t *pTxbuf, volatile int tx_cnt)
{
  // write bit to __R30
  int i, j;
  uint8_t data_byte;

  // Set MOSI high
  __R30 = __R30 | (1 << MOSI); // Turn on data bit

  // First assert CS down
  __R30 = __R30 & ~(1 << CS);

  // set clk down
  __R30 = __R30 & ~(1 << CLK); // Turn off clk

  // ---->   Clock out Tx command from MOSI
  // Loop over data words *pTxbuf
  for (i=0; i<tx_cnt; i++) {
    data_byte = (uint8_t) *(pTxbuf+i);

    // Loop over bits in byte
    for (j=0; j<8; j++) {
      // set clk down
      __R30 = __R30 & ~(1 << CLK); // Turn off clk

      // Now set bit
      if ( (data_byte<<j) & 0x80 ) {        // 1 bit
        __R30 = __R30 | (1 << MOSI); // Turn on data bit
      } else {                                       // 0 bit
        __R30 = __R30 & ~(1 << MOSI); // Turn off data bit
      }

      // Delay to let bit settle
      __delay_cycles(DELAY_CNT);

    } // loop over bits

    // Quick delay before next byte
    __delay_cycles(DELAY_CNT);

  } // loop over bytes

  // Set MOSI low while clocking in reply
  __R30 = __R30 & ~(1 << MOSI); // Transmit 0 bit

  // Bring CS back up at end of transaction
  __R30 = __R30 | (1 << CS);

  return 0x00;
}

I have 3 questions to ask,

1. what's the speed limitation of PRU-SPI on am335x?

2. how can I setup bit transfer speed in a systematic way, rather than change __delay_cycles(DELAY_CNT) ?

3. does TI have example projects or any other suggestions for PRU-SPI  than the above approach?

Please advise, thanks in advance

Mike