開發工具: STM32CubeMX 6.6.1 (使用這個建立Library)
開發環境: STM32CubeIDE
MCU型號: STM32F103VET6(內建FSMC LCD接口)
LCD型號: ILI9488 8-bit Parallel TFT LCD
LCD Driver library:ILI9341 Driver library for STM32
使用STM32CubeMX設定IO及產生Library
RCC HSE選擇外部震盪器
SYS Devug選擇Serial Wire
Connectivity的FSMC選項,開啟NE1並選擇LCD Interface
LCD Register Select選擇A16(對應DC腳位)
Data選擇8bits(對應8-bits bus line的LCD)
NOR/PSRAM timming的Data setup time設為8
NE1->LCD CS
A16->LCD RS(D/C)
NWR->LCD WR
NOE->LCD RD
FSMC_D0~D7 ->LCD D0~D7
Clock Confirguration設置選擇PLLCLK,頻率設為72MHz。
IDE選擇STM32CubeIDE
選Code Generator勾選Generate peripheral initialization as a pair of'.c/.h' files,執行GENRATE CODE會產生需要的Libraray。
修改LCD Driver的Write command與Write data
開啟ILI9341 Driver library for STM32.c
加入宣告FSMC LCD Register與LCD Data的地址
#define LCD_REG (*(uint8_t *)0x60000000) // A16 low for writing to reg
#define LCD_DATA (*(uint8_t *)0x60010000) // A16 high for writring data
修改Write_Command與Wire_Data
void ILI9341_Write_Command(uint8_t Command)
{
LCD_REG=Command;
}
/* Send Data (char) to LCD */
void ILI9341_Write_Data(uint8_t Data)
{
LCD_DATA=Data;
}
操作到這個步驟,LCD已經可以正常驅動。
不同驅動程式有些微差異性,只差在Write command與Write data的修改,若能使用GPIO驅動,改用FSMC也應該能正常驅動。
透過DMA提升顯示速度
DMA是Memory到Memory,可以將內部記憶體資料傳送給FSMC LCD接口,因為是memory到memory,所以不會占用CPU使用率。
System Core的DMA,於DMA1新增MEMTOMEM。
使用DMA主要是將資料進行搬移,所以資料移動一定會是連續的,例如將圖檔資料搬到LCD GRAM。
所以會是針對Fill Screen、Draw rect等需要連續寫入資料的function進行修改。
HAL_DMA_Start是啟動DMA開始進行傳送
第一個參數是dam地址:&hdma_memtomem_dma1_channel1
第二個參數是要搬運資料的地址: (uint32_t)&SRC_RED_Buffer
第三個參數是FSMC Write data的地址:(uint32_t)&LCD_DATA
第四個是資料長度:640 (最大值為65535)
HAL_DMA_Start(&hdma_memtomem_dma1_channel1, (uint32_t)&SRC_RED_Buffer, (uint32_t)&LCD_DATA,640);
HAL_DMA_PollForTransfer(&hdma_memtomem_dma1_channel1, HAL_DMA_FULL_TRANSFER, 1000);
下面是自行定義一個1*320的橫線,再透過DMA傳輸480次填滿整個畫面,顯示速度約15FPS。
#define BUFFER_SIZE 640
const uint8_t SRC_RED_Buffer[BUFFER_SIZE] = { 0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00};
修改範例如下
void ILI9341_Fill_Screen(uint16_t Colour)
{
ILI9341_Set_Address(0,0,LCD_WIDTH-1,LCD_HEIGHT-1);
ILI9341_Write_Command(0x2C);
uint32_t img_size=LCD_WIDTH*LCD_HEIGHT;
uint32_t img_page=img_size/(640/2);//(8bit 640 need /2 = 16bit color)
for(uint16_t i=0;i<=img_page;i++){
HAL_StatusTypeDef DMA_status = HAL_ERROR;
HAL_DMA_Start(&hdma_memtomem_dma1_channel1, (uint32_t)&SRC_RED_Buffer, (uint32_t)&LCD_DATA,640);
HAL_DMA_PollForTransfer(&hdma_memtomem_dma1_channel1, HAL_DMA_FULL_TRANSFER, 1000);
}
}
留言列表