3回答

0收藏

基于GD32F207的解码JPEG图片显示和STemWin移植

GD32 GD32 7003 人阅读 | 3 人回复 | 2016-01-14

本帖最后由 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

   运行结果见视频,下图是死机后进入的循环。由于水平有限,不能找出死机的原因,敬请高手指导。


五、作品实物+视频

http://player.youku.com/player.php/sid/XMTQyNDk2OTA0NA==/v.swf

                                JPEG解码

http://player.youku.com/player.php/sid/XMTQzODE5ODI0MA==/v.swf

                            STemWin移植
六、方案代码
  1. //JPEG解码部分代码
  2. void LCD_CtrlLinesConfig(void)
  3. {
  4.     GPIO_InitPara            GPIO_InitStructure;
  5.     EXMC_NORSRAMInitPara  EXMC_NORSRAMInitStructure;
  6.     EXMC_NORSRAMTimingInitPara  p;
  7.    
  8.     /* EXMC clock enable */
  9.     RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_EXMC, ENABLE);

  10.     /*GPIO clock enable */
  11. RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOB |RCC_APB2PERIPH_GPIOC |       RCC_APB2PERIPH_GPIOD | RCC_APB2PERIPH_GPIOE |
  12. RCC_APB2PERIPH_GPIOF | RCC_APB2PERIPH_GPIOG |  RCC_APB2PERIPH_AF, ENABLE);

  13.     /* Config GPIO port */
  14.     GPIO_InitStructure.GPIO_Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 |
  15.                                 GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_14 |
  16.                                 GPIO_PIN_15;
  17.     GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP;
  18.     GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
  19.     GPIO_Init(GPIOD, &GPIO_InitStructure);

  20.    GPIO_InitStructure.GPIO_Pin = GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 |
  21.                                 GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 |
  22.                                 GPIO_PIN_15;
  23.   GPIO_Init(GPIOE, &GPIO_InitStructure);

  24. //Set PF.00(A0 (RS)) as alternate function push pull
  25.   GPIO_InitStructure.GPIO_Pin = GPIO_PIN_0;
  26.   GPIO_Init(GPIOF, &GPIO_InitStructure);

  27. //Set PG.12(NE4 (LCD/CS)) as alternate function push pull - CE3(LCD /CS)
  28.   GPIO_InitStructure.GPIO_Pin = GPIO_PIN_12;
  29.   GPIO_Init(GPIOG, &GPIO_InitStructure);

  30.     p.EXMC_AsynAddressSetupTime = 0x08;  
  31.     p.EXMC_AsynAddressHoldTime = 0x09;  
  32.     p.EXMC_AsynDataSetupTime = 0x08;
  33.     p.EXMC_BusLatency =0x09;

  34.     p.EXMC_SynCLKDivision = 0x06;   
  35.     p.EXMC_SynDataLatency = 0;  
  36.     p.EXMC_AsynAccessMode = EXMC_ACCESS_MODE_A ;

  37.     EXMC_NORSRAMInitStructure.EXMC_NORSRAMBank = EXMC_BANK1_NORSRAM4;

  38.     EXMC_NORSRAMInitStructure.EXMC_AddressDataMux = EXMC_ADDRESS_DATA_MUX_DISABLE;

  39.     EXMC_NORSRAMInitStructure.EXMC_MemoryType = EXMC_MEMORY_TYPE_SRAM;
  40.     EXMC_NORSRAMInitStructure.EXMC_DatabusWidth = EXMC_DATABUS_WIDTH_16B;
  41.     EXMC_NORSRAMInitStructure.EXMC_BurstMode = EXMC_BURST_MODE_DISABLE;
  42.     EXMC_NORSRAMInitStructure.EXMC_AsynWait = EXMC_ASYN_WAIT_DISABLE;
  43.     EXMC_NORSRAMInitStructure.EXMC_NWAITPolarity = EXMC_NWAIT_POLARITY_LOW;
  44.   
  45.     EXMC_NORSRAMInitStructure.EXMC_WrapBurstMode = EXMC_WRAP_BURST_MODE_DISABLE;
  46.     EXMC_NORSRAMInitStructure.EXMC_NWAITConfig = EXMC_NWAIT_CONFIG_DURING;
  47.     EXMC_NORSRAMInitStructure.EXMC_MemoryWrite = EXMC_MEMORY_WRITE_ENABLE;
  48.     EXMC_NORSRAMInitStructure.EXMC_NWAITSignal = EXMC_NWAIT_SIGNAL_DISABLE;
  49.     EXMC_NORSRAMInitStructure.EXMC_ExtendedMode = EXMC_EXTENDED_MODE_DISABLE;
  50.     EXMC_NORSRAMInitStructure.EXMC_WriteMode = EXMC_ASYN_WRITE;
  51.     EXMC_NORSRAMInitStructure.EXMC_ReadWriteTimingParaStruct = &p;
  52.     EXMC_NORSRAMInitStructure.EXMC_WriteTimingParaStruct = &p;
  53.     EXMC_NORSRAM_Init(&EXMC_NORSRAMInitStructure);

  54.     EXMC_NORSRAM_Enable(EXMC_BANK1_NORSRAM4, ENABLE);

  55. }
  56. void lcd_initialize(void)
  57. {
  58. LCD_CtrlLinesConfig();
  59. LCD_WriteReg(0x0025,0xe000);
  60. LCD_WriteReg(0x0000,0x0001);
  61. Delay_ms(8);
  62. LCD_WriteReg(0x0003,0xEEEE);  
  63. LCD_WriteReg(0x000C,0x0004);
  64. LCD_WriteReg(0x000D,0x0003);
  65. LCD_WriteReg(0x000E,0x3000);
  66. Delay_ms(8);  
  67. LCD_WriteReg(0x001E,0x00af);
  68. LCD_WriteReg(0x0001,0x293F);
  69. LCD_WriteReg(0x0002,0x0600);
  70. LCD_WriteReg(0x0010,0x0000);
  71. LCD_WriteReg(0x0011,0x6070);  
  72. LCD_WriteReg(0x0005,0x0000);
  73. LCD_WriteReg(0x0006,0x0000);
  74. LCD_WriteReg(0x0007,0x0001);
  75. LCD_WriteReg(0x0007,0x0021);
  76. LCD_WriteReg(0x0007,0x0023);
  77. LCD_WriteReg(0x0007,0x0033);
  78. LCD_WriteReg(0x000B,0x0000);  
  79. LCD_WriteReg(0x000F,0x0000);
  80. Delay_ms(8);
  81. LCD_WriteReg(0x0041,0x0000);
  82. LCD_WriteReg(0x0042,0x0000);
  83. LCD_WriteReg(0x0048,0x0000);
  84. LCD_WriteReg(0x0049,0x013F);
  85. LCD_WriteReg(0x004A,0x0000);
  86. LCD_WriteReg(0x004B,0x0000);
  87. LCD_WriteReg(0x0044,0xEF00);
  88. LCD_WriteReg(0x004E,0x0000);
  89. LCD_WriteReg(0x004F,0x0319);
  90. LCD_WriteReg(0x0045,0x0000);
  91. LCD_WriteReg(0x0046,0x013F);
  92. LCD_WriteReg(0x0023,0x0000);
  93. LCD_WriteReg(0x0024,0x0000);
  94. LCD_WriteReg(0x0021,0x0000);
  95. LCD_WriteReg(0x0030,0x0707);
  96. LCD_WriteReg(0x0031,0x0204);
  97. LCD_WriteReg(0x0032,0x0204);
  98. LCD_WriteReg(0x0033,0x0502);
  99. LCD_WriteReg(0x0034,0x0507);
  100. LCD_WriteReg(0x0035,0x0204);
  101. LCD_WriteReg(0x0036,0x0204);
  102. LCD_WriteReg(0x0037,0x0502);
  103. LCD_WriteReg(0x003A,0x0302);
  104. LCD_WriteReg(0x003B,0x000F);
  105. LCD_WriteReg(0x0023,0x0000);
  106. LCD_WriteReg(0x0024,0x0000);
  107. LCD_WriteReg(0x0028,0x0006);
  108. LCD_WriteReg(0x002F,0x122E);
  109. LCD_W_REG(0x0022);
  110. Delay_ms(8);
  111. LCD_Fill(BLUE);
  112. }

  113. //主函数
  114. #include "gd32f20x.h"
  115. #include "psram_driver.h"
  116. #include "main.h"
  117. #include "W.h"//这个是JPEG图片数据文件
  118. int main(void)
  119. {
  120.   lcd_initialize();
  121.   LoadJpegFile(img_w);
  122.     while(1)
  123.     {
  124.     }
  125. }
复制代码
移植STemWin部分代码
//------------------------------------------------
  1. #include "stm32f1xx_hal.h"
  2. #include "SSD1289_lcd.h"
  3. #include "crc.h"
  4. #include "gpio.h"
  5. #include "fsmc.h"
  6. #include "GUI.h"
  7. #include "GUIDEMO.h"
  8. void SystemClock_Config(void);
  9. int main(void)
  10. {
  11.   HAL_Init();
  12.   SystemClock_Config();
  13.   MX_GPIO_Init();
  14.   MX_CRC_Init();
  15.   MX_FSMC_Init();
  16.   STM3210E_LCD_Init();
  17. GUI_Init();
  18. GUIDEMO_Main();
  19. while (1)
  20.   {
  21.   }
  22. }
  23. void SystemClock_Config(void)
  24. {
  25.   RCC_OscInitTypeDef RCC_OscInitStruct;
  26.   RCC_ClkInitTypeDef RCC_ClkInitStruct;
  27.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  28.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  29.   RCC_OscInitStruct.HSICalibrationValue = 16;
  30.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  31.   HAL_RCC_OscConfig(&RCC_OscInitStruct);
  32.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
  33.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  34.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  35.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  36.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  37.   HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
  38.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  39.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  40.   HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  41. }
复制代码
//CRC.c
  1. #include "crc.h"
  2. CRC_HandleTypeDef hcrc;
  3. void MX_CRC_Init(void)
  4. {
  5.   hcrc.Instance = CRC;
  6.   HAL_CRC_Init(&hcrc);
  7. }
  8. void HAL_CRC_MspInit(CRC_HandleTypeDef* hcrc)
  9. {
  10.   if(hcrc->Instance==CRC)
  11.   {
  12.     __CRC_CLK_ENABLE();
  13.   }
  14. }

  15. void HAL_CRC_MspDeInit(CRC_HandleTypeDef* hcrc)
  16. {

  17.   if(hcrc->Instance==CRC)
  18.   {
  19.     __CRC_CLK_DISABLE();
  20.   }
  21. }
复制代码
  1. //LCDConf_FlexColor_Template.c
  2. #include "GUI.h"
  3. #include "GUIDRV_FlexColor.h"
  4. #include "SSD1289_lcd.h"
  5. typedef struct
  6. {
  7.   __IO uint16_t LCD_REG;
  8.   __IO uint16_t LCD_RAM;
  9. } LCD_TypeDef;

  10. #define LCD_BASE           ((uint32_t)(0x60000000 | 0x0C000000))
  11. #define LCD                ((LCD_TypeDef *) LCD_BASE)
  12. #define XSIZE_PHYS  240
  13. #define YSIZE_PHYS  320
  14. #ifndef   VXSIZE_PHYS
  15.   #define VXSIZE_PHYS XSIZE_PHYS
  16. #endif
  17. #ifndef   VYSIZE_PHYS
  18.   #define VYSIZE_PHYS YSIZE_PHYS
  19. #endif
  20. #ifndef   XSIZE_PHYS
  21.   #error Physical X size of display is not defined!
  22. #endif
  23. #ifndef   YSIZE_PHYS
  24.   #error Physical Y size of display is not defined!
  25. #endif
  26. #ifndef   GUICC_565
  27.   #error Color conversion not defined!
  28. #endif
  29. #ifndef   GUIDRV_FLEXCOLOR
  30.   #error No display driver defined!
  31. #endif
  32. static void LcdWriteReg(U16 Data) {
  33.   LCD->LCD_REG = Data;
  34. }
  35. static void LcdWriteData(U16 Data) {
  36.    LCD->LCD_RAM =Data;// ... TBD by user
  37. }
  38. static void LcdWriteDataMultiple(U16 * pData, int NumItems) {
  39.   while (NumItems--) {
  40.     LCD->LCD_RAM = *pData++;
  41.   }
  42. }
  43. static void LcdReadDataMultiple(U16 * pData, int NumItems) {
  44.   while (NumItems--) {
  45.   *pData++ =LCD->LCD_RAM ;
  46.   }
  47. }
  48. void LCD_X_Config(void) {
  49.   GUI_DEVICE * pDevice;
  50.   CONFIG_FLEXCOLOR Config = {0};
  51.   GUI_PORT_API PortAPI = {0};
  52.   pDevice = GUI_DEVICE_CreateAndLink(GUIDRV_FLEXCOLOR, GUICC_M565, 0, 0);
  53.   LCD_SetSizeEx (0, XSIZE_PHYS , YSIZE_PHYS);
  54.   LCD_SetVSizeEx(0, VXSIZE_PHYS, VYSIZE_PHYS);
  55.   Config.Orientation = GUI_SWAP_XY | GUI_MIRROR_Y;
  56.   GUIDRV_FlexColor_Config(pDevice, &Config);
  57.   PortAPI.pfWrite16_A0  = LcdWriteReg;
  58.   PortAPI.pfWrite16_A1  = LcdWriteData;
  59.   PortAPI.pfWriteM16_A1 = LcdWriteDataMultiple;
  60.   PortAPI.pfReadM16_A1  = LcdReadDataMultiple;
  61.   GUIDRV_FlexColor_SetFunc(pDevice, &PortAPI, GUIDRV_FLEXCOLOR_F66702, GUIDRV_FLEXCOLOR_M16C0B16);
  62. }
  63. int LCD_X_DisplayDriver(unsigned LayerIndex, unsigned Cmd, void * pData) {
  64.   int r;
  65.   (void) LayerIndex;
  66.   (void) pData;
  67.   switch (Cmd) {
  68.   case LCD_X_INITCONTROLLER: {
  69.    
  70.     return 0;
  71.   }
  72.   default:
  73.     r = -1;
  74.   }
  75.   return r;
  76. }

  77. //GUI_Conf.C
  78. #include "GUI.h"
  79. #define GUI_NUMBYTES  1024*50
  80. void GUI_X_Config(void) {
  81.   static U32 aMemory[GUI_NUMBYTES / 4];
  82.   GUI_ALLOC_AssignMemory(aMemory, GUI_NUMBYTES);
  83.   GUI_SetDefaultFont(GUI_FONT_6X8);
  84. }
复制代码
FSMC-TFT-HEX.rar (201.15 KB, 下载次数: 25)

评分

参与人数 1声望 +3 与非币 +100 收起 理由
小菜儿 + 3 + 100 很给力!

查看全部评分

分享到:
回复

使用道具 举报

回答|共 3 个

倒序浏览

沙发

党国特派员

发表于 2016-1-15 09:23:51 | 只看该作者

学习了。。。。
喜欢在构思妙想,电子产品DIY是工作,也是一种爱好。
板凳

晨枫-366963

发表于 2016-1-19 09:26:55 | 只看该作者

高大上,好好学习下!
地板

糖悦之果飞

发表于 2016-1-25 10:20:17 | 只看该作者

亲,可以将内容一并发到经验频道,很有机会获得每月之星的呢http://jingyan.eeboard.com/
您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条