跳转到主要内容

编译& 烧录

本节描述如何完成从TouchGFX应用程序代码到程序执行这一过程,即如何在特定的设置中进行编译和烧录。

编译TouchGFX应用程序

当编译一个TouchGFX应用程序时,有两个选项:面向PC模拟器进行编译,或面向目标硬件进行编译。

面向PC模拟器进行编译

面向PC模拟器编译项目时有两个选项:GCC和Visual Studio。
这两个选项始终可用,因为它们是由TouchGFX Designer生成的。

GCC

Makefile的位置<touchgfx_application_root_folder>/simulator/gcc/Makefile

TouchGFX包含一个MinGW环境,该环境预装了一个GCC编译器和GNU Make,可以轻松执行面向PC模拟器生成的Makefile。

TouchGFX Environment可以从C:/TouchGFX/4.18.0/env/MinGW/msys/1.0/msys.bat启动,或者从添加到Windows启动菜单的快捷方式(名为“TouchGFX x.y.z Environment”,其中x、y和z描述版本号)启动。

在启动TouchGFX Environment并导航到TouchGFX Application根文件夹后,可以执行下面的简单命令以生成一个simulator.exe文件。

make -f simulator/gcc/Makefile

然后可以使用以下命令从TouchGFX Environment启动模拟器可执行文件。

./build/bin/simulator.exe

也可以从TouchGFX Designer编译和启动PC模拟器,方法是使用Run Simulator命令。

Visual Studio

要使用Visual Studio编译PC Simulator,只需使用Visual Studio打开位于<touchgfx_application_root_folder>/simulator/msvs/Application.sln的已生成解决方案文件。

可以直接从Visual Studio启动PC 模拟器,启用代码调试

Note
在运用GCC或Visual Studio进行编译之前,从TouchGFX Designer运行Generate命令。

面向目标硬件进行编译

对于基于TouchGFX板卡设置的应用程序来说,面向STM32评估套件进行项目编译是非常简单的。

每个TouchGFX板卡设置包含面向GCC、STM32CubeIDE、IAR和Keil的项目文件:

  • GCC: <project_root_folder>/gcc/MakeFile
  • STM32CubeIDE: <project_root_folder>/STM32CubeIDE/.cproject
  • IAR: <project_root_folder>/EWARM/Project.eww
  • Keil: <project_root_folder>/MDK-ARM/<STM32_evaluation_kit_name>.uvprojx

STM32CubeMX默认设置的活动工具链为STM32CubeIDE。 请注意!所有项目文件不会同时出现。 生成的项目文件取决于在STM32CubeMX中选择的工具链

TouchGFX includes a MinGW environment, that comes preinstalled with the GNU Embedded tool-chain for Arm and GNU Make, making it easy to execute the included Makefile for the target hardware.

TouchGFX Environment可以从C:/TouchGFX/4.18.0/env/MinGW/msys/1.0/msys.bat启动,或者从添加到Windows启动菜单的快捷方式“TouchGFX x.y.z Environment”启动

在启动TouchGFX Environment并导航到项目根文件夹后,可以执行下面的简单命令,面向目标硬件进行项目编译。

make -f gcc/Makefile
Note
在运用GCC、STM32CubeIDE、IAR或Keil进行编译之前,从TouchGFX Designer运行Generate命令。

烧录STM32评估套件

因为项目基于预先完成的TouchGFX板卡设置,将项目烧录到STM32评估套件是非常轻松的。

每个项目在构建之后都会生成一个二进制文件,该文件可以通过ST Link UtilitySTM32CubeProgrammer刷写。

因此,必须安装这些工具,才能进行烧录。

建议将这些工具安装到默认位置。

  • ST Link Utility默认安装位置:
    C:/Program Files (x86)/STMicroelectronics/STM32 ST-LINK Utility/ST-LINK Utility
  • STM32CubeProgrammer默认安装位置:
    C:/Program Files/STMicroelectronics/STM32Cube/STM32CubeProgrammer
Note
TouchGFX板卡设置不提供任何flash loader,用于直接从IAR、Keil、STM32CubeIDE或其他IDE进行烧录。

GCC与TouchGFX Designer

The Makefile included with an TouchGFX Board Setup located at <project_root_folder>/gcc/MakeFile has a built-in flash command, as shown below, that uses either ST Link Utility or STM32CubeProgrammer (depending on the TBS) to flash the STM32 Evaluation Kit.

You can start the flashing from the command-line using the same command as TouchGFX Designer uses:

make -f gcc/Makefile flash

You can also use the desktop version of the flash tools to flash the boards with the generated .hex files. The .hex file is located at <project_root_folder>/TouchGFX/build/bin/target.hex

Flashing the internal flash only

Many development boards and products use two flashes. The internal flash of the micro controller and an external flash. Typically, the internal flash contains the code and small/often used data, whereas the external flash contains large data items like images, videos and fonts.

In many situations, you need to flash both flashes at the same time as the program in the internal flash contains addresses pointing to the data in the external flash. But in some cases it is possible to flash the internal flash without flashing the external flash, for example when you have made small modifications to the application code (like changing the color or position of a Box). In this case, all the data in the external flash is unmodified and there is no need to flash it again. This can reduce the flash time considerably if you have a large set of images.

However, you need to be sure that the content for the external flash has not changed since you wrote the external flash last time. If it has, and you do not flash it again, you will see strange behavior. In this case: flash both the internal and external flash.

make -f gcc/Makefile intflash

The .hex file for the internal flash is located at: <project_root_folder>/TouchGFX/build/bin/intflash.hex.

Linker script

The intflash make target first compiles and links the application. It then flashes the intflash.hex file. This file is produced after the linking step by removing the ExternalFlashSection, TextFlashSection, and FontFlashSection sections from the application elf file. This is done using the following command:

arm-none-eabi-objcopy -O ihex --remove-section=ExtFlashSection --remove-section=FontFlashSection --remove-section=TextFlashSection target.elf intflash.hex

The result of this command is a hex-file containing only the data that is located in the internal flash. This will only work if the linker script only puts the three aforementioned sections into the external flash. The gcc linker script for the TouchGFX Board Setups typically looks like:

...  /* Details skipped */

MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 320K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
QUADSPI (r) : ORIGIN = 0x90000000, LENGTH = 16M
SDRAM (xrw) : ORIGIN = 0xC0000000, LENGTH = 8M
}

SECTIONS
{
... /* Sections for RAM, Flash, SDRAM */

ExtFlashSection :
{
*(ExtFlashSection ExtFlashSection.*)
*(.gnu.linkonce.r.*)
. = ALIGN(0x4);
} >QUADSPI

FontFlashSection :
{
*(FontFlashSection FontFlashSection.*)
*(.gnu.linkonce.r.*)
. = ALIGN(0x4);
} >QUADSPI

TextFlashSection :
{
*(TextFlashSection TextFlashSection.*)
*(.gnu.linkonce.r.*)
. = ALIGN(0x4);
} >QUADSPI
}

The linker script first defines 4 memory regions: RAM, FLASH, QUADSPI, and SDRAM. The QUADSPI region is the external flash. The 3 sections ExtFlashSection, FontFlashSection, and TextFlashSections are linked into the QUADSPI region. Nothing else is put into the QUADSPI region. This is the reason that we can produce a hex file for the internal flash by removing these 3 section from the target.elf file, which contains everything. If the linker script also puts other data into the external flash, we would need to remove that data also to end up with the internal flash content only.

If you build your target elf file using other makefiles or compilers, you can reuse the technique above to create a hex file for the internal flash and flash it from TouchGFX Designer or the command-line.

TouchGFX Designer Configuration

The TouchGFX Board Setup provides the configuration for TouchGFX Designer to be able to flash projects via the Run Target Command. 被TouchGFX Designer用于进行烧录的命令可以在TouchGFX Designer中配置视图构建部分看见并覆盖。

STM32CubeIDE

TouchGFX板卡设置使用STM32CubeIDE输出的.elf文件支持通过STM32CubeProgrammer对用STM32CubeIDE编译的项目进行烧录。

.elf文件位于<project_root_folder>/STM32CubeIDE/Debug/<STM32_evaluation_kit_name>.elf

e.g. C:/TouchGFXProjects/MyApplication/STM32CubeIDE/Debug/STM32F746G_DISCO.elf

IAR

TouchGFX板卡设置使用IAR输出的.hex文件支持通过STM32CubeProgrammer对用IAR编译的项目进行烧录。

.hex文件位于<project_root_folder>/EWARM/<STM32_evaluation_kit_name>/Exe/<STM32_evaluation_kit_name>.hex

例如,C:/TouchGFXProjects/MyApplication/EWARM/STM32F469I-DISCO/STM32F469I-DISCO.hex

Keil

TouchGFX板卡设置使用Keil输出的.hex文件支持通过STM32CubeProgrammer对用Keil编译的项目进行烧录。

.hex文件位于<project_root_folder>/MDK-ARM/<STM32_evaluation_kit_name>/<STM32_evaluation_kit_name>.hex

e.g. C:/TouchGFXProjects/MyApplication/MDK-ARM/STM32F469I-DISCO/STM32F469I-DISCO.hex

烧录自定义硬件

如果需要刷写的是自定义硬件,而不是STM32评估套件这样的预定义硬件设置,则仍然可以使用STM32CubeProgrammer。 STM32CubeProgrammer不一定带有针对你的特定外部存储器的flash加载机制。 然而,可以创建一个自定义的flash loader。 参阅关于如何为外部存储器开发自定义加载器的用户手册可了解更多信息。