Page 1 of 1

STM32F4 SPI: DMA Transfer Error Interrupt

Posted: Fri Feb 03, 2017 9:04 am
by daniel_s
Hello,
I'm using SPI2 of STM32F407 series to send data to a DAC module each 50us.
After some seconds, system is halted due to an Transfer Error Interrupt Flag (TEIF), which was detected in function spi_lld_serve_rx_interrupt(). This function was called by Vector78, which is the IRQ Handler for DMA Stream (1,3) (#define in mcuconf: #define STM32_SPI_SPI2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3)).
So I don't get, why a SPI RX interrupt is called (and why actually activated?), I just want to send data. Furthermore, i don't get why a transfer error is generated. A transmission of one SPI data block takes about 5us, so enough time with a cycle of 50us.

SPI_send_time.JPG


By the way: Why does it take so long, until ChipSelect is set/reset (It is set via hal_lib_spi_select(&hal_lib_spi_2_hdl)).

Regards,
Daniel

Re: STM32F4 SPI: DMA Transfer Error Interrupt

Posted: Fri Feb 03, 2017 9:20 am
by Giovanni
Hi,

Are debug options enabled in chconf.h? those could give an hint about the problem.

I don't know why CS takes so long, is the code compiled with optimizations? are clocks initialized correctly?

Note that you should never call spi_lld_ functions directly, use the official interfaces.

Giovanni

Re: STM32F4 SPI: DMA Transfer Error Interrupt

Posted: Fri Feb 03, 2017 2:25 pm
by daniel_s
Hi Giovanni,
thanks for your fast response.

Are debug options enabled in chconf.h? those could give an hint about the problem.


I don't use the Chibi-OS as Kernel. I'm working OS-less. I enabled OSAL_DBG_ENABLE_ASSERTS and OSAL_DBG_ENABLE_CHECKS in osalconf.h, but I didn't get on with it until now.

I don't know why CS takes so long, is the code compiled with optimizations? are clocks initialized correctly?

I don't use code optimizations. SYSCLK is set to 168Mhz, APB1 is clocked with 42Mhz. With the used prescaler of 4, I get a SPI frequency of ~10Mhz.

Note that you should never call spi_lld_ functions directly, use the official interfaces

Yes, sorry for that. I meant function call to spiSelect().

I don't understand why function call to spi_lld_serve_rx_interrupt() is executed. I don't want to receive data, I just want to send data via SPI. Do you have an explanation for it? Might a transfer error occur due to timing problems (when I send 4 channels to DAC module instead of 1 each 50us, the transfer interrupt happens more likely)?

Re: STM32F4 SPI: DMA Transfer Error Interrupt

Posted: Fri Feb 03, 2017 3:07 pm
by Giovanni
The driver enables the DMA interrupt regardless if the callback is enabled or not.

DMA errors could be caused by DMA accessing unmapped memory or by starting an operation while the driver is still sending old data.

Giovanni

Re: STM32F4 SPI: DMA Transfer Error Interrupt

Posted: Thu Mar 09, 2017 8:13 am
by neums
Hi,
@daniel_s: i can reproduce your image of your first post. What you see is not the time to set the chip select. It is the runtime of the function spiStartSend.

Re: STM32F4 SPI: DMA Transfer Error Interrupt

Posted: Thu Mar 09, 2017 2:44 pm
by neums
Maybe it is possible to reduce the runtime without using the DMA but this has impact to the low level driver

Re: STM32F4 SPI: DMA Transfer Error Interrupt

Posted: Fri Mar 31, 2017 7:12 am
by neums
Is it possible to introduce a single word send method like the DAC method dacPutChannelX?

Re: STM32F4 SPI: DMA Transfer Error Interrupt

Posted: Fri Mar 31, 2017 8:12 am
by Giovanni
Hi,

There is already a polled function in the SPI driver, it is best used when transferring small data and low latency is required.

spiPolledExchange()

Giovanni