SPI error on HLK-7688A Module

I am trying to use SPI on my HLK-7688A module.
I've enabled SPI Support, and SPI_TOOLS in the build, and updated my device.

I fond that I am able to do Write transactions without problem, and I can see the correct activity on the SPI_CS1, SPI_CLK, and SPI_MOSI pins.

However if I try to do a write & read transaction, it fails with errno (EINVAL).
I guess there is something it does not like in my spi_ioc_transfer struct?

Here is my code for writes and write/read operations.

int SpiHandler::spi_write(int fd, uint8_t *buf, ssize_t len)
{
        int ret;
        struct spi_ioc_transfer tr[1];
        memset(tr,0,sizeof(tr));
        
        tr[0].tx_buf = (unsigned long long)buf;
        tr[0].rx_buf = NULL;
        tr[0].len = len;
        tr[0].cs_change = 1; // deslect CS at end of transfer
        
        ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
        printf("SPI_WRite wrote %d bytes with errno at %d\n",ret,errno);
        
        if (ret < 0)
        {
                printf("SPI Write faild:%d\n",ret);
        }
        
        return ret;
}

int SpiHandler::spi_write_read(int fd, uint8_t *bufOut, ssize_t lenOut, uint8_t *bufIn )
{
        int ret;
        struct spi_ioc_transfer tr;
        memset(&tr,0,sizeof(tr));       
        tr.tx_buf = (unsigned long long) bufOut;
        tr.rx_buf = (unsigned long long) bufIn;
        tr.len = lenOut;
        tr.cs_change = 1; // deslect CS at end of transfer

        // Attempting to perform the transfer
        printf("Transferring %d bytes from %p and reading into %p\n",tr.len, (void*)tr.tx_buf, (void*)tr.rx_bu$
        
        ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
        
        if (ret < 0)
        {
                printf("SPI Write/Read failed:%d, %d\n",ret,errno);
        }
        
        return ret;
}

Any suggestions?

This platform doesn't support full-duplex mode, there is a h/w bug in the SPI core which prevents such operations, see: Error when using SPI device on HLK-7688 module - #11 by jeff

1 Like

OK I see - that makes sense.
I can easily update my code to use two transactions, and leave the CS unchaged between them.
Thank you!