本帖最后由 wenyangzeng 于 2016-1-21 11:09 编辑
一、方案名称:基于GD32F207的解码JPEG图片显示和STemWin移植 二、方案介绍: 使用GD32F207开发板进行FSMC驱动TFT液晶模块的JPEG图片解码显示,由于JPEG格式相对于BMP格式占用内存空间小,可以一次将多幅JPEG图片数据直接编译进代码中,供函数调用,由于显示过程需要解码,MCU处理速度要足够快。而GD32F207因其更快的运算速度,用来解码JPEG很合适。本方案实现了解码JPEG图片数据在TFT显示的功能。同时实现了STemWin移植。 三、方案结构图
四、设计应用描述及心得总结 1、JPEG图片解码显示 方案中使用SSD1289TFT液晶模块作显示屏用,分辨率320×240,驱动方式使用静态存储方式16位数据总线的FSMC,使用了FMCS的FSMC_Bank1_NORSRAM4。硬件的连接见下图:
采用杜邦线连接开发板插针与TFT插针,由于这片开发板的16位FSMC数据引线的D11(PE14)悬空没有引出,给硬件连接造成不少麻烦。
方案中预先制作了7幅JPEG图片,通过BIN2C.EXE转换出JPEG图片数据文件供代码编译,同时下载一个jpegdecode.c文件供调用。演示效果见视频。由于GD32F207的运行速度较快,刚开始运行的图片显示效果很不理想,屏幕约1/3出现花屏。
后来经过摸索,发现是FSMC总线时钟和数据的时序相位有误差所致。经过试验,对FSMC各种时序的延时进行调整,最终得到满意的效果:
p.EXMC_AsynAddressSetupTime = 0x00;
p.EXMC_AsynAddressHoldTime = 0x02;
p.EXMC_AsynDataSetupTime = 0x03;
p.EXMC_BusLatency =0x00;
p.EXMC_SynCLKDivision = 0x00;
p.EXMC_SynDataLatency = 0x00;
2、STemWin移植 在上述硬件连接下,还对该开发板进行了STemWin移植,虽然STemWin移植不是十分成功,运行到一半就死机了,但总算是移植还是有点结果,屏幕能显示图像、能够动起来了。 移植过程试过几种编译环境,只有采用STM32CUbeMX在MDK5下能勉强运行。 代码中如果有“LCD.h”、”LCD.C”、“GUI.H”同名的文件必须另起新文件名。 STM32CUbeMX的配置中选择STM32F103ZET6,需要配置的选项有”SYS”、”CRC”、“FSMC”和“RCC”,见下图: 要注意那个CRC是必须的。
芯片配置
Optinos-Utilities
工程添加STemWin库文件
Options-Debug
运行结果见视频,下图是死机后进入的循环。由于水平有限,不能找出死机的原因,敬请高手指导。
六、方案代码 - //JPEG解码部分代码
- void LCD_CtrlLinesConfig(void)
- {
- GPIO_InitPara GPIO_InitStructure;
- EXMC_NORSRAMInitPara EXMC_NORSRAMInitStructure;
- EXMC_NORSRAMTimingInitPara p;
-
- /* EXMC clock enable */
- RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_EXMC, ENABLE);
- /*GPIO clock enable */
- RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOB |RCC_APB2PERIPH_GPIOC | RCC_APB2PERIPH_GPIOD | RCC_APB2PERIPH_GPIOE |
- RCC_APB2PERIPH_GPIOF | RCC_APB2PERIPH_GPIOG | RCC_APB2PERIPH_AF, ENABLE);
- /* Config GPIO port */
- GPIO_InitStructure.GPIO_Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 |
- GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_14 |
- GPIO_PIN_15;
- GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
- GPIO_Init(GPIOD, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 |
- GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 |
- GPIO_PIN_15;
- GPIO_Init(GPIOE, &GPIO_InitStructure);
- //Set PF.00(A0 (RS)) as alternate function push pull
- GPIO_InitStructure.GPIO_Pin = GPIO_PIN_0;
- GPIO_Init(GPIOF, &GPIO_InitStructure);
- //Set PG.12(NE4 (LCD/CS)) as alternate function push pull - CE3(LCD /CS)
- GPIO_InitStructure.GPIO_Pin = GPIO_PIN_12;
- GPIO_Init(GPIOG, &GPIO_InitStructure);
- p.EXMC_AsynAddressSetupTime = 0x08;
- p.EXMC_AsynAddressHoldTime = 0x09;
- p.EXMC_AsynDataSetupTime = 0x08;
- p.EXMC_BusLatency =0x09;
- p.EXMC_SynCLKDivision = 0x06;
- p.EXMC_SynDataLatency = 0;
- p.EXMC_AsynAccessMode = EXMC_ACCESS_MODE_A ;
- EXMC_NORSRAMInitStructure.EXMC_NORSRAMBank = EXMC_BANK1_NORSRAM4;
- EXMC_NORSRAMInitStructure.EXMC_AddressDataMux = EXMC_ADDRESS_DATA_MUX_DISABLE;
- EXMC_NORSRAMInitStructure.EXMC_MemoryType = EXMC_MEMORY_TYPE_SRAM;
- EXMC_NORSRAMInitStructure.EXMC_DatabusWidth = EXMC_DATABUS_WIDTH_16B;
- EXMC_NORSRAMInitStructure.EXMC_BurstMode = EXMC_BURST_MODE_DISABLE;
- EXMC_NORSRAMInitStructure.EXMC_AsynWait = EXMC_ASYN_WAIT_DISABLE;
- EXMC_NORSRAMInitStructure.EXMC_NWAITPolarity = EXMC_NWAIT_POLARITY_LOW;
-
- EXMC_NORSRAMInitStructure.EXMC_WrapBurstMode = EXMC_WRAP_BURST_MODE_DISABLE;
- EXMC_NORSRAMInitStructure.EXMC_NWAITConfig = EXMC_NWAIT_CONFIG_DURING;
- EXMC_NORSRAMInitStructure.EXMC_MemoryWrite = EXMC_MEMORY_WRITE_ENABLE;
- EXMC_NORSRAMInitStructure.EXMC_NWAITSignal = EXMC_NWAIT_SIGNAL_DISABLE;
- EXMC_NORSRAMInitStructure.EXMC_ExtendedMode = EXMC_EXTENDED_MODE_DISABLE;
- EXMC_NORSRAMInitStructure.EXMC_WriteMode = EXMC_ASYN_WRITE;
- EXMC_NORSRAMInitStructure.EXMC_ReadWriteTimingParaStruct = &p;
- EXMC_NORSRAMInitStructure.EXMC_WriteTimingParaStruct = &p;
- EXMC_NORSRAM_Init(&EXMC_NORSRAMInitStructure);
- EXMC_NORSRAM_Enable(EXMC_BANK1_NORSRAM4, ENABLE);
- }
- void lcd_initialize(void)
- {
- LCD_CtrlLinesConfig();
- LCD_WriteReg(0x0025,0xe000);
- LCD_WriteReg(0x0000,0x0001);
- Delay_ms(8);
- LCD_WriteReg(0x0003,0xEEEE);
- LCD_WriteReg(0x000C,0x0004);
- LCD_WriteReg(0x000D,0x0003);
- LCD_WriteReg(0x000E,0x3000);
- Delay_ms(8);
- LCD_WriteReg(0x001E,0x00af);
- LCD_WriteReg(0x0001,0x293F);
- LCD_WriteReg(0x0002,0x0600);
- LCD_WriteReg(0x0010,0x0000);
- LCD_WriteReg(0x0011,0x6070);
- LCD_WriteReg(0x0005,0x0000);
- LCD_WriteReg(0x0006,0x0000);
- LCD_WriteReg(0x0007,0x0001);
- LCD_WriteReg(0x0007,0x0021);
- LCD_WriteReg(0x0007,0x0023);
- LCD_WriteReg(0x0007,0x0033);
- LCD_WriteReg(0x000B,0x0000);
- LCD_WriteReg(0x000F,0x0000);
- Delay_ms(8);
- LCD_WriteReg(0x0041,0x0000);
- LCD_WriteReg(0x0042,0x0000);
- LCD_WriteReg(0x0048,0x0000);
- LCD_WriteReg(0x0049,0x013F);
- LCD_WriteReg(0x004A,0x0000);
- LCD_WriteReg(0x004B,0x0000);
- LCD_WriteReg(0x0044,0xEF00);
- LCD_WriteReg(0x004E,0x0000);
- LCD_WriteReg(0x004F,0x0319);
- LCD_WriteReg(0x0045,0x0000);
- LCD_WriteReg(0x0046,0x013F);
- LCD_WriteReg(0x0023,0x0000);
- LCD_WriteReg(0x0024,0x0000);
- LCD_WriteReg(0x0021,0x0000);
- LCD_WriteReg(0x0030,0x0707);
- LCD_WriteReg(0x0031,0x0204);
- LCD_WriteReg(0x0032,0x0204);
- LCD_WriteReg(0x0033,0x0502);
- LCD_WriteReg(0x0034,0x0507);
- LCD_WriteReg(0x0035,0x0204);
- LCD_WriteReg(0x0036,0x0204);
- LCD_WriteReg(0x0037,0x0502);
- LCD_WriteReg(0x003A,0x0302);
- LCD_WriteReg(0x003B,0x000F);
- LCD_WriteReg(0x0023,0x0000);
- LCD_WriteReg(0x0024,0x0000);
- LCD_WriteReg(0x0028,0x0006);
- LCD_WriteReg(0x002F,0x122E);
- LCD_W_REG(0x0022);
- Delay_ms(8);
- LCD_Fill(BLUE);
- }
- //主函数
- #include "gd32f20x.h"
- #include "psram_driver.h"
- #include "main.h"
- #include "W.h"//这个是JPEG图片数据文件
- int main(void)
- {
- lcd_initialize();
- LoadJpegFile(img_w);
- while(1)
- {
- }
- }
复制代码移植STemWin部分代码
//------------------------------------------------ - #include "stm32f1xx_hal.h"
- #include "SSD1289_lcd.h"
- #include "crc.h"
- #include "gpio.h"
- #include "fsmc.h"
- #include "GUI.h"
- #include "GUIDEMO.h"
- void SystemClock_Config(void);
- int main(void)
- {
- HAL_Init();
- SystemClock_Config();
- MX_GPIO_Init();
- MX_CRC_Init();
- MX_FSMC_Init();
- STM3210E_LCD_Init();
- GUI_Init();
- GUIDEMO_Main();
- while (1)
- {
- }
- }
- void SystemClock_Config(void)
- {
- RCC_OscInitTypeDef RCC_OscInitStruct;
- RCC_ClkInitTypeDef RCC_ClkInitStruct;
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
- RCC_OscInitStruct.HSIState = RCC_HSI_ON;
- RCC_OscInitStruct.HSICalibrationValue = 16;
- RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
- HAL_RCC_OscConfig(&RCC_OscInitStruct);
- RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
- RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
- RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
- RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
- RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
- HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
- HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
- HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
- HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
- }
复制代码//CRC.c - #include "crc.h"
- CRC_HandleTypeDef hcrc;
- void MX_CRC_Init(void)
- {
- hcrc.Instance = CRC;
- HAL_CRC_Init(&hcrc);
- }
- void HAL_CRC_MspInit(CRC_HandleTypeDef* hcrc)
- {
- if(hcrc->Instance==CRC)
- {
- __CRC_CLK_ENABLE();
- }
- }
- void HAL_CRC_MspDeInit(CRC_HandleTypeDef* hcrc)
- {
- if(hcrc->Instance==CRC)
- {
- __CRC_CLK_DISABLE();
- }
- }
复制代码- //LCDConf_FlexColor_Template.c
- #include "GUI.h"
- #include "GUIDRV_FlexColor.h"
- #include "SSD1289_lcd.h"
- typedef struct
- {
- __IO uint16_t LCD_REG;
- __IO uint16_t LCD_RAM;
- } LCD_TypeDef;
- #define LCD_BASE ((uint32_t)(0x60000000 | 0x0C000000))
- #define LCD ((LCD_TypeDef *) LCD_BASE)
- #define XSIZE_PHYS 240
- #define YSIZE_PHYS 320
- #ifndef VXSIZE_PHYS
- #define VXSIZE_PHYS XSIZE_PHYS
- #endif
- #ifndef VYSIZE_PHYS
- #define VYSIZE_PHYS YSIZE_PHYS
- #endif
- #ifndef XSIZE_PHYS
- #error Physical X size of display is not defined!
- #endif
- #ifndef YSIZE_PHYS
- #error Physical Y size of display is not defined!
- #endif
- #ifndef GUICC_565
- #error Color conversion not defined!
- #endif
- #ifndef GUIDRV_FLEXCOLOR
- #error No display driver defined!
- #endif
- static void LcdWriteReg(U16 Data) {
- LCD->LCD_REG = Data;
- }
- static void LcdWriteData(U16 Data) {
- LCD->LCD_RAM =Data;// ... TBD by user
- }
- static void LcdWriteDataMultiple(U16 * pData, int NumItems) {
- while (NumItems--) {
- LCD->LCD_RAM = *pData++;
- }
- }
- static void LcdReadDataMultiple(U16 * pData, int NumItems) {
- while (NumItems--) {
- *pData++ =LCD->LCD_RAM ;
- }
- }
- void LCD_X_Config(void) {
- GUI_DEVICE * pDevice;
- CONFIG_FLEXCOLOR Config = {0};
- GUI_PORT_API PortAPI = {0};
- pDevice = GUI_DEVICE_CreateAndLink(GUIDRV_FLEXCOLOR, GUICC_M565, 0, 0);
- LCD_SetSizeEx (0, XSIZE_PHYS , YSIZE_PHYS);
- LCD_SetVSizeEx(0, VXSIZE_PHYS, VYSIZE_PHYS);
- Config.Orientation = GUI_SWAP_XY | GUI_MIRROR_Y;
- GUIDRV_FlexColor_Config(pDevice, &Config);
- PortAPI.pfWrite16_A0 = LcdWriteReg;
- PortAPI.pfWrite16_A1 = LcdWriteData;
- PortAPI.pfWriteM16_A1 = LcdWriteDataMultiple;
- PortAPI.pfReadM16_A1 = LcdReadDataMultiple;
- GUIDRV_FlexColor_SetFunc(pDevice, &PortAPI, GUIDRV_FLEXCOLOR_F66702, GUIDRV_FLEXCOLOR_M16C0B16);
- }
- int LCD_X_DisplayDriver(unsigned LayerIndex, unsigned Cmd, void * pData) {
- int r;
- (void) LayerIndex;
- (void) pData;
- switch (Cmd) {
- case LCD_X_INITCONTROLLER: {
-
- return 0;
- }
- default:
- r = -1;
- }
- return r;
- }
- //GUI_Conf.C
- #include "GUI.h"
- #define GUI_NUMBYTES 1024*50
- void GUI_X_Config(void) {
- static U32 aMemory[GUI_NUMBYTES / 4];
- GUI_ALLOC_AssignMemory(aMemory, GUI_NUMBYTES);
- GUI_SetDefaultFont(GUI_FONT_6X8);
- }
复制代码
FSMC-TFT-HEX.rar
(201.15 KB, 下载次数: 25)
|