Feature request: set value of dummytx in spi_lld.c

Use this forum for requesting small changes in ChibiOS. Large changes should be discussed in the development forum. This forum is NOT for support.
Tinkerer
Posts: 19
Joined: Wed Apr 19, 2017 2:47 pm
Has thanked: 4 times

Feature request: set value of dummytx in spi_lld.c

Postby Tinkerer » Mon May 22, 2017 1:58 pm

Dear readers,

I'm implementing a driver for an ASIC that exchanges a lot of data. There's a 2-byte address to be written, then data is exchanged. The requirement for receiving data is that the MOSI data is zero until the last byte is read; this is called the 'termination byte' and should be 0xFF.

The SPI_DI signal (MOSI) is used for termination of the read access by the SPI master. For the last
data byte, the SPI master has to set SPI_DI to high (Read Termination byte = 0xFF), so the slave will
not prefetch the next read data internally. If SPI_DI is low during a data byte transfer, at least one
more byte will be read by the master afterwards.



Unfortunately 'SpiReceive()' sends 0xFF by default for SpiReceive. I have now changed this in spi_lld.c for my architecture (STM32), but I don't like messing around in the LLD drivers, code portability becomes impossible that way.

I'd like to request a feature that makes it possible to override the default value of the dummytx byte, maybe in halconf.h? This way the code would be portable. Otherwise, I'd have to use SpiExchange and reserve memory for the largest message that I expect to receive (I feel a bug coming...) and fill that with my preferred MOSI character.

If you see another solution to make my code portable: I'm all ears.

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Feature request: set value of dummytx in spi_lld.c

Postby Giovanni » Mon May 22, 2017 2:22 pm

Hi,

Moving in "bug reports". Note that it would be an STM32-specific feature, not part of the SPI driver requirements.

Giovanni

Tinkerer
Posts: 19
Joined: Wed Apr 19, 2017 2:47 pm
Has thanked: 4 times

Re: Feature request: set value of dummytx in spi_lld.c

Postby Tinkerer » Mon May 22, 2017 2:39 pm

Okay, thanks.

Doesn't this apply to other architectures aswell? I took a short look in the Kinetis implementation spi_lld.c, where I found this:

Code: Select all

static uint16_t dmaTxDummy = 0xFFFF;


Code: Select all

    /* Configure TX DMA */
    if (spip->txbuf) {
      DMA->TCD[KINETIS_SPI0_TX_DMA_CHANNEL].SADDR =  (uint32_t)spip->txbuf;
      DMA->TCD[KINETIS_SPI0_TX_DMA_CHANNEL].SOFF = spip->word_size;
    } else {
      DMA->TCD[KINETIS_SPI0_TX_DMA_CHANNEL].SADDR =  (uint32_t)&dmaTxDummy;
      DMA->TCD[KINETIS_SPI0_TX_DMA_CHANNEL].SOFF = 0;
    }


I guess I would have run into the same issue there, wouldn't I?

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Feature request: set value of dummytx in spi_lld.c

Postby Giovanni » Mon May 22, 2017 3:43 pm

It simply can't be implemented on some micros, on Atmel T91 I had to allocate a 512 bytes buffer filled with 0xFF because the DMA cannot be programmed to not increase the source pointer. Another problem is that I only maintain directly the STM32 port, it would mean imposing changes to the other maintainers.

Giovanni

Tinkerer
Posts: 19
Joined: Wed Apr 19, 2017 2:47 pm
Has thanked: 4 times

Re: Feature request: set value of dummytx in spi_lld.c

Postby Tinkerer » Tue May 23, 2017 9:34 am

OK, clear; thanks for the update.


Return to “Small Change Requests”

Who is online

Users browsing this forum: No registered users and 31 guests