cancel
Showing results for 
Search instead for 
Did you mean: 

Using HAL_SPI_GetState() for checking when HAL_SPI_Transmit_DMA() is finished

benjaminbrammer9
Associate II
Posted on May 12, 2017 at 18:02

Hi Guys,

I am using the HAL_SPI_Transmit_DMA() function to write my data over SPI. Since I don't want my CS asserted for more time, than the transmission time, or worse for less then the transmission time I check with HAL_SPI_GetState() when the SPI isn't busy anymore.

Sadly this takes quite a lot of time and the whole routine from asserting CS to transmitting data and the deasserting CS is about 10�s. Far too much for my taste for a SPI running at approx. 18MHz.

I have searched a bit in the forum and it seems that this all takes so long because of the HAL implementation and the complex flag and instance checking.

My question now: do you recommend to only work with the HAL API driver or is it better in case of speed to work with the LL drivers or even go another step back and implement everything with register access and custom functions?

In my opinion driver APIs shall make the developper's life much more easier and shall help him not to write every function from the scratch again. So with a slow driver implementation this is not achieved, because in the end, I have to implement everything myself for maximum performance.

Secondly I would like to know if there exists a way to automatically trigger an interrupt when the SPI over DMA has done it's job and jumps after completion into the apropriate ISR, so that I then - after the perfect amount of time - deassert the CS?

Thanks for your help, and beside my little moaning with the HAL driver API, off course STM did a fantastic job with CubeMX and the APIs. If I could make a wish, I would love to have some high performance serial communication APIs in the HAL driver that are implemented minimalistically to achieve best performance and speed.

best regards

Benjamin 

#hal_spi #slow #dma #spi-over-dma
2 REPLIES 2
S.Ma
Principal
Posted on May 12, 2017 at 18:30

It's done for stdlib on STM32F437, however this interrupt based sequencer enables richer SPI under the hood implementation.

https://community.st.com/community/contribute-your-knowledge/blog/2016/12/31/interrupt-based-state-machine

 

The SPI runs at 24 Mbps with SYSCLK = 96MHz

You might find some hints browsing the code. This code uses SPI which only has 8 or 16 bit mode and no FIFO.

Posted on May 12, 2017 at 18:46

thanks for the answer, I will check on that!