https://shequ.stmicroelectronics.cn/thread-871072-1-1.html
https://shequ.stmicroelectronics.cn/thread-871079-1-1.html
https://shequ.stmicroelectronics.cn/thread-871081-1-1.html
上面三个帖子从创建STM32H7R7L8H6H芯片工程开始,生成Appli、Boot、ExtMemLoader三个工程,首先实现控制板载LED翻转,验证工程配置的可用性。在此基础上配置显示相关的外设,添加TouchGFX和FreeRTOS组件,利用TouchGFX导入GUI界面,并生成相应的代码,编译和烧录到开发板上运行。
1、CubeMX工程复用
将可用的CubeMX工程文件另存为不同名称的文件,用于创建同一硬件平台上的不同应用。

将原有的包含自定义文件信息的.extSettings文件和包含有对应的自定义的源文件复制到新的CubeMX文件目录中。如果.extSettings文件和自定义文件不匹配,在生成工程时会无法生成。

2、生成代码并添加相应的驱动
在生成的代码基础上,需要添加外部HyperRAM和Flash的驱动代码。
在其中的Boot工程的main.c中添加HyperRAM的头文件,并在MX_XSPI2_Init添加HyperRAM调用。
/* USER CODE BEGIN Includes */
#include "HyperRAM/hyperram.h"
/* USER CODE END Includes */
/* USER CODE BEGIN XSPI2_Init 2 */
HyperRAM_EnableMemroyMapMode();
/* USER CODE END XSPI2_Init 2 */
在Boot工程的stm32h7rsxx_hal_msp.c中添加XSPI1和XSPI2的HSLV使能,支持1.8V 200MHz速度。
void HAL_MspInit(void)
{
/* USER CODE BEGIN MspInit 1 */
/* high speed low voltage config */
HAL_SBS_EnableIOSpeedOptimize(SBS_IO_XSPI2_HSLV);
HAL_SBS_EnableIOSpeedOptimize(SBS_IO_XSPI1_HSLV);
/* USER CODE END MspInit 1 */
}
在ExtMemLoader中启用XSPI1的HSLV功能,在stm32h7rsxx_hal_msp.c中使能XSPI1的HSLV功能。
void HAL_MspInit(void)
{
/* USER CODE BEGIN MspInit 1 */
/* high speed low voltage config */
HAL_SBS_EnableIOSpeedOptimize(SBS_IO_XSPI1_HSLV);
/* USER CODE END MspInit 1 */
}
完成以上操作,编译ExtMemLoader工程,得到的固件用于Appli工程烧录时的外部存储空间管理。
3、TouchGFX导入界面
在生成工程的STM32H7R7_ATK_GUI2\Appli\TouchGFX路径中,有ApplicationTemplate.touchgfx.part,使用TouchGFX打开该文件。在提示界面导入800x480的示例GUI。

导入后,生成该界面的代码。

对工程中的代码进行修改,添加背光和触摸信息相关的代码。
App TouchGFXHAL.cpp当第一帧帧缓存数据准备好后,再打开LCD背景光可以避免开机的撕裂现象
#include "main.h"
void TouchGFXHAL::endFrame()
{
TouchGFXGeneratedHAL::endFrame();
if (!Display_ON)
{
HAL_GPIO_WritePin(LCD_BL_GPIO_Port, LCD_BL_Pin, GPIO_PIN_SET);
Display_ON = true;
}
}
STM32TouchController.cpp中添加代码,获取触摸坐标
#include "TOUCH/touch.h"
void STM32TouchController::init()
{
tp_dev.init(); /* Touch Init*/
}
bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y)
{
uint8_t touches = 0;
touches = tp_dev.scan(0);
if(touches == 1)
{
y = tp_dev.x[0];
x = tp_dev.y[0];
}
return (touches > 0);
}
修改Appli工程中的STM32H7R7L8HXH_ROMxspi1.ld内容如下
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = ORIGIN(DTCM) + LENGTH(DTCM); /* end of "DTCM" Ram type memory */
_Min_Heap_Size = 0x1000; /* required amount of heap */
_Min_Stack_Size = 0x1000; /* required amount of stack */
/* Memories definition */
MEMORY
{
RAM (rw) : ORIGIN = 0x24000000, LENGTH = 0x0006c000
RAM_CMD (rw) : ORIGIN = 0x2406c000, LENGTH = 0x00006000
ITCM (rw) : ORIGIN = 0x00000000, LENGTH = 0x00010000
DTCM (rw) : ORIGIN = 0x20000000, LENGTH = 0x00003000
DTCM_RTOS (rw) : ORIGIN = 0x20003000, LENGTH = 0x0000D000
SRAMAHB (rw) : ORIGIN = 0x30000000, LENGTH = 0x00008000
BKPSRAM (rw) : ORIGIN = 0x38800000, LENGTH = 0x00001000
FLASH (xr) : ORIGIN = 0x90000000, LENGTH = 0x00200000
FLASH_GFX (r) : ORIGIN = 0x90200000, LENGTH = 0x07e00000
EXTRAM (rw) : ORIGIN = 0x70000000, LENGTH = 0x02000000
}
/* Sections */
SECTIONS
{
/* The startup code into "FLASH" FLASH type memory */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* The program code and other data into "FLASH" FLASH type memory */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
/* Constant data into "FLASH" FLASH type memory */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
.ARM.extab (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
{
. = ALIGN(4);
*(.ARM.extab* .gnu.linkonce.armextab.*)
. = ALIGN(4);
} >FLASH
.ARM (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
{
. = ALIGN(4);
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
. = ALIGN(4);
} >FLASH
.preinit_array (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
{
. = ALIGN(4);
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
. = ALIGN(4);
} >FLASH
.init_array (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
{
. = ALIGN(4);
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
. = ALIGN(4);
} >FLASH
.fini_array (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
{
. = ALIGN(4);
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
. = ALIGN(4);
} >FLASH
/* Used by the startup to initialize data */
_sidata = LOADADDR(.data);
FreeRtosHeapSection :
{
*(.bss.ucHeap)
. = ALIGN(0x8);
} >DTCM_RTOS
/* Initialized data sections into "RAM" Ram type memory */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
*(.RamFunc) /* .RamFunc sections */
*(.RamFunc*) /* .RamFunc* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM AT> FLASH
/* Uninitialized data section into "RAM" Ram type memory */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss section */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM
/* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
._user_heap_stack :
{
. = ALIGN(8);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(8);
} >DTCM
/* Remove information from the compiler libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
.ARM.attributes 0 : { *(.ARM.attributes) }
BufferSection (NOLOAD) :
{
*(TouchGFX_Framebuffer TouchGFX_Framebuffer.*)
*(.gnu.linkonce.r.*)
. = ALIGN(0x8);
*(Nemagfx_Stencil_Buffer Nemagfx_Stencil_Buffer.*)
*(.gnu.linkonce.r.*)
. = ALIGN(0x8);
} >EXTRAM
UncachedSection (NOLOAD) :
{
*(Nemagfx_Memory_Pool_Buffer Nemagfx_Memory_Pool_Buffer.*)
*(.gnu.linkonce.r.*)
. = ALIGN(0x8);
} >RAM_CMD
FontFlashSection :
{
*(FontFlashSection FontFlashSection.*)
*(.gnu.linkonce.r.*)
. = ALIGN(0x4);
} >FLASH_GFX
TextFlashSection :
{
*(TextFlashSection TextFlashSection.*)
*(.gnu.linkonce.r.*)
. = ALIGN(0x4);
} >FLASH_GFX
ExtFlashSection :
{
*(ExtFlashSection ExtFlashSection.*)
*(.gnu.linkonce.r.*)
. = ALIGN(0x4);
} >FLASH_GFX
}
4、烧录编译
编译并烧录Boot和Appli工程到开发板,可以看到工程正常运行。


5、总结
利用CubeMX和其自定义代码,以上述方式实现在同一块开发板上不同应用的程序的开发,结合TouchGFX的图形界面代码生成功能,实现在正点原子H7R7开发板上的图形应用开发。