Adafruit ILI9341 SPI for stm32duino

Working libraries, libraries being ported and related hardware
Post Reply
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Adafruit ILI9341 SPI for stm32duino

Post by ag123 »

This is an (yet another) implementation of Adafruit ILI9341 SPI lcd library for STM32duino official STM core and libmaple (roger's and steve's mainly F4) core.

I've attempted a 'multi-core' (STM official, steve's libmaple (F4) (also in roger's core F4), and roger's (F1) libmaple) implementation
https://github.com/ag88/Adafruit_ILI9341_SPI_stm32duino

I attempted to use hardware features (SPI - that is 'standard', using SPI.h and SPI.cpp 'arduinoish' interfaces, and i used features in the 'dialect'
to gain access to DMA etc). And the other thing I've attempted is to use bit banding to toggle the CS and DC (data / command) pins.

the results of using SPI, DMA and bit banding is an almost doubled performance on Steve's libmaple F4 (and Roger's for F4)
on stm32f401ccu blackpill as compared to Adafruit original with hardware SPI and SPI_HAS_TRANSACTION define.

Code: Select all

Benchmark (microseconds) Adafruit        this  
                         stm32f401ccu    stm32f401ccu
                         libmaple        libmaple
Screen fill              476799          154057
Text                     41574           28803
Lines                    352653          172626
Horiz/Vert Lines         41711           15210
Rectangles (outline)     26464           10875
Rectangles (filled)      990327          321102
Circles (filled)         138760          91825
Circles (outline)        156673          105738
Triangles (outline)      79426           46922
Triangles (filled)       339544          152668
sum                      2643931         1099826
and as usual this won't be complete without a youtube video :lol:
https://youtu.be/7Ey1U36YtY0

the use of bit banding apparently means that this won't work on Cortex M0 mcus (stm32f0xx) and only works in Cortex M3 (stm32f1xx), Cortex M4 (stm32f4xx) and above.

currently only tested on:
libmaple (rogers's, steve's) stm32f401ccu 84mhz blackpill
libmaple (rogers's, steve's) stm32f103c{8,b} 72mhz maple mini clone
STM official stm32f401ccu 84mhz blackpill
more details in the repository readme
https://github.com/ag88/Adafruit_ILI9341_SPI_stm32duino
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Adafruit ILI9341 SPI for stm32duino

Post by ag123 »

note that these days there are many Adafruit ILI9341 'clones' libs and what i've done is just another one
https://github.com/search?q=adafruit+il ... positories
many choices :lol:
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Adafruit ILI9341 SPI for stm32duino

Post by ag123 »

just found out that what i've done in my implementation using hardware bit banding is called 'fast pin io'
if one is using the original Adafruit ILI9341 libs
you may like to explore the defines
USE_FAST_PINIO
HAS_PORT_SET_CLR
https://github.com/adafruit/Adafruit-GF ... t_SPITFT.h
https://github.com/adafruit/Adafruit-GF ... SPITFT.cpp
https://github.com/adafruit/Adafruit_ILI9341
at your own risk though. using hardware bit banding accounts for quite significant speedups toggling the CS and DC (data/command) pins.
but they fall flat the moment you use a mcu that don't have that. it just 'don't work'
cortex M3 (stm32f1xx), M4 (stm32f4xx) and higher etc have bit banding and i simply use them in my lib leaving no if defs.
if you happen to use an mcu that doesn't do bit banding with my implementation
you can try defining in Adafruit_ILI9341_STM.h

Code: Select all

/* note bit banding is used here */
	inline void dc_command() { *dc_addr = 0; } // 0
	inline void dc_data()    { *dc_addr = 1; } // 1
	inline void cs_clear()   { *cs_addr = 0; }
	inline void cs_set()     { *cs_addr = 1; }
as

Code: Select all

	inline void dc_command() { digitalWrite(_dc,0); } // 0
	inline void dc_data()    { digitalWrite(_dc,1); } // 1
	inline void cs_clear()   { digitalWrite(_cs,0); }
	inline void cs_set()     { digitalWrite(_cs,1); }
of course that is (a lot) slower, but it may at least make it work, hope it helps.
Post Reply

Return to “Libraries & Hardware”