驅動程式
驅動程式一節可協助開發人員為TouchGFX AL的各種功能選擇驅動程式。
應用時標源(Application Tick Source)
應用程式的應用時標源,定義了如何驅動應用程式進行運作。開發人員有以下的選項:
- LTDC:如果在「Display」(顯示)群組將介面設為「LTDC」,則應用時標源即可設定為「LTDC」。這表示TouchGFX Generator將在
TouchGFXGeneratedHAL類別中置入驅動程式函數(LTDC中斷處理常式),並在此驅動程式函數中呼叫OSWrappers::signalVSync()以驅動應用程式運作。 - Custom and FMC (客製和FMC):在這種情況下,開發人員需要實作處理常式,以重複呼叫
OSWrappers::signalVSync()的方式驅動應用程式運作。
Further reading
DMA2D Accelerator (Chrom-ART)
關於DMA2D圖形加速開發人員有三個選項:
- No(否):應用程式只使用CPU進行渲染。
- Yes - The application uses the Chrom-ART chip when possible to move and blend pixels, freeing up CPU cycles. 驅動程式由TouchGFX Generator產生,因此開發人員不需要做任何動作。
- Custom (客製):TouchGFX Generator會產生泛型TouchGFX DMA類別,繼承自TouchGFX引擎的DMA介面,並有開發人員必須實作用於客製圖形加速器的成員函數。
為了能在TouchGFX Generator中選擇DMA2D加速器,必須在STM32CubeMX的Multimedia(多媒體)類別中將其啟用:
Platforms that have DMA2D v3 (e.g., STM32H5Fx/H5Ex series) should activate it in Command List Mode for best performance.
Further reading
The DMA2D (Chrom-ART) driver generated by TouchGFX Generator supports two ways of receiving a TransferCompleteInterrupt:
- 使用STM32Cube HAL驅動程式,其中將回呼函數暫存到dma2d的控制程式碼(handle)
hdma2d. XferCpltCallback。 - 直接使用中斷處理常式
DMA2D_IRQHandler ()。
如果要在以上兩者之間進行切換,請於適用於DMA2D IP的STM32CubeMX之中,在NVIC Settings (NVIC設定)啟用或停用DMA2D全域中斷:
啟用全域中斷可產生選項1)的程式碼,停用全域中斷可產生選項2)的程式碼。
Note
GFXPAND Decoder (Chrom-DEC)
GFXPAND (Chrom-DEC) is a compressed graphics decoder capable of accelerating the decompression of L8 RLE and RGB (QOI and QOI565) compressed images. It works together with the DMA2D (Chrom-ART) accelerator to draw compressed images to the framebuffer, freeing up CPU cycles. 其中可支援RGB565、RGB888及ARGB8888格式的影像緩衝區。 GFXPAND is currently available on STM32U3A6 MCUs.
The developer has two options when it comes to GFXPAND decoding:
- No - Compressed images are decompressed using only the CPU.
- Yes - The application uses the Chrom-DEC decoder to decompress L8 RLE and RGB compressed images when they are drawn. 驅動程式由TouchGFX Generator產生,因此開發人員不需要做任何動作。
To be able to select Use GFXPAND decoder (Chrom-DEC) in TouchGFX Generator, the following conditions must be met:
- The GFXPAND peripheral must be activated in STM32CubeMX.
- The framebuffer pixel format must be RGB565, RGB888, or ARGB8888.
Note
The GFXPAND driver generated by TouchGFX Generator uses two DMA channels to transfer data to and from the GFXPAND. A DMA channel must be configured for both the GFXPAND input and the GFXPAND output in the GFXPAND configuration in STM32CubeMX. The interrupt for the DMA channel used for the GFXPAND output must be enabled in the NVIC settings.
Further reading
When GFXPAND is enabled, the setting Scratch Buffer Size appears in the TouchGFX Generator:
The setting Scratch Buffer Size sets the size in bytes of each of the two scratch buffers used by the GFXPAND driver. The default size is 960 bytes and the minimum size is 256 bytes. The scratch buffers are used when the decompressed pixels must be alpha blended and/or have unaligned destination addresses. The pixels in the scratch buffer are processed by DMA2D before being written to the framebuffer while the other buffer is filled by the GFXPAND. Otherwise, the decompressed pixels are transferred directly to the framebuffer. Generally, larger scratchbuffers improve render performance.
The size must be a multiple of 16 bytes when the framebuffer format is 16 bpp or 32 bpp, and a multiple of 48 bytes when the framebuffer format is 24 bpp.
GPU2D加速器(NeoChrom)
GPU2D (NeoChrom)是圖形加速器,能夠加速TouchGFX之中許多的繪製操作,包括紋理映射及向量渲染。其中可支援RGB565、RGB888及ARGB8888格式的影像緩衝區。
關於GPU2D圖形加速開發人員有兩個選項:
- No(否):應用程式只使用CPU進行繪製。
- Yes(是):應用程式會在可能情況下使用NeoChrom晶片,以加速由TouchGFX進行的許多繪製操作。驅動程式由TouchGFX Generator產生,因此開發人員不需要做任何動作。
為了能在TouchGFX Generator中選擇GPU2D加速器,必須在STM32CubeMX的Multimedia(多媒體)類別中將其啟用:
Note
啟用時,TouchGFX Generator會出現新的區段(GPU2D Driver (GPU2D驅動程式)):
GPU2D Command List Size (GPU2D指令清單大小)設定,可依據位元組為單位設定GPU2D使用的指令清單大小。
Note
即時作業系統
開發人員可在TouchGFX使用任何的RTOS(甚至不使用作業系統)。如抽象層架構所述,TouchGFX引擎會依據使用者所選的RTOS,使用OSWrappers介面來同步本身的主要事件迴圈與影像緩衝區存取。開發人員在TouchGFX Generator選擇作業系統時,將產生程式碼並透過所選作業系統的基本型別實現內部同步。作業系統仍然必須透過STM32CubeMX進行設定,以確定堆疊大小等各種項目。
FreeRTOS (CMSIS OS V1和V2)和ThreadX (原生中介軟體或Azure RTOS套裝軟體)可直接在STM32CubeMX和TouchGFX Generator中設定,為使用者提供產生的程式碼,用於工作定義和TouchGFX RTOS驅動程式。 TouchGFX Generator可產生符合CMSIS V1和CMSIS V2標準的RTOS驅動程式,與任何符合CMSIS標準的RTOS一起執行,一個用於ThreadX的驅動程式,一個用於在沒有作業系統(無OS)的情況下執行裸機的驅動程式。
無OS
如果需要在沒有作業系統的情況下執行TouchGFX,只要在STM32CubeMX中的Middleware and Software Packs(中介軟體及套裝軟體)類別沒有啟用作業系統,或是選擇X-CUBE,TouchGFX Generator中的No OS(無OS)選項就會出現。
Further reading
FreeRTOS
為了能在TouchGFX Generator中選擇CMSIS_RTOS_V1或CMSIS_RTOS_V2,必須在STM32CubeMX的Middleware and Software Packs(中介軟體及套裝軟體)類別中啟用FreeRTOS:
部分TouchGFX開發板設定並未預設設定使用FreeRTOS中介軟體,而是使用ThreadX或NoOS(例如STM32U599)。如果您仍希望以這類TouchGFX開發板設定使用FreeRTOS,就必須在STM32CubeMX的Software Packs Components Selector(套裝軟體元件選擇器)下載X-CUBE-FreeRTOS套件並加以啟用。
Further reading
ThreadX
如要啟用ThreadX,可選擇X-CUBE套裝軟體,或是由STM32CubeMX啟用原生ThreadX中介軟體(如果適用於選定的MCU裝置)。
開發人員應能發現ThreadX是設定為X-CUBE套裝軟體或原生ThreadX中介軟體,以用於特定的MCU系列。
Note
下節將說明如何為應用程式啟用ThreadX作為中介軟體或AZRTOS套裝軟體。
由Middleware and Software Packs(中介軟體及套裝軟體)類別啟用ThreadX
為了能在TouchGFX Generator中選擇ThreadX,必須在STM32CubeMX的Middleware and Software Packs(中介軟體及套裝軟體)類別中啟用ThreadX。
啟用之後,ThreadX選項就會出現在TouchGFX Generator之中。
Further reading
由X-CUBE套裝軟體啟用ThreadX
為了能在TouchGFX Generator中選擇ThreadX,必須在STM32CubeMX中的Software Packs Component Selector (套裝軟體元件選擇器)中啟用AZRTOS套裝軟體。請在專案中點擊「Select Components」(選擇元件)按鈕或 Alt + o (位在STM32CubeMX的專案選單)。
下圖顯示如何為專案啟用AZRTOS套裝軟體。請選擇RTOS ThreadX,然後勾選Core (核心)核取方塊以啟用ThreadX。如果尚未完成,請下載及安裝套裝軟體。
將ThreadX套裝軟體新增至專案後,X-CUBE應該會出現在STM32CubeMX專案選單左側的Middleware and Software Packs(中介軟體及套裝軟體)類別之下。
ThreadX啟用後,也會在TouchGFX Generator之中成為可用選項;如果在Memory Pool Size(記憶體集區大小)和Memory Stack Size(記憶體堆疊大小)中加以選取,將會出現下列值:
前述值應足以包含執行緒資源。
Further reading
其他符合CMSIS標準的作業系統
若開發人員不使用STM32CubeMX所提供的FreeRTOS和ThreadX,而要採用其他符合CMSIS標準的作業系統,就必須自行手動完成RTOS設定和工作定義。 TouchGFX Generator將產生空白的OSWrappers介面,必須由開發人員實作。通常需要進行以下手動步驟:
- 設定RTOS
- 實作
OSWrappers介面 - 定義工作以執行TouchGFX (
MX_TouchGFX_Process) - 啟動排程器
呼叫MX_TouchGFX_Process以便在工作處理常式之中啟動TouchGFX引擎主迴圈。
void MX_TouchGFX_Process(void);














