STM32F407上移植emwin

               


STM32F407上移植emwin


本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明.


环境:

主机:WIN8

开发环境:MDK5.13

emwin版本:STemWinLibrary522

mcu: stm32f407VGT6

开发板:安富莱STM32-X3

TFT型号:艾蓝2.8寸TFT,主控芯片:ILI9325


说明:

在STM32F407上移植emwin,驱动屏幕接口为FSMC


移植步骤:

1.MDK新建文件结构:

2.GUIConf.c文件修改

    a)增加宏定义:

#define GUI_NUMBYTES  (1024 * 80)#define GUI_BLOCKSIZE 0x80

  b)GUI_X_Config(void)函数中增加语句:

GUI_ALLOC_SetAvBlockSize(GUI_BLOCKSIZE);

   修改后:

/***********************************************************************       GUI_X_Config** Purpose:*   Called during the initialization process in order to set up the*   available memory for the GUI.*/void GUI_X_Config(void) //  // 32 bit aligned memory area  //  static U32 aMemory[GUI_NUMBYTES / 4];  //  // Assign memory to emWin  //  GUI_ALLOC_AssignMemory(aMemory, GUI_NUMBYTES);  GUI_ALLOC_SetAvBlockSize(GUI_BLOCKSIZE);  //  // Set default font  //  GUI_SetDefaultFont(GUI_FONT_6X8);}


3.LCDConf_FlexColor_Template.c文件修改

    a)增加宏定义:

#define LCD_REG_ADDRESS            BANK1_LCD_REG#define LCD_DATA_ADDRESS           BANK1_LCD_RAM

      这两个BANK宏定义在tft驱动文件中定义:

#define BANK1_BASE  ((uint32_t)(0x60000000 | 0x00000000))#define BANK1_LCD_RAM *(__IO uint16_t *)(BANK1_BASE +  (1 << (18 + 1))) /* FSMC 16位总线模式下,FSMC_A18口线对应物理地址A19 */#define BANK1_LCD_REG *(__IO uint16_t *)(BANK1_BASE)

       具体值和接线相关


     b)具体函数修改

/***********************************************************************       Local functions************************************************************************//**********************************************************************       LcdWriteReg** Function description:*   Sets display register*/static void LcdWriteReg(U16 Data) // ... TBD by user LCD_REG_ADDRESS = Data;}/**********************************************************************       LcdWriteData** Function description:*   Writes a value to a display register*/static void LcdWriteData(U16 Data) // ... TBD by user LCD_DATA_ADDRESS=Data;}/**********************************************************************       LcdWriteDataMultiple** Function description:*   Writes multiple values to a display register.*/static void LcdWriteDataMultiple(U16 * pData, int NumItems) while (NumItems--) {    // ... TBD by user   LCD_DATA_ADDRESS=*pData++;  }}/**********************************************************************       LcdReadDataMultiple** Function description:*   Reads multiple values from a display register.*/static void LcdReadDataMultiple(U16 * pData, int NumItems) while (NumItems--) {    // ... TBD by user   *pData++=LCD_DATA_ADDRESS;  }}/***********************************************************************       Public functions************************************************************************//***********************************************************************       LCD_X_Config** Function description:*   Called during the initialization process in order to set up the*   display driver configuration.**/void LCD_X_Config(void) {  GUI_DEVICE * pDevice;  CONFIG_FLEXCOLOR Config = {0};  GUI_PORT_API PortAPI = {0};  //  // Set display driver and color conversion  //  pDevice = GUI_DEVICE_CreateAndLink(GUIDRV_FLEXCOLOR, GUICC_565, 0, 0);  //  // Display driver configuration, required for Lin-driver  //  LCD_SetSizeEx (0, XSIZE_PHYS , YSIZE_PHYS);  LCD_SetVSizeEx(0, VXSIZE_PHYS, VYSIZE_PHYS);  //  // Orientation  //  //Config.Orientation = GUI_SWAP_XY | GUI_MIRROR_Y;  Config.FirstCOM = 0;  Config.FirstSEG = 0//Config.Orientation = GUI_MIRROR_X | GUI_MIRROR_Y;  Config.NumDummyReads = 2;  GUIDRV_FlexColor_Config(pDevice, &Config);  //  // Set controller and operation mode  //  PortAPI.pfWrite16_A0  = LcdWriteReg;  PortAPI.pfWrite16_A1  = LcdWriteData;  PortAPI.pfWriteM16_A1 = LcdWriteDataMultiple;  PortAPI.pfReadM16_A1  = LcdReadDataMultiple;  GUIDRV_FlexColor_SetFunc(pDevice, &PortAPI, GUIDRV_FLEXCOLOR_F66708, GUIDRV_FLEXCOLOR_M16C0B16); //GUIDRV_FlexColor_SetFunc(pDevice, &PortAPI, GUIDRV_FLEXCOLOR_F66709, GUIDRV_FLEXCOLOR_M16C0B16);}

      其中:GUIDRV_FlexColor_SetFunc函数说明:

     

       因为主控芯片为ILI9325,所以参数选择GUIDRV_FLEXCOLOR_F66708


4.GUI_X.c文件修改

      此文件控制的是GUI中的延时,可以用定时器配合实现,修改如下:

      

/***********************************************************************       Global data*/volatile GUI_TIMER_TIME OS_TimeMS;/***********************************************************************      Timing:*                 GUI_X_GetTime()*                 GUI_X_Delay(int)  Some timing dependent routines require a GetTime  and delay function. Default time unit (tick), normally is  1 ms.*/extern __IO int32_t g_iRunTime;GUI_TIMER_TIME GUI_X_GetTime(void) {   //return OS_TimeMS;  return g_iRunTime;}void GUI_X_Delay(int ms) { //  int tEnd = OS_TimeMS + ms;//  while ((tEnd - OS_TimeMS) > 0);  int tEnd = g_iRunTime + ms; while ((tEnd - g_iRunTime) > 0);}

5.主函数实现:

int main(void)/*  ST固件库中的启动文件已经执行了 SystemInit() 函数,该函数在 system_stm32f4xx.c 文件,主要功能是 配置CPU系统的时钟,内部Flash访问时序,配置FSMC用于外部SRAM */ bsp_Init();  /* 硬件初始化 */ PrintfLogo(); /* 打印例程信息到串口1 */ vLCDInit(); // vClearScreen(Green);// vSetTextColor(Red);  // vPutString(20,0, "NanJing RF Tracking!!!!!");// ShowImage(); //DemoFatFS(); /* SD卡文件系统演示程序 */ //RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE);  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC, ENABLE);    GUI_Init();    GUI_DispString("I am jdh!"); while (1) {  GUI_Delay(1000); }}

注意:

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC, ENABLE);

函数是必须的,否则GUI将不工作,这是ST公司防止其他芯片用此GUI的措施。


效果:



参考资料:

1.STemWin5.22移植笔记
2.《野火emwin实战指南V1.0.0》

3.安富莱源程序:x3开发板_裸机STemWin5.20



           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

你可能感兴趣的:(STM32F407上移植emwin)