AnsweredAssumed Answered

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

Question asked by brammer.benjamin on May 12, 2017
Latest reply on May 12, 2017 by KIC8462852 EPIC204278916

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