跳转到主要内容

TouchGFX on NeoChrom/NeoChromVG

本节讨论如何在具有NeoChrom图形加速器的硬件上使用TouchGFX。 该图形加速器显著提高了纹理映射、图像缩放和旋转等操作的性能。 这意味着可以在保持高帧速率的同时构建更高级的UI。

NeoChrom图形加速器目前仅在STM32U5x9微控制器中提供,如:STM32U599 Discovery Kit。

STM32U599 Discovery板

NeoChrom加速器在源代码和CubeMX中也被称为GPU2D。

NeoChrom and NeoChromVG

The NeoChrom accelerator has been updated with extra capabilities with the introduction of STM32U5G9. The improved accelerator is named NeoChromVG. The accelerator contains extended capabilities that allows hardware accelerated vector graphics.

Micro controllerAccelerator
STM32U599NeoChrom
STM32U5A9NeoChrom
STM32U5F9NeoChromVG
STM32U5G9NeoChromVG

NeoChrom图形功能

The NeoChrom accelerators are capable of performing basic blitting (drawing images), blending, scaling, rotation, and texture mapping. All such operations are automatically used by TouchGFX when running on a microcontroller with NeoChrom.

与DMA2D图形加速器相比,NeoChrom能够加速更多的图形操作,并具有更丰富的功能集:

图形特征DMA2DGPU2D
支持的格式(带TouchGFX)ARGB8888, RGB888, RGB565, A8, A4, L8ARGB8888, RGB888, RGB565, A8, A4, A2, A1
基于命令列表
绘图矩形矩形、像素、直线、三角形、四边形以及多采样抗锯齿(MSAA)
位图复制复制alpha混合像素格式转换复制、alpha混合、像素格式转换、颜色键控
纹理映射
Vector GraphicsNo*

* Hardware accelerated Vector Graphics is available with NeoChromVG.

凭借这些功能,NeoChrom可以加速更多的TouchGFX控件:

控件DMA2DGPU2D
Box, BoxWithBorder
Image, AnimatedImage, TiledImage, SnapshotWidget
Button, ButtonWithIcon, ButtonWithLabel, ToggleButton
RadioButton, RepeatButton
PixelDataWidget
TextArea, TextAreaWithWildcard, KeyboardPartly
ScalableImage
TextureMapper, AnimatedTextureMapper
Circle, Line, Graph, Gauge
SVGNo*

* Hardware accelerated SVG is available with NeoChromVG.

非硬件加速的操作属于软件渲染操作(意味着更高的CPU负载和更低的性能)。 如上表所示,NeoChrom能加速ScalableImage和纹TextureMapper等控件。 这意味着我们可以在保持高性能的同时更大程度地使用这些控件。

Vector Graphics

The new NeoChromVG accelerator can accelerate vector graphics. This capability is used when rendering SVG images with TouchGFX. An extra buffer called the stencil buffer is required by the graphics accelerator. This buffer has the same dimension as the frame buffer, but only 1 byte pr pixel.

Example, if your frame buffer is 480 x 480 in 24bpp, the stencil buffer must be 480 * 480 = 230.400 bytes. It is important to allocate the stencil buffer in fast SRAM for best performance.

The stencil buffer is allocated by the TouchGFX Generator. See this guide.

使用NeoChrom改善渲染时间.

以下示例说明NeoChrom在DMA2D和软件渲染方面提供的加速。 我们利用设计器创建了两个项目。 第一个项目是在方框背景上显示Image。 第二个项目在Box背景上显示TextureMapper Widget。 控件在每一帧中都会重新绘制。 这两种情况下,位图大小为128x128,采用ARGB888格式,并存储在内部Flash中。 帧缓存采用RGB565格式。

Image项目

TextureMapper项目

两个项目在STM32F746和STM32U599 Discovery板上执行。

我们将GPIO连接到逻辑分析仪来测量渲染时间:

STM32F746运行Image项目

上图显示了在STM32F746上运行时的帧速率和渲染时间。 通道00显示VSYNC信号。 我们看到,显示器以16.9ms(A1至A2)的帧间隔运行,对应59.2Hz帧速率。 通道01显示渲染时间(渲染时较高,B1到B2)。 因此,渲染Image的时间为1.3 ms。 STM32F746上的Image渲染速度快。

STM32F746运行TextureMapper项目

上图为STM32F746上运行的TextureMapper项目。 TextureMapper的渲染时间为 4.5 ms。 TextureMapper控件比Image慢得多。

STM32U599运行Image项目

此为运行Image项目的STM32U599 Discovery套件。 STM32U599 Discovery套件显示屏的显示帧间隔为12.26 ms,对应81.6 Hz帧速率。 Image的渲染时间为 0.7 ms。 我们看到Image控件比STM32F746套件更快。

STM32U599运行TextureMapper项目

TextureMapper的渲染时间为 1.7 ms。 与STM32F746相比,STM32U599上的TextureMapper速度更快。

渲染时间总结

下表显示了渲染时间:

元素STM32F746STM32U599加快
频率200 MHz160 MHz0.8
图像1.3 ms0.7 ms~2x
TextureMapper4.5 ms1.7 ms~3x

我们看到,即使时钟频率降低,STM32U599也大大优于STM32F746,TextureMapper尤为如此。

对于STM32F746,使用内部闪存中的图像和外部SDRAM中的帧缓存进行此类测量。 STM32U599的帧缓存位于内部SRAM中(此为典型情况)。 将图像移至外部Flash会更加降低STM32F746性能,因其使用QSPI Flash(4位总线),而STM32U599使用更快的OSPI Flash(8位总线)。

STM32F746 Discovery套件可在内部RAM中使用480x272 RGB565帧缓存运行。 从而提高了性能(Image降至1.03ms),但其并非STM32F746的标准配置,因为它使用了很大一部分内部SRAM作为帧缓存,只剩下很少的RAM用于其他应用程序组件。
利用单帧缓存运行也不适用于所有应用程序。

更丰富的用户界面

改进的渲染性能可用于创建具有更高级动画的用户界面。 例如,更多缩放或旋转元素。
对于STM32F746,帧刷新时间为16.8ms。 这意味着应用程序必须将渲染时间保持在该值以下,以保持60fps的帧速率。 因此,屏幕上最多可以有3.75个此种复杂度(16.8毫秒/4.48毫秒)的纹理映射器,或者一个尺寸为247 x 247(像素数量相同,渲染时间大致相同)的较大纹理映射器。
如果我们假设屏幕刷新率相同,但使用STM32U599 CPU,则可以有14.36个纹理映射器(16.8毫秒/1.17毫秒),或一个485 x 485大小的单个纹理映射器。

下图显示了分别在STM32F746和STM32U599上运行的两个应用程序。 其想法是制作一个类似旋转木马的菜单,其中元素在到达中心时被放大,离开时被缩小(这里我们对所有元素使用相同的纹理)。

STM32F746(左)和STM32U599(右)运行基于纹理映射器的旋转木马项目

STM32F746能够显示三个图标,一个放大1.9倍的大图标和两个较小的图标。 STM32U599能显示7个图标。 最大的图标放大了2.7倍。

STM32F746上3图标应用程序的渲染时间为14.38 ms。 STM32U599上7图标应用程序的渲染时间为14.93 ms。 因此,两种UI均能以60 fps的速度运行,STM32U599以更高的分辨率显示更多内容。

Accelerated Vector Graphics

The new NeoChromVG accelerator is capable of accelerating vector graphics. This open the possibilities of a new class of applications, where vector based graphics plays a central role and not bitmaps.

One example is a map-application. Maps can be built from bitmaps, but that often requires a very large storage or that specific map sections are downloaded in advance.

The video below shows a demonstration application running on a STM32U5F9. The application zooms, rotates, and pans a map that is drawn from a vector definition (multiple polygons that are filled with different colors and stroked). The video is running full screen on a 800 x 480 display with 16bpp colors.

STM32U5F9 showing a moving map.

Coordinate limitations

Vector graphics with coordinates above 1024 are by default discarded on NeoChrom and NeoChrom. See here for a work-around. Note, this happens both when an SVG image is scaled up or if the SVG contains large coordinates in itself.

创建项目

CubeMX和TouchGFX Generator支持NeoChrom。 在CubeMX中,加速器的代号为GPU2D。 如果在CubeMX的TouchGFX配置中启用了GPU2D,则GPU2D加速器仅对TouchGFX可用。
如果您使用TouchGFX 设计器提供的STM32U599 TBS(模板项目),则已完成启用。 如果您创建自己的定制项目,请确保启用GPU2D加速器,如下所示:

在CubeMX中启用GPU2D(NeoChrom)

启用GPU2D后,按CubeMX中的“生成代码”。 重新生成目标配置代码。 然后,在TouchGFX 设计器中打开项目并在那里生成代码(F4)。

Designer生成与目标配置匹配的资产(图像、字体和文本)和模拟器代码。 现在,您可以使用IAR编译代码。

如果您从Designer启动项目,则无需打开CubeMX,除非您需要更改某些硬件设置。

支持的IDE

STM32U599 TBS(3.0.0版)目前仅支持IAR Workbench。

需要最新版IAR(8.5x.x)。 通过检查“常规选项”,确保处理器型号的适用性(STM32U599NJ用于Discovery板):

IAR常规选项

帧缓存格式

STM32U599 Discovery板支持三种帧缓存格式:RGB565, RGB888, ARGB8888。 可从CubeMX进行配置。

NeoChrom限制

STM32U599中的NeoChrom图形加速器不支持L8图像格式(L8_RGB565、L8_RGB888、L8_ARGB8888)。
如果在STM32U599上运行的TouchGFX应用程序中使用这些图像格式,则将使用DMA2D绘制图像。 如果将这些格式与ScalableImage或TextureMapper一起使用,将使用软件回退。

因此,建议不要将L8图像与STM32U599一起使用。