adafruit_ILI9341_STM for SPI2

Please do not post requests
madias
Posts: 813
Joined: Mon Apr 27, 2015 11:26 am
Location: Vienna, Austria

adafruit_ILI9341_STM for SPI2

Post by madias » Sun Apr 17, 2016 7:03 pm

Hello,
cause I needed the TFT on SPI2 I rewrote the library and renamed it to Adafruit_ILI9341_STM_SPI2 so it can easily coexist with the standard lib so if you need it you can run two independent ILI9341's simultaneous. Better example would be to use with a another device on SPI1, like NRF24 (as I did) or SD-Card. Benefit would be to use both DMA channels for SPI. Another benefit is you won't take care of which SPI you are taking to in the sketch, every ILI9341 functions is automatically on SPI2.
Usage is simple: Just put the SPI lines of the TFT module to SPI2, the rest of the pins can be changed by software.
All examples should include the "#include <Adafruit_ILI9341_STM_SPI2.h>", DMA tested successfully (I didn't have to change anything "DMA" related in the code, because of the smart SPI library, hope that's right) , so it runs out of the box.
Attachments
Adafruit_ILI9341_STM_SPI2.zip
(35.91 KiB) Downloaded 107 times

User avatar
WereCatf
Posts: 166
Joined: Sat Apr 16, 2016 5:30 pm

Re: adafruit_ILI9341_STM for SPI2

Post by WereCatf » Sun Apr 17, 2016 7:40 pm

That's a rather clunky approach. Why not just add one more class-constructor to the original adafruit_ILI9341_STM that allows you to specify the SPI-bus to use? Like e.g. Adafruit_ILI9341_STM(uint8_t _SPIBUS, int8_t _CS, int8_t _DC, int8_t _RST = -1)? That's a much cleaner approach and doesn't require multiple copies of the library.

User avatar
mrburnette
Posts: 2190
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: adafruit_ILI9341_STM for SPI2

Post by mrburnette » Sun Apr 17, 2016 9:48 pm

WereCatf wrote:That's a rather clunky approach. <...>
Play nice. "chunky" could be considered an assault on a programmers integrity. In some circles, that would be a 'fighting word.'

Madias wrote the entire DMA implementation for SPI and it was included into the core library about 18 months ago. Then he modified the implementation for multi-instance with DMA and put it in a second library so the community could test but also so that the users of his first approach would not be required to change anything while the testing went on ... but his need was immediate, so as history now shows, we have two libraries.

Please feel free to combine them if you like.

The vast majority of our community have jobs and devotion to the STM32 is on a cycle-steal basis. I'm the lazy bastard and I'm too lazy to care how the libraries were implemented. Actually, I do not utilize host libraries in the normal sense anyway, I incorporate all of the libraries into the sketch folder for 2 reasons:
  • I publish, so I do not want my readers to have to go out and find, download, and install libraries.
  • Libraries evolve and source code needs to adapt, I do not want to have to constantly update my code because someone else made a change.
Ray

User avatar
WereCatf
Posts: 166
Joined: Sat Apr 16, 2016 5:30 pm

Re: adafruit_ILI9341_STM for SPI2

Post by WereCatf » Sun Apr 17, 2016 10:05 pm

mrburnette wrote:Play nice.
... I do.

User avatar
mrburnette
Posts: 2190
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: adafruit_ILI9341_STM for SPI2

Post by mrburnette » Sun Apr 17, 2016 10:10 pm

WereCatf wrote:
mrburnette wrote:Play nice.
... I do.
touché

Ray :D

madias
Posts: 813
Joined: Mon Apr 27, 2015 11:26 am
Location: Vienna, Austria

Re: adafruit_ILI9341_STM for SPI2

Post by madias » Mon Apr 18, 2016 4:16 pm

Ok, while ignoring the comments above, I've recognized, that DMA on SPI2 isn't working as it should. It looks like, its only doing the "normal" transfer. At the first tests, I only saw it was ok, but it's slower than on SPI1. I had a quick look into the SPI library and it seems, like all DMA channels are active since the implementation begun. Have to check it twice, or I need a input.
Ray: The DMA implementation was done by Victor, I've only ported the library (as I can remember).

BTW: Setting different SPI ports is a bit blurry for me:
http://www.stm32duino.com/viewtopic.php ... spi2#p3923

so I guess

Code: Select all

SPIClass SecondSPI(2);
SecondSPI.setClockDivider(SPI_CLOCK_DIV32);
is the cleaner variant, but it's still unclear to me how it incooperate with DMA

PPS: A better approach in this forum is not only to criticize others work (this is ok), but to also present the corrected work as solution here.

User avatar
mrburnette
Posts: 2190
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: adafruit_ILI9341_STM for SPI2

Post by mrburnette » Mon Apr 18, 2016 4:25 pm

madias wrote: <...>
Ray: The DMA implementation was done by Victor, I've only ported the library (as I can remember).
Thank you and a thank-you to Victor, too. I have a difficult time with credits, but both you and Victor have been active with such - and it all is appreciated.

Ray

User avatar
martinayotte
Posts: 1241
Joined: Mon Apr 27, 2015 1:45 pm

Re: adafruit_ILI9341_STM for SPI2

Post by martinayotte » Mon Apr 18, 2016 4:27 pm

That make me think that we didn't hear something from Victor since awhile ...

User avatar
mrburnette
Posts: 2190
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: adafruit_ILI9341_STM for SPI2

Post by mrburnette » Mon Apr 18, 2016 4:35 pm

martinayotte wrote:That make me think that we didn't hear something from Victor since awhile ...
Wow! You are correct:
by victor_pv
Fri Nov 06, 2015 8:24 pm

User avatar
WereCatf
Posts: 166
Joined: Sat Apr 16, 2016 5:30 pm

Re: adafruit_ILI9341_STM for SPI2

Post by WereCatf » Mon Apr 18, 2016 4:35 pm

madias wrote:Ok, while ignoring the comments above, I've recognized, that DMA on SPI2 isn't working as it should. It looks like, its only doing the "normal" transfer. At the first tests, I only saw it was ok, but it's slower than on SPI1.
If I understand the specsheet right, SPI1 and SPI2 run at different speeds, with SPI2 half that of SPI1, so if you're using the same clockdiv it'll obviously result in half the performance. The relevant lines are "APB1:Fmax=24/36MHz" for SPI2 and "APB2:Fmax=48/72MHz" for SPI1 on page 11.

Post Reply