STM32F4 SPI: DMA Transfer Error Interrupt

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
daniel_s
Posts: 9
Joined: Tue Dec 08, 2015 1:45 pm

STM32F4 SPI: DMA Transfer Error Interrupt

Postby daniel_s » Fri Feb 03, 2017 9:04 am

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

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: STM32F4 SPI: DMA Transfer Error Interrupt

Postby Giovanni » Fri Feb 03, 2017 9:20 am

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

daniel_s
Posts: 9
Joined: Tue Dec 08, 2015 1:45 pm

Re: STM32F4 SPI: DMA Transfer Error Interrupt

Postby daniel_s » Fri Feb 03, 2017 2:25 pm

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)?

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: STM32F4 SPI: DMA Transfer Error Interrupt

Postby Giovanni » Fri Feb 03, 2017 3:07 pm

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

neums
Posts: 137
Joined: Fri May 08, 2015 1:09 pm
Location: Dresden, Germany
Has thanked: 10 times
Been thanked: 5 times

Re: STM32F4 SPI: DMA Transfer Error Interrupt

Postby neums » Thu Mar 09, 2017 8:13 am

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.

neums
Posts: 137
Joined: Fri May 08, 2015 1:09 pm
Location: Dresden, Germany
Has thanked: 10 times
Been thanked: 5 times

Re: STM32F4 SPI: DMA Transfer Error Interrupt

Postby neums » Thu Mar 09, 2017 2:44 pm

Maybe it is possible to reduce the runtime without using the DMA but this has impact to the low level driver

neums
Posts: 137
Joined: Fri May 08, 2015 1:09 pm
Location: Dresden, Germany
Has thanked: 10 times
Been thanked: 5 times

Re: STM32F4 SPI: DMA Transfer Error Interrupt

Postby neums » Fri Mar 31, 2017 7:12 am

Is it possible to introduce a single word send method like the DAC method dacPutChannelX?

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: STM32F4 SPI: DMA Transfer Error Interrupt

Postby Giovanni » Fri Mar 31, 2017 8:12 am

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


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 31 guests