cancel
Showing results for 
Search instead for 
Did you mean: 

Help with STM32VL_Discovery and a TFT display

jonathanurbina92
Associate II
Posted on August 23, 2012 at 21:43

The original post was too long to process during our migration. Please click on the attachment to read the original post.
13 REPLIES 13
Posted on September 13, 2012 at 13:02

The code doesn't seem to address the initial conditions of the pins well either.

Most of the bit banging aspects should be easy enough to abstract, and the rest should be a copy of some examples or documentation. I'd focus on the pins and the abstraction.

The STM32F4 example might provide some additional insight, you can attach rather large ZIP files to posts.

No fsmc.. Oh, sorry then.

No need to be sorry, just trying to point out the context of the OP. Not sure the VL-Discovery would have been my board of choice either.

Having some functional code attached would be welcome here, the nature of the forum is people mostly attach broken or dysfunctional code.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
serggorsky
Associate II
Posted on September 13, 2012 at 23:13

First of all you need to call your code somewhere from main().

What do you expect from the code you are not executing? Your main() do nothing except initializing two leds and switching them off. Then you need a right sequence to send your commands and data. For bit-banging you need something like this: 1) define pin set/reset commands. Replace the pins in code with the pins you're using. (Double-check this! )

#define Set_Cs GPIO_SetBits(GPIOC,GPIO_Pin_8);
#define Clr_Cs GPIO_ResetBits(GPIOC,GPIO_Pin_8);
#define Set_Rs GPIO_SetBits(GPIOC,GPIO_Pin_9);
#define Clr_Rs GPIO_ResetBits(GPIOC,GPIO_Pin_9);
#define Set_nWr GPIO_SetBits(GPIOC,GPIO_Pin_10);
#define Clr_nWr GPIO_ResetBits(GPIOC,GPIO_Pin_10);
#define Set_nRd GPIO_SetBits(GPIOC,GPIO_Pin_11);
#define Clr_nRd GPIO_ResetBits(GPIOC,GPIO_Pin_11);
#define Set_Rst GPIO_SetBits(GPIOC,GPIO_Pin_12);
#define Clr_Rst GPIO_ResetBits(GPIOC,GPIO_Pin_12);

2) define data sending commands (replaceGPIOB andGPIOC with your actual ports. Double-check this as well, if you make a mistake here, nothing will work)

#define LCD_WriteCommand(cmd) {Clr_Rs; GPIOB->ODR=((GPIOB->ODR&0x00ff)|(cmd<<8)); GPIOC->ODR=((GPIOC->ODR&0xff00)|(cmd>>8)); Clr_Cs; Clr_nWr; Set_nWr; Set_Cs;};
#define LCD_WriteData(data) {Set_Rs; GPIOB->ODR=((GPIOB->ODR&0x00ff)|(data<<8)); GPIOC->ODR=((GPIOC->ODR&0xff00)|(data>>8)); Clr_nWr; Set_nWr;};

3) Define your TFT data (Read the datasheet carefully! There are a lot of similar displays with different characteristics) If you make a mistake here, your display will probably initialize, but will show garbage or distorted picture. For 7'' panel TY700TFT800480 this defines should be:

/*********************************************************************
* Overview: Image orientation (can be 0, 90, 180, 270 degrees).
*********************************************************************/
#define DISP_ORIENTATION 0
/*********************************************************************
* Overview: Panel Data Width (R,G,B) in (6,6,6)
*********************************************************************/
#define DISP_DATA_WIDTH 18
/*********************************************************************
* Overview: Horizontal and vertical display resolution
* (from the glass datasheet).
*********************************************************************/
#define DISP_HOR_RESOLUTION 800
#define DISP_VER_RESOLUTION 480
/*********************************************************************
* Overview: Horizontal synchronization timing in pixels
* (from the glass datasheet).
*********************************************************************/
#define DISP_HOR_PULSE_WIDTH 1
#define DISP_HOR_BACK_PORCH 210
#define DISP_HOR_FRONT_PORCH 45
/*********************************************************************
* Overview: Vertical synchronization timing in lines
* (from the glass datasheet).
*********************************************************************/
#define DISP_VER_PULSE_WIDTH 1
#define DISP_VER_BACK_PORCH 34 
#define DISP_VER_FRONT_PORCH 10

4) Initialize the display (replace GPIO initialization to use your pins)

void
LCD_Delay(vu32 nCount)
{
nCount = nCount * 1000;
while
(nCount-- != 0);
}
void
LCD_ResetDevice(
void
)
{
GPIO_InitTypeDef GPIO_InitStructure;
//?!?// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; 
// Initialization of Data pins
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
//!?!//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_13;
GPIO_Init(GPIOC, &GPIO_InitStructure);
Set_Rst; 
Set_Cs; 
// SSD1963 is not selected by default
Set_nRd;
Set_nWr;
Clr_Rst;
LCD_Delay(1);
Set_Rst; 
// release from reset state to sleep state
//Set MN(multipliers) of PLL, VCO = crystal freq * (N+1)
//PLL freq = VCO/M with 250MHz < VCO < 800MHz
//The max PLL freq is around 120MHz. To obtain 120MHz as the PLL freq
LCD_WriteCommand(0xE2); 
// Set PLL with OSC = 10MHz (hardware)
// Multiplier N = 35, VCO (>250MHz)= OSC*(N+1), VCO = 360MHz
Clr_Cs;
LCD_WriteData(0x23);
LCD_WriteData(0x02); 
// Divider M = 2, PLL = 360/(M+1) = 120MHz
LCD_WriteData(0x54); 
// Validate M and N values
Set_Cs;
LCD_WriteCommand(0xE0); 
// Start PLL command
Clr_Cs;
LCD_WriteData(0x01); 
// enable PLL
Set_Cs;
LCD_Delay(1); 
// wait stablize
LCD_WriteCommand(0xE0); 
// Start PLL command again
Clr_Cs;
LCD_WriteData(0x03); 
// now, use PLL output as system clock 
Set_Cs;
LCD_WriteCommand(0x01); 
// Soft reset
LCD_Delay(10);
//Set LSHIFT freq, i.e. the DCLK with PLL freq 120MHz set previously
//Typical DCLK for TY700TFT800480 is 3MHz(datasheet), experiment shows 30MHz gives a stable result
//30MHz = 120MHz*(LCDC_FPR+1)/2^20
//LCDC_FPR = 262143 (0x3FFFF)
//Time per line = (DISP_HOR_RESOLUTION+DISP_HOR_PULSE_WIDTH+DISP_HOR_BACK_PORCH+DISP_HOR_FRONT_PORCH)/30 us = 1056/30 = 2us
LCD_WriteCommand(0xE6);
Clr_Cs;
LCD_WriteData(0x04);
LCD_WriteData(0xff);
LCD_WriteData(0xff);
Set_Cs;
//Set panel mode, varies from individual manufacturer
LCD_WriteCommand(0xB0);
Clr_Cs;
LCD_WriteData(0x10); 
// set 18-bit for 7'' panel TY700TFT800480
LCD_WriteData(0x80); 
// set TTL mode
LCD_WriteData((DISP_HOR_RESOLUTION-1)>>8); 
//Set panel size
LCD_WriteData(DISP_HOR_RESOLUTION-1);
LCD_WriteData((DISP_VER_RESOLUTION-1)>>8);
LCD_WriteData(DISP_VER_RESOLUTION-1);
LCD_WriteData(0x00); 
//RGB sequence 
Set_Cs;
//Set horizontal period
LCD_WriteCommand(0xB4);
#define HT (DISP_HOR_RESOLUTION+DISP_HOR_PULSE_WIDTH+DISP_HOR_BACK_PORCH+DISP_HOR_FRONT_PORCH)
Clr_Cs;
LCD_WriteData((HT-1)>>8); 
LCD_WriteData(HT-1);
#define HPS (DISP_HOR_PULSE_WIDTH+DISP_HOR_BACK_PORCH)
LCD_WriteData((HPS-1)>>8);
LCD_WriteData(HPS-1);
LCD_WriteData(DISP_HOR_PULSE_WIDTH-1);
LCD_WriteData(0x00);
LCD_WriteData(0x00);
LCD_WriteData(0x00);
Set_Cs;
//Set vertical period
LCD_WriteCommand(0xB6);
#define VT (DISP_VER_PULSE_WIDTH+DISP_VER_BACK_PORCH+DISP_VER_FRONT_PORCH+DISP_VER_RESOLUTION)
Clr_Cs;
LCD_WriteData((VT-1)>>8);
LCD_WriteData(VT-1);
#define VSP (DISP_VER_PULSE_WIDTH+DISP_VER_BACK_PORCH)
LCD_WriteData((VSP-1)>>8);
LCD_WriteData(VSP-1);
LCD_WriteData(DISP_VER_PULSE_WIDTH-1);
LCD_WriteData(0x00);
LCD_WriteData(0x00);
Set_Cs;
//Set pixel format, i.e. the bpp
LCD_WriteCommand(0x3A);
Clr_Cs;
LCD_WriteData(0x55); 
// set 16bpp
Set_Cs;
//Set pixel data interface
LCD_WriteCommand(0xF0);
Clr_Cs;
LCD_WriteData(0x03); 
//16-bit(565 format) data 

//LCD_WriteData(0x00); //8-bit data for 16bpp

Set_Cs;
 LCD_WriteCommand(0x29); 
// Turn on display; show the image on display 
}

At this time your display should be properly initialized, waiting for data. If ater LCD_ResetDevice() you'll callLCD_WriteData(u16 fillColor) DISP_HOR_RESOLUTION x DISP_VER_RESOLUTION times , your display should fill with fillColor color. If it does, I'll show you how to draw graphics and text on it 🙂
tomstuchlik9
Associate
Posted on January 24, 2013 at 11:27

If it does, I'll show you how to draw graphics and text on it 🙂

Hello there , I tryed to implement your code in to my . There is no errors after compiling , so could you post the rest of code , which will show how to use graphick and fonts , please .

I do not have the display  yet , but a vould like to be redy for next week.

  BR , Tomas .

phlopes
Associate
Posted on February 01, 2013 at 19:01

Hi,

I used some off the tips, to use a 3,5''inches with SSD1963 controller 320x240 and 8bits interface, but I have to change same things so the colors appears correct once the colors in this display have the following format 0xRRGGBB so 24 bits.

I manage to gat work several routines, Line, Rectangule, Text, Full screen color, but I can't get a image .bmp. I've tried some files that I found and tried to generate to create an ''const char pic[]={ ...}, but I believe I missing something about the estructure of .bmp files.

I'm using the STM32-Discovery with an STM32F100xB mic.

www.st.com/stm32-discovery

And programing C on IAR.

So far thats what I got. If this help a little.

This is a test project on IAR for the Kit I mention above, in there you will see that I've used some of the tips, but made some adjustments, for 3,5'', and create some functions the first one is LCD_SendData(to send 24bit color information), and then I've created same new ones with similar names, that the original file to use 24bits color.

But as I said, I've got line, fullscreen, rectangle, but not picture.

I still need help to use pictures.

Hope it helps.

Paulo

________________

Attachments :

*****.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I00X&d=%2Fa%2F0X0000000bS6%2F.DD47mj4CAnAHnyABhYU_AmkYihWgqxOUZP7ZBd2EFY&asPdf=false