10 years, 7 months ago.

SPI functions slow?

Hi,

I noticed very slow performances on spi write (no DMA) in comparison to FR401 board, something like 3 times slower, so i digged a little but i've not yet spot where is the (eventual)overhead. I'm referring to the time it takes to poll TXE flag, write DR, poll RXNE flag, read DR and probalby all the calls/jumps here and there. I saw FR302 cmsis drivers are different from the ones of FR402, maybe i'll take a look deeper, in the meantime i just observed what happens if i comment out acquire() in the SPI.c api at line 56 (sorry for stupid question, in which occasion is it needed?) http://mbed.org/users/mbed_official/code/mbed-src/file/e752b4ee7de1/common/SPI.cpp

or if i set APB1 clock prescaler to 1 at line 441 here http://mbed.org/users/mbed_official/code/mbed-src/file/e752b4ee7de1/targets/cmsis/TARGET_STM/TARGET_NUCLEO_F302R8/system_stm32f30x.c (sorry for another stupid question, what pro/cons of having APB1 at pclk/2 or pclk/1?)

here is sample code

[Repository '/users/Geremia/code/SPI_overhead_test/' not found]

Here some results of FR401 and FR302 with or without acquire(), with APB1 at pclk/1 or pclk/2, verified with an external Logic Analyzer

-------------------------------------------
//F302 SPI2 (APB1, 32MHz)

std
SPI job time: 1000ns  Overhead: 2657ns

no acquire
SPI job time: 1000ns  Overhead: 2064ns // acquire() took 593ns

APB1 64MHz
SPI job time: 1000ns  Overhead: 2267ns // 390ns faster

no acquire, APB1 64MHz
SPI job time: 1000ns  Overhead: 1829ns // acquire() took 438ns

----------------------------------------
//F401 SPI1 (APB2, 84MHz)

std
SPI job time: 762ns  Overhead: 822ns

no acquire
SPI job time: 762ns  Overhead: 584ns // acquire() took 238ns

---------------------------------------
//F401 SPI2 (APB1, 42MHz)

std
SPI job time: 762ns  Overhead: 858ns

no acquire
SPI job time: 762ns  Overhead: 620ns // acquire() took 238ns

APB1 84MHz
SPI job time: 762ns  Overhead: 823ns // 35ns faster

no acquire, APB1 84MHz
SPI job time: 762ns  Overhead: 585ns // acquire() took 238ns

FR302 runs at 64MHz while FR401 at 84MHz, but time differences are not of the same ratio. Why it gains so much (390ns) in FR302 if i double APB1 clock, while it does not matter so much (35ns) for FR401? Is there some big difference in the MCUs architecture which i'm probably missing, or is it about code overhead in HAL libs?

Thanks for any hints.

Question relating to:

Affordable and flexible platform to ease prototyping using a STM32F302R8T6 microcontroller.
Be the first to answer this question.