STM32F103C8 & TFT (ili9325)

Working libraries, libraries being ported and related hardware
stevestrong
Posts: 1501
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: STM32F103C8 & TFT (ili9325)

Post by stevestrong » Tue Jul 04, 2017 8:54 am

Please note, that beside changing the pins, you also have to change the masks (couple of lines below changing the pins) in the header file.

I most likely will have to change the strategy here since I see many users confronted with the same issue.

VadimEL
Posts: 66
Joined: Sat Aug 13, 2016 1:28 pm

Re: STM32F103C8 & TFT (ili9325)

Post by VadimEL » Tue Jul 04, 2017 9:02 am

I do not change the pins, i use connecting scheme in

Code: Select all

Adafruit_TFTLCD_8bit_STM32.h
I think it's the right scheme. :D

Code: Select all

#define TFT_DATA_PORT	GPIOB
// Port data bits D0..D7:
// enable only one from below lines corresponding to your HW setup:
#define TFT_DATA_LOW_NIBBLE	1 // take the lower 8 bits: 0..7
//#define TFT_DATA_HIGH_NIBBLE	1 // take the higher 8 bits: 8..15

//Control pins |RD |WR |RS |CS |RST|
#define TFT_CNTRL_PORT	GPIOA
#define TFT_RD			PA0
#define TFT_WR			PA1
#define TFT_RS			PA2
#define TFT_CS			PA3
#define TFT_RST			PB10 //PB0

david.prentice
Posts: 109
Joined: Wed Nov 16, 2016 8:52 am

Re: STM32F103C8 & TFT (ili9325)

Post by david.prentice » Tue Jul 04, 2017 9:33 am

@Vadim,

If you want to use MCUFRIEND_kbv please make these edits:
MCUFRIEND_kbv.h:

Code: Select all

#elif defined(ARDUINO_GENERIC_STM32F103C) || defined(ARDUINO_GENERIC_STM32F103V) || defined(ARDUINO_MAPLE_REV3) || defined(ARDUINO_MAPLE_MINI)
	MCUFRIEND_kbv(int CS=0, int RS=0, int WR=0, int RD=0, int RST=0);  //dummy arguments 
mcufriend_special.h:

Code: Select all

#define USE_VADIMEL_MAPLEMINI
...

Code: Select all

#elif  defined(USE_VADIMEL_MAPLEMINI) && (defined(__STM32F1__) || defined(STM32F103xB)) // MAPLECORE or STM32CORE 
#warning USE_VADIMEL_MAPLEMINI

#if defined(ARDUINO_NUCLEO_F103C8)   //regular CMSIS libraries
#define REGS(x) x
#define GPIO_INIT()   { RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_IOPDEN | RCC_APB2ENR_AFIOEN; \
        AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_1;}
#else                                                                  //weird Maple libraries
#define REGS(x) regs->x
#endif

#define WRITE_DELAY { }
#define READ_DELAY  { RD_ACTIVE; }
#define GROUP_MODE(port, reg, mask, val)  {port->REGS(reg) = (port->REGS(reg) & ~(mask)) | ((mask)&(val)); }
#define GP_OUT(port, reg, mask)           GROUP_MODE(port, reg, mask, 0x33333333)
#define GP_INP(port, reg, mask)           GROUP_MODE(port, reg, mask, 0x44444444)
#define PIN_OUTPUT(port, pin) {\
        if (pin < 8) {GP_OUT(port, CRL, 0xF<<((pin)<<2));} \
        else {GP_OUT(port, CRH, 0xF<<((pin&7)<<2));} \
    }
#define PIN_INPUT(port, pin) { \
        if (pin < 8) { GP_INP(port, CRL, 0xF<<((pin)<<2)); } \
        else { GP_INP(port, CRH, 0xF<<((pin&7)<<2)); } \
    }

#define PIN_HIGH(port, pin)   (port)-> REGS(BSRR) = (1<<(pin))
#define PIN_LOW(port, pin)    (port)-> REGS(BSRR) = (1<<((pin)+16))

#define RD_PORT GPIOA
#define RD_PIN  0
#define WR_PORT GPIOA
#define WR_PIN  1
#define CD_PORT GPIOA
#define CD_PIN  2
#define CS_PORT GPIOA
#define CS_PIN  3
#define RESET_PORT GPIOA
#define RESET_PIN  8

// configure macros for the data pins
#define write_8(d)    { GPIOB->REGS(BSRR) = 0x00FF << 16; GPIOB->REGS(BSRR) = ((d)) & 0x00FF; }
#define read_8()      ((GPIOB->REGS(IDR) & 0x00FF))
//                                         PB7..PB0
#define setWriteDir() {GP_OUT(GPIOB, CRL, 0xFFFFFFFF); }
#define setReadDir()  {GP_INP(GPIOB, CRL, 0xFFFFFFFF); }

#define write8(x)     { write_8(x); WRITE_DELAY; WR_STROBE; }
#define write16(x)    { uint8_t h = (x)>>8, l = x; write8(h); write8(l); }
#define READ_8(dst)   { RD_STROBE; READ_DELAY; dst = read_8(); RD_IDLE; }
#define READ_16(dst)  { uint8_t hi; READ_8(hi); READ_8(dst); dst |= (hi << 8); }

Untested. But it compiles with both ST Core and Maple Core.
It might need some "slowing down" e.g. WRITE_DELAY

David.

stevestrong
Posts: 1501
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: STM32F103C8 & TFT (ili9325)

Post by stevestrong » Tue Jul 04, 2017 9:40 am

The issue must relate to inappropriate init sequence.

In my lib I use data for ILI9328, which may be different from ILI9325.
Having a look to David's lib, the 9325 init sequence is there, and it seems that is used for both 9325 and 9328, so you could maybe import to my lib and try it out.

EDIT
Instead of reading the ID, you could set the ID in the sketch fixed to 0x9328, and begin the library with this value.

VadimEL
Posts: 66
Joined: Sat Aug 13, 2016 1:28 pm

Re: STM32F103C8 & TFT (ili9325)

Post by VadimEL » Tue Jul 04, 2017 11:37 am

David.
white screen :( but in arduino uno r3+this tft LCD, your lib work fine.

Serial output in graphictest_kbv

Code: Select all

Serial took 0ms to start
ID = 0x9325

I read

Code: Select all

17. If you do not have a standard Uno Shield, you can add a SPECIAL to the mcufriend_special.h
    Edit mcufriend_shield.h:  #define USE_SPECIAL
    Edit mcufriend_special.h: e.g. #define USE_MEGA_16BIT_SHIELD
    If your "special" is write-only,  the library can not read the ID.  It always returns 0xD3D3
===========================================================

file mcufriend_shield.h change

Code: Select all

//редактирую
#define USE_VADIMEL_MAPLEMINI             //check for custom drivers
#if defined(USE_VADIMEL_MAPLEMINI)
#include "mcufriend_special.h"
#if !defined(USE_VADIMEL_MAPLEMINI_FAIL)
#warning WE ARE USING A SPECIAL CUSTOM DRIVER
#endif
#endif
#if !defined(USE_VADIMEL_MAPLEMINI) || defined (USE_VADIMEL_MAPLEMINI_FAIL)

file mcufriend_special.h

comment all code

Code: Select all

//#elif defined(__AVR_ATmega2560__) && defined(USE_MEGA_16BIT_SHIELD)
//#warning USE_MEGA_16BIT_SHIELD
...
//#define PIN_OUTPUT(p, b)     *(&p-1) |= (1<<(b))
and paste

Code: Select all

#elif  defined(USE_VADIMEL_MAPLEMINI) && (defined(__STM32F1__) || defined(STM32F103xB)) // MAPLECORE or STM32CORE 
#warning USE_VADIMEL_MAPLEMINI

#if defined(ARDUINO_NUCLEO_F103C8)   //regular CMSIS libraries
#define REGS(x) x
#define GPIO_INIT()   { RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_IOPDEN | RCC_APB2ENR_AFIOEN; \
        AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_1;}
#else                                                                  //weird Maple libraries
#define REGS(x) regs->x
#endif

#define WRITE_DELAY {  }
#define READ_DELAY  { RD_ACTIVE; }
#define GROUP_MODE(port, reg, mask, val)  {port->REGS(reg) = (port->REGS(reg) & ~(mask)) | ((mask)&(val)); }
#define GP_OUT(port, reg, mask)           GROUP_MODE(port, reg, mask, 0x33333333)
#define GP_INP(port, reg, mask)           GROUP_MODE(port, reg, mask, 0x44444444)
#define PIN_OUTPUT(port, pin) {\
        if (pin < 8) {GP_OUT(port, CRL, 0xF<<((pin)<<2));} \
        else {GP_OUT(port, CRH, 0xF<<((pin&7)<<2));} \
    }
#define PIN_INPUT(port, pin) { \
        if (pin < 8) { GP_INP(port, CRL, 0xF<<((pin)<<2)); } \
        else { GP_INP(port, CRH, 0xF<<((pin&7)<<2)); } \
    }

#define PIN_HIGH(port, pin)   (port)-> REGS(BSRR) = (1<<(pin))
#define PIN_LOW(port, pin)    (port)-> REGS(BSRR) = (1<<((pin)+16))

#define RD_PORT GPIOA
#define RD_PIN  0
#define WR_PORT GPIOA
#define WR_PIN  1
#define CD_PORT GPIOA
#define CD_PIN  2
#define CS_PORT GPIOA
#define CS_PIN  3
#define RESET_PORT GPIOA
#define RESET_PIN  8

// configure macros for the data pins
#define write_8(d)    { GPIOB->REGS(BSRR) = 0x00FF << 16; GPIOB->REGS(BSRR) = ((d)) & 0x00FF; }
#define read_8()      ((GPIOB->REGS(IDR) & 0x00FF))
//                                         PB7..PB0
#define setWriteDir() {GP_OUT(GPIOB, CRL, 0xFFFFFFFF); }
#define setReadDir()  {GP_INP(GPIOB, CRL, 0xFFFFFFFF); }

#define write8(x)     { write_8(x); WRITE_DELAY; WR_STROBE; }
#define write16(x)    { uint8_t h = (x)>>8, l = x; write8(h); write8(l); }
#define READ_8(dst)   { RD_STROBE; READ_DELAY; dst = read_8(); RD_IDLE; }
#define READ_16(dst)  { uint8_t hi; READ_8(hi); READ_8(dst); dst |= (hi << 8); }
It compile with out errors.

I have another LCD S6D0154 try it, but the same.

david.prentice
Posts: 109
Joined: Wed Nov 16, 2016 8:52 am

Re: STM32F103C8 & TFT (ili9325)

Post by david.prentice » Tue Jul 04, 2017 12:28 pm

You appear to have done "your own" edits of mcufriend_shield.h

Since you do not have a proper "mating" shield, any special code should be in mcufriend_special.h

I have posted a test_vadim Branch on GitHub. You have to download ZIP and install from ZIP.

David.

VadimEL
Posts: 66
Joined: Sat Aug 13, 2016 1:28 pm

Re: STM32F103C8 & TFT (ili9325)

Post by VadimEL » Tue Jul 04, 2017 1:13 pm

David. Thanks, now mcufriend S6D0154 is work :D
I do not test touch, i connect touch like in scheme to analog pins, and test soon.
Image
=================================
mcufriend 0x9325 the same white screen :mrgreen:

david.prentice
Posts: 109
Joined: Wed Nov 16, 2016 8:52 am

Re: STM32F103C8 & TFT (ili9325)

Post by david.prentice » Tue Jul 04, 2017 2:54 pm

Did you get the MapleMini going with the GitHub branch ?

I would get familiar with the basic TFT and GFX methods first. The existing TouchScreen libraries all have issues with Due, Zero, STM32, Teensy, ... generally due to pinMode() and digitalWrite() "optimisations".

I will publish a bog-standard TouchScreen_kbv version that just uses the Arduino analogRead() and digitalWrite(). It works plenty fast enough on the ARM. And quite honestly, it is not too bad on a Uno.

David.

VadimEL
Posts: 66
Joined: Sat Aug 13, 2016 1:28 pm

Re: STM32F103C8 & TFT (ili9325)

Post by VadimEL » Tue Jul 04, 2017 4:35 pm

I download it from your github https://github.com/prenticedavid/MCUFRI ... test_vadim

saleae logic capture arduino uno r3 and maplemini (forced 0x9325 capture) http://dropmefiles.com/wdtzB

only tft.begin(9325) sequence http://dropmefiles.com/p6Rmp

bill thomson
Posts: 4
Joined: Wed Feb 08, 2017 4:30 pm
Location: Oklahoma, USA
Contact:

Re: STM32F103C8 & TFT (ili9325)

Post by bill thomson » Sun Jul 09, 2017 3:17 pm

VadimEL wrote:
Tue Jul 04, 2017 8:08 am
Iteadmaple cost 33$ :lol: maplemini(STM32F103CBT6) the same hardware and cost 6$ :D
---------------------------------------------------------------------------------------------------------------
The link to their new page has them listed at 5.80 USD
https://www.itead.cc/development-platfo ... maple.html

I bought one about a month ago, shipping time to the US was 12 days.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests