<div dir="ltr"><p class="MsoNormal" style="font-size:12.8px;direction:ltr"><span style="font-size:9.5pt;font-family:Arial,sans-serif;background-image:initial;background-repeat:initial">Hi all,</span><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif"></span></p><p class="MsoNormal" style="font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:9.5pt;font-family:Arial,sans-serif"> </span></p><p class="MsoNormal" style="font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:9.5pt;font-family:Arial,sans-serif">I&#39;m trying to write a kernel device driver for a Freescale imx6 processor based board.</span></p><p class="MsoNormal" style="font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:9.5pt;font-family:Arial,sans-serif">This driver is using spi to communicate with a radio module (using linux spi.c).</span></p><p class="MsoNormal" style="font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:9.5pt;font-family:Arial,sans-serif">I managed to wr/rd from the module, however once I&#39;m trying to read more than 64 bytes I&#39;m getting coruppted data. here are some details:</span></p><p class="MsoNormal" style="font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:9.5pt;font-family:Arial,sans-serif"> </span></p><p class="MsoNormal" style="margin-bottom:12pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:9.5pt;font-family:Arial,sans-serif"><br>The SPI reading process goes as follows:<br><br>1.      Interrupt function is invoked from SPI device via dedicated GPIO line.<br><br>2.       The interrupt function performs asynchronous SPI read in the following order:<br><br>2.1   radio_trx_end_callback is called, as it is the registered call back function.<br><br>2.2   radio_trx_end_callback calls hal_frame_read function which prepares spi_message and spi_transfer structures and fill them with relevant data: spi_device , data tx, transfer len , complete handler , …<br><br>3.      The read itself  is done by calling to function spi_async<br><br>4.      The completion handler function is called and prints the read message, but trying to read more than 64 bytes in one transaction causes the read data to be corrupted.<br><br>Any idea why am I seeing this behavior ?<br><br>Is there (in Linux) any definition for the size to be read via the SPI ?<br><br>The relevant variables and functions can be seen below:<br><br>Thanks in advance for helping..<br><br>__________________________</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">uint8_t rx_buf[200];</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">uint8_t reg[200] = {HAL_TRX_CMD_FR, 0xff, 0xff};</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">struct spi_transfer transfer;</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">struct spi_message  spi_msg;</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif"> </span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">// interrupt function</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">//-----------------------------------------------------------------------------------------------------------------------</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">static irq_handler_t radio_trx_end_callback(unsigned int irq, void *dev_id, struct pt_regs *regs)</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">{</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">    hal_frame_read(irq, dev_id);</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">    return (irq_handler_t) IRQ_HANDLED;      // Announce that the IRQ has been handled correctly</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">}</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif"> </span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">//read function</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">//-----------------------------------------------------------------------------------------------------------------------</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">void hal_frame_read(unsigned int irq, void *dev_id)</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">{</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        int status;</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        spi_device-&gt;irq = irq;</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        spi_message_init(&amp;spi_msg);</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        spi_msg.spi = spi_device;</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        spi_msg.complete = rf_rx_completion_handler;</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        spi_msg.context = NULL;</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        memset((uint8_t*)&amp;transfer, 0, sizeof(transfer));</span></p><p class="MsoNormal" style="font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif"> </span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        memset(rx_buf, 0xFF, sizeof(rx_buf));</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        memset(reg, 0xFF, sizeof(reg));</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        reg[0] = HAL_TRX_CMD_FR;</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        transfer.tx_buf = reg;</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        transfer.len =64;</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        transfer.rx_buf = rx_buf;</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        spi_message_add_tail(&amp;transfer, &amp;spi_msg);</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif"> </span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        memset(rx_buf, 0x0, sizeof(rx_buf));</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        status = spi_async(spi_device, &amp;spi_msg);</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">    return;</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">}</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif"> </span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">//read completion handler</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">//-----------------------------------------------------------------------------------------------------------------------</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">static void rf_rx_completion_handler(void *arg)</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">{</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        int ii;</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif"> </span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;text-indent:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">//print the received message</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;text-indent:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">printk(&quot;\npure message: rx_buf [1]-2=%02X\n      &quot;, rx_buf [1]-2);</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        for (ii=0; ii&lt; rx_buf [1]-2; ii++)</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">                        printk(&quot;%02X &quot;, rx_buf [2+ii]);</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif"> </span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif"> </span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        printk(&quot;\nframe len=%X actual len=%X status=%i\n&quot;,spi_msg.frame_length, spi_msg.actual_length, spi_msg.status);</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif"> </span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">        send_up_rf_event_to_workque(TRX_END_EVENT);</span></p><p class="MsoNormal" style="margin-left:18pt;font-size:12.8px;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">}</span></p></div>