Porting emwin on STM32F407

Publisher:haoyingLatest update time:2016-12-18 Source: eefocusKeywords:STM32F407 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

environment:

Host: WIN8

Development environment: MDK5.13

emwin version: STemWinLibrary522

mcu: stm32f407VGT6

Development board: Anfulai STM32-X3

TFT model: Ailan 2.8-inch TFT, main control chip: ILI9325


illustrate:

Porting emwin on STM32F407, driving the screen interface to FSMC


Transplantation steps:

1. MDK new file structure:

2. GUIConf.c file modification

    a) Add macro definition:



  1. #define GUI_NUMBYTES  (1024 * 80)  

  2. #define GUI_BLOCKSIZE 0x80  




  b) Add the following statement to the GUI_X_Config(void) function:



  1. GUI_ALLOC_SetAvBlockSize(GUI_BLOCKSIZE);  


  1.   




   After modification:


  1. /********************************************************************* 

  2. *       GUI_X_Config 

  3. * Purpose: 

  4. *   Called during the initialization process in order to set up the 

  5. *   available memory for the GUI. 

  6. */  

  7. void GUI_X_Config(void) {  

  8.   //  

  9.   // 32 bit aligned memory area  

  10.   //  

  11.   static U32 aMemory[GUI_NUMBYTES / 4];  

  12.   //  

  13.   // Assign memory to emWin  

  14.   //  

  15.   GUI_ALLOC_AssignMemory(aMemory, GUI_NUMBYTES);  

  16.       

  17.     GUI_ALLOC_SetAvBlockSize(GUI_BLOCKSIZE);  

  18.   //  

  19.   // Set default font  

  20.   //  

  21.   GUI_SetDefaultFont(GUI_FONT_6X8);  

  22. }  



3. LCDConf_FlexColor_Template.c file modification


    a) Add macro definition:


  1. #define LCD_REG_ADDRESS             BANK1_LCD_REG  

  2. #define LCD_DATA_ADDRESS            BANK1_LCD_RAM  


 

  1.   


      These two BANK macro definitions are defined in the tft driver file:


  1. #define BANK1_BASE     ((uint32_t)(0x60000000 | 0x00000000))  

  2. #define BANK1_LCD_RAM ​​*(__IO uint16_t *)(BANK1_BASE + (1 << (18 + 1))) /* In FSMC 16-bit bus mode, FSMC_A18 port line corresponds to physical address A19 */  

  3. #define BANK1_LCD_REG   *(__IO uint16_t *)(BANK1_BASE)  




       Specific values ​​are related to wiring


     b) Specific function modification


  1. /********************************************************************* 

  2. *       Local functions 

  3. ********************************************************************** 

  4. */  

  5. /******************************************************************** 

  6. *       LcdWriteReg 

  7. * Function description: 

  8. *   Sets display register 

  9. */  

  10. static void LcdWriteReg(U16 Data) {  

  11.   // ... TBD by user  

  12.     LCD_REG_ADDRESS = Data;  

  13. }  

  14.   

  15. /******************************************************************** 

  16. *       LcdWriteData 

  17. * Function description: 

  18. *   Writes a value to a display register 

  19. */  

  20. static void LcdWriteData(U16 Data) {  

  21.   // ... TBD by user  

  22.     LCD_DATA_ADDRESS=Data;  

  23. }  

  24.   

  25. /******************************************************************** 

  26. *       LcdWriteDataMultiple 

  27. * Function description: 

  28. *   Writes multiple values to a display register. 

  29. */  

  30. static void LcdWriteDataMultiple(U16 * pData, int NumItems) {  

  31.   while (NumItems--) {  

  32.     // ... TBD by user  

  33.       LCD_DATA_ADDRESS=*pData++;  

  34.   }  

  35. }  

  36.   

  37. /******************************************************************** 

  38. *       LcdReadDataMultiple 

  39. * Function description: 

  40. *   Reads multiple values from a display register. 

  41. */  

  42. static void LcdReadDataMultiple(U16 * pData, int NumItems) {  

  43.   while (NumItems--) {  

  44.     // ... TBD by user  

  45.       *pData++=LCD_DATA_ADDRESS;  

  46.   }  

  47. }  

  48.   

  49. /********************************************************************* 

  50. *       Public functions 

  51. ********************************************************************** 

  52. */  

  53. /********************************************************************* 

  54. *       LCD_X_Config 

  55. * Function description: 

  56. *   Called during the initialization process in order to set up the 

  57. *   display driver configuration. 

  58. */  

  59. void LCD_X_Config(void) {  

  60.   GUI_DEVICE * pDevice;  

  61.   CONFIG_FLEXCOLOR Config = {0};  

  62.   GUI_PORT_API PortAPI = {0};  

  63.   //  

  64.   // Set display driver and color conversion  

  65.   //  

  66.   pDevice = GUI_DEVICE_CreateAndLink(GUIDRV_FLEXCOLOR, GUICC_565, 0, 0);  

  67.   //  

  68.   // Display driver configuration, required for Lin-driver  

  69.   //  

  70.   LCD_SetSizeEx (0, XSIZE_PHYS , YSIZE_PHYS);  

  71.   LCD_SetVSizeEx(0, VXSIZE_PHYS, VYSIZE_PHYS);  

  72.   //  

  73.   // Orientation  

  74.   //  

  75.   //Config.Orientation = GUI_SWAP_XY | GUI_MIRROR_Y;  

  76.   Config.FirstCOM = 0;  

  77.   Config.FirstSEG = 0;  

  78.   //Config.Orientation = GUI_MIRROR_X | GUI_MIRROR_Y;  

  79.   Config.NumDummyReads = 2;  

  80.   GUIDRV_FlexColor_Config(pDevice, &Config);  

  81.   //  

  82.   // Set controller and operation mode  

  83.   //  

  84.   PortAPI.pfWrite16_A0  = LcdWriteReg;  

  85.   PortAPI.pfWrite16_A1  = LcdWriteData;  

  86.   PortAPI.pfWriteM16_A1 = LcdWriteDataMultiple;  

  87.   PortAPI.pfReadM16_A1 = LcdReadDataMultiple;  

  88.   GUIDRV_FlexColor_SetFunc(pDevice, &PortAPI, GUIDRV_FLEXCOLOR_F66708, GUIDRV_FLEXCOLOR_M16C0B16);  

  89.     //GUIDRV_FlexColor_SetFunc(pDevice, &PortAPI, GUIDRV_FLEXCOLOR_F66709, GUIDRV_FLEXCOLOR_M16C0B16);  

  90. }  

      Among them: GUIDRV_FlexColor_SetFunc function description:

      

       Because the main control chip is ILI9325, the parameter is selected as GUIDRV_FLEXCOLOR_F66708


4. GUI_X.c file modification

      This file controls the delay in the GUI, which can be implemented with a timer. The modifications are as follows:

      

  1. /********************************************************************* 

  2. *       Global data 

  3. */  

  4. volatile GUI_TIMER_TIME OS_TimeMS;  

  5.   

  6. /********************************************************************* 

  7. *      Timing: 

  8. *                 GUI_X_GetTime() 

  9. *                 GUI_X_Delay(int) 

  10.  

  11.   Some timing dependent routines require a GetTime 

  12.   and delay function. Default time unit (tick), normally is 

  13.   1 ms. 

  14. */  

  15.   

  16. extern __IO int32_t g_iRunTime;  

  17. GUI_TIMER_TIME GUI_X_GetTime(void) {   

  18.   //return OS_TimeMS;   

  19.     return g_iRunTime;  

  20. }  

  21.   

  22. void GUI_X_Delay(int ms) {   

  23. //  int tEnd = OS_TimeMS + ms;  

  24. //  while ((tEnd - OS_TimeMS) > 0);  

  25.       

  26.     int tEnd = g_iRunTime + ms;  

  27.     while ((tEnd - g_iRunTime) > 0);  

  28. }  



5. Main function implementation:


  1. int main(void)  

  2. {  

  3.     /* 

  4.         The startup file in the ST firmware library has already executed the SystemInit() function, which is in the system_stm32f4xx.c file. Its main function is 

  5.     Configure the CPU system clock, internal Flash access timing, and configure FSMC for external SRAM 

  6.     */  

  7.   

  8.     bsp_Init(); /* Hardware initialization */  

  9.     PrintfLogo(); /* Print routine information to serial port 1 */  

  10.     vLCDInit();  

  11.       

  12. //  vClearScreen(Green);  

  13. //  vSetTextColor(Red);       

  14. //  vPutString(20,0, "NanJing RF Tracking!!!!!");  

  15. //  ShowImage();  

  16.     //DemoFatFS(); /* SD card file system demonstration program */  

  17.     //RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE);   

  18.     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC, ENABLE);  

  19.     GUI_Init();  

  20.     GUI_DispString("I am jdh!");  

  21.   

  22.     while (1)  

  23.     {  

  24.         GUI_Delay(1000);  

  25.     }  

  26. }  



Notice:


  1. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC, ENABLE);  




The function is necessary, otherwise the GUI will not work. This is a measure taken by ST to prevent other chips from using this GUI.


Effect:



References:

1. STemWin5.22 transplantation notes
2. "Wildfire emwin practical guide V1.0.0"

3. Anfulai source code: x3 development board_bare metal STemWin5.20


Keywords:STM32F407 Reference address:Porting emwin on STM32F407

Previous article:Driver font chip GT23L24M0140
Next article:ucos-ii example 7: memory management test

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号