How to set the maximum SPI speed for HAL-Core?

Post here first, or if you can't find a relevant section!
Post Reply
User avatar
blue-man
Posts: 37
Joined: Mon Mar 23, 2020 5:02 pm

How to set the maximum SPI speed for HAL-Core?

Post by blue-man »

I want to use an ILI9341 display and i am glad that it directly works using this example: https://create.arduino.cc/projecthub/te ... lay-78e1c3

But i wonder that the graphics are slower with an Blue-Pill than showed in the Video of the example for an Arduino: https://www.youtube.com/watch?v=my83ggtQfiA

I tried to adjust the SPI-speed like in the example of this thread: viewtopic.php?p=2823#p2823

Code: Select all

  SPI.begin();		//Initialize the SPI_1 port
  SPI.setClockDivider(SPI_CLOCK_DIV2);      // High speed (72 / 2 = 36 MHz SPI_1 speed)
  tft.begin();
but it seems to make no difference.
(It makes no difference if the SPI.setClockDivider is done before or after the tft.begin.)

What i am doing wrong?

Here's the complete example including the compiled output:
ILI9341.zip
SPI Display Test with ILI9341
(84.21 KiB) Downloaded 21 times
by GonzoG » Thu Nov 05, 2020 7:56 pm
No matter how you set SPI. This library has own settings and it's for Arduino AVR boards so it uses 8MHz for SPI speed.
Use this library:
https://github.com/Bodmer/TFT_eSPI
It's for STM32 (also) and you can set SPI speed.
Go to full post
Last edited by blue-man on Thu Nov 05, 2020 5:38 pm, edited 1 time in total.

User avatar
blue-man
Posts: 37
Joined: Mon Mar 23, 2020 5:02 pm

Re: How to set the maximum SPI speed for HAL-Core?

Post by blue-man »

Here are the results of the benchmarks:

Code: Select all

Benchmark                Time (microseconds)
Screen fill              3209532
Text                     186241
Lines                    1690966
Horiz/Vert Lines         267624
Rectangles (outline)     169832
Rectangles (filled)      6662453
Circles (filled)         795866
Circles (outline)        745934
Triangles (outline)      384408
Triangles (filled)       2190194
Rounded rects (outline)  340407
Rounded rects (filled)   6634961
Done!

GonzoG
Posts: 80
Joined: Wed Jan 15, 2020 11:30 am
Answers: 5

Re: How to set the maximum SPI speed for HAL-Core?

Post by GonzoG »

No matter how you set SPI. This library has own settings and it's for Arduino AVR boards so it uses 8MHz for SPI speed.
Use this library:
https://github.com/Bodmer/TFT_eSPI
It's for STM32 (also) and you can set SPI speed.

User avatar
blue-man
Posts: 37
Joined: Mon Mar 23, 2020 5:02 pm

Re: How to set the maximum SPI speed for HAL-Core?

Post by blue-man »

Thank you for the hint!

This library is much better.
There is the same example (TFT_graphicstest_PDQ) with extended tests in it.
The results are now:

Code: Select all

#define SPI_FREQUENCY  55000000

Benchmark                Time (microseconds)
HaD pushColor            1421621
Screen fill              77519
Text                     89028
Pixels                   1786829
Lines                    1855724
Horiz/Vert Lines         41798
Rectangles (outline)     27787
Rectangles (filled)      808001
Circles (filled)         211429
Circles (outline)        286212
Triangles (outline)      108349
Triangles (filled)       372466
Rounded rects (outline)  130403
Rounded rects (filled)   863916
Done!
So a screen fill is now factor 41.4 faster and other operations like circles filled 3.8 faster.
Last edited by blue-man on Fri Nov 06, 2020 9:59 am, edited 4 times in total.

User avatar
blue-man
Posts: 37
Joined: Mon Mar 23, 2020 5:02 pm

Re: How to set the maximum SPI speed for HAL-Core?

Post by blue-man »

What is the correct method to set the SPI speed when the TFT library is not used?

User avatar
fpiSTM
Posts: 848
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 33
Location: Le Mans
Contact:

Re: How to set the maximum SPI speed for HAL-Core?

Post by fpiSTM »

setClockDivider() is deprecated:
https://www.arduino.cc/en/Reference/SPISetClockDivider

SPISettings have to be used instead:
https://www.arduino.cc/en/Reference/SPISettings

User avatar
blue-man
Posts: 37
Joined: Mon Mar 23, 2020 5:02 pm

Re: How to set the maximum SPI speed for HAL-Core?

Post by blue-man »

fpiSTM wrote:
Fri Nov 06, 2020 1:08 pm
SPISettings have to be used instead:
https://www.arduino.cc/en/Reference/SPISettings
O.K. Thanks.
But how the parameters have to be set?

Syntax
SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0))
Note: Best if all 3 settings are constants

SPISettings mySettting(speedMaximum, dataOrder, dataMode)
Note: Best when any setting is a variable''

Parameters
speedMaximum: The maximum speed of communication. For a SPI chip rated up to 20 MHz, use 20000000.


In ~/.arduino15/packages/STM32/hardware/stm32/1.9.0/libraries/SPI/src/utility/spi_com.h i can find

Code: Select all

///@brief specifies the SPI speed bus in HZ.
#define SPI_SPEED_CLOCK_DEFAULT     4000000

#define SPI_SPEED_CLOCK_DIV2_MHZ    ((uint32_t)2)
#define SPI_SPEED_CLOCK_DIV4_MHZ    ((uint32_t)4)
#define SPI_SPEED_CLOCK_DIV8_MHZ    ((uint32_t)8)
#define SPI_SPEED_CLOCK_DIV16_MHZ   ((uint32_t)16)
#define SPI_SPEED_CLOCK_DIV32_MHZ   ((uint32_t)32)
#define SPI_SPEED_CLOCK_DIV64_MHZ   ((uint32_t)64)
#define SPI_SPEED_CLOCK_DIV128_MHZ  ((uint32_t)128)
#define SPI_SPEED_CLOCK_DIV256_MHZ  ((uint32_t)256)
so it is not clear if the settings should be 35000000 for a clock divided by 2 or if the definitions for the divider like SPI_SPEED_CLOCK_DIV2_MHZ are better used?
Last edited by blue-man on Fri Nov 06, 2020 4:41 pm, edited 3 times in total.

User avatar
blue-man
Posts: 37
Joined: Mon Mar 23, 2020 5:02 pm

Re: How to set the maximum SPI speed for HAL-Core?

Post by blue-man »

Is there another recommendation for a better SD library <SD.h> ?

I think here is the same problem setting the SPI-speed like in the TFT library.


Has someone tested this one ?
https://sparklogic.ru/working-ported-li ... t-dma.html
https://github.com/greiman/SdFat
The hardware interface to the SD card should not use a resistor based level shifter. SdFat sets the SPI bus frequency to 8 MHz which results in signal rise times that are too slow for the edge detectors in many newer SD card controllers when resistor voltage dividers are used.

Post Reply

Return to “General discussion”