Issues with spiSend() Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
josesimoes
Posts: 18
Joined: Sat Feb 18, 2017 11:50 am
Has thanked: 9 times
Been thanked: 3 times

Issues with spiSend()

Postby josesimoes » Mon Aug 14, 2017 4:38 pm

Hi,

(this is related with ST_STM32F429I_DISCOVERY board)

I'm trying to use the SPI to write a byte array to a SPI device and keep bumping onto a "DMA failure" exception.
This is write only operation.
If I call spiSend(...) the exception is thrown.
If I call spiStartSendI(...) the code executes without issues.

I've read several forum threads about this SPI and DMA and I've tested this either using the byte array pointer received for tx and also by copying in them to static local vars.

Peeking into the code several questions rise:
- in spi_lld_send why is that the dmaStreamSetTransactionSize(spip->dmarx, n); is (apparently) setting an RX operation of N size when there is none, after all this is a TX operation only?
- also in spi_lld_send isn't there an issue with calling dmaStreamEnable(spip->dmarx); before dmaStreamEnable(spip->dmatx); (after all we are trying to perform a TX operation not an RX)?

I could also only find test cases (in testhal\STM32\STM32F4xx\SPI) that are using spiExchange(), none using 'just' spiStartSend() or spiStartReceive().

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

Re: Issues with spiSend()

Postby Giovanni » Mon Aug 14, 2017 5:21 pm

Hi,

The RX channel is initialized to empty the RX register of data, SPI is always receiving and transmitting at same time, spiSend simply discards received data.

spiSend is used a lot by other drivers like, flash drivers, MMCSD driver etc. It is hard to believe it fails. A DMA error means that one of the DMA pointers tries to access an unmapped memory area, watch your buffers and sizes.

Please use the correct board for support, this one is about discussions regarding RT (the RTOS) the STM32 board would have been more appropriate, moving the topic.

Giovanni

josesimoes
Posts: 18
Joined: Sat Feb 18, 2017 11:50 am
Has thanked: 9 times
Been thanked: 3 times

Re: Issues with spiSend()

Postby josesimoes » Mon Aug 14, 2017 5:54 pm

Thanks for the prompt reply. And for moving the topic to the appropriate section :oops:

As I've wrote on the original post, I've tried to use both the array that the send function receives and also copying that to a local static var.
Here's a code snippet:

Code: Select all

  #if defined(__GNUC__)
  __attribute__((aligned (32)))
  #endif
    static uint8_t tmpBuff[] = { 0x20, 0x30, 0x40, 0x50};
   


and on the send function (after the calls to Spi init, start, etc:

Code: Select all

...
spiSend(_drv, 4, tmpBuff);
...


the execution hits void _unhandled_exception(void)

with the call stack:
void _unhandled_exception(void)
static void spi_lld_serve_rx_interrupt(SPIDriver *spip, uint32_t flags)
OSAL_IRQ_HANDLER(STM32_DMA2_CH3_HANDLER)


in spi_lld_serve_rx_interrupt the execution is is in the line _spi_isr_code(spip);

any further hints you could provide to help me get to the bottom of this?
Thanks!

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

Re: Issues with spiSend()

Postby Giovanni » Mon Aug 14, 2017 6:01 pm

You could check if the DMA channel ISR is linked to the right vector, if not then you could have that unhandled exception. Check the vector name of the DMA ISR, STM32_DMA2_CH3_HANDLER could be wrong.

Giovanni

josesimoes
Posts: 18
Joined: Sat Feb 18, 2017 11:50 am
Has thanked: 9 times
Been thanked: 3 times

Re: Issues with spiSend()

Postby josesimoes » Mon Aug 14, 2017 6:20 pm

Please check the following: in line 245 of hal_spi.h there is this call to

Code: Select all

(spip)->config->end_cb(spip);
which I believe it's the callback.
If one is using SPI_USE_WAIT TRUE there should be no callback defined (this is assert on line 347 of hal_spi.c).

Removing this line and not having the non-existing callback called gets the code flowing and I don't get an exception anymore.
Last edited by josesimoes on Mon Aug 14, 2017 6:35 pm, edited 1 time in total.

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

Re: Issues with spiSend()

Postby Giovanni » Mon Aug 14, 2017 6:34 pm

Good, moving this topic in "bug reports" for analysis and fix.

Giovanni

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

Re: Issues with spiSend()

Postby Giovanni » Mon Aug 14, 2017 6:40 pm

Hi,

The callback is only called if it is not NULL, this is the full code:

Code: Select all

#define _spi_isr_code(spip) {                                               \
  if ((spip)->config->end_cb) {                                             \
    (spip)->state = SPI_COMPLETE;                                           \
    (spip)->config->end_cb(spip);                                           \
    if ((spip)->state == SPI_COMPLETE)                                      \
      (spip)->state = SPI_READY;                                            \
  }                                                                         \
  else                                                                      \
    (spip)->state = SPI_READY;                                              \
  _spi_wakeup_isr(spip);                                                    \
}


If it crashes there then it is not because a NULL callback, it could be a wrong callback address or configuration pointer.

Giovanni

josesimoes
Posts: 18
Joined: Sat Feb 18, 2017 11:50 am
Has thanked: 9 times
Been thanked: 3 times

Re: Issues with spiSend()  Topic is solved

Postby josesimoes » Mon Aug 21, 2017 2:43 pm

This seems to be working now... sill not sure what was the cause...


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 1 guest