SF32LB52x-DevKit-LCD adds SPI-LCD instance(外置)¶
1 Confirm that the rt-driver project is operating normally.¶
It is recommended to use the rt-driver project for screen adjustment, and confirm that the rt-driver project can run normally and has Log printing before debugging
1.1 Compilation¶
Enter the example\rt_driver\project
directory, right-click on ComEmu_Here
and select “Open Serial Port Compilation Command”, and then execute it step by step.
> D:\sifli\git\sdk\v2.2.4\set_env.bat #Set compilation environment path
> scons --board=sf32lb52-lcd_n16r8 -j8 #Specify sf32lb52-lcd_n16r8 module to compile rt-driver project
1.2 Enter BOOT mode¶
Confirm that the sf32lb52-lcd_n16r8
module board enters the boot
mode for easy downloading. Refer to the following steps as shown in the figure.
1.3 Download¶
> build_sf32lb52-lcd_n16r8\uart_download.bat
Uart Download
please input the serial port num:7 #然后Select the serial port number connected to the sf32lb52-lcd_n16r8 module to download
1.4 Confirm normal LOG¶
如下图,运行用户程序需要去掉勾选进入BOOT
选项,确认板子跑起来后,就可以继续下一步添加新屏幕模组
2 Add screen driver gc9107¶
2.1 Create gc9107 driver¶
1)在新的屏驱文件夹sdk-demo
中添加工程和修改Kconfig.proj文件
复制SDK\example\rt_driver
(如果已有外置的工程,可以直接在工程中进行修改添加),并修改名称,以屏驱名称命名multi_screen
放在SDK外部。并在project
中修改Konfig.proj
文件添加内容如下
#APP specific configuration.
comment "------------Project configuration-----------"
if !BSP_USING_BUILT_LCD
···
endif
2)修改proj.conf
文件
在
project\proj.conf
中添加# CONFIG_BSP_USING_BUILTIN_LCD is not set
,用来使用外置屏驱,关闭SDK内部屏驱。
如果想单独某个板子使用外置屏驱,或者使用内置屏驱,需要再project目录下新建文件例如sf32lb52-lcd_n16r8/proj.conf
其中添加# CONFIG_BSP_USING_BUILTIN_LCD is not set
或CONFIG_BSP_USING_BUILTIN_LCD=y
3) Copy driver
SDK内屏驱动位于sdk\customer\peripherals
内,复制一份其他spi
接口的驱动放在新创建的屏驱文件夹sdk-demo
中并更名为qspi_gc9107
3 Screen hardware connection¶
3.1 Ribbon connection¶
If the purchased screen module is a compatible one, simply connect the wires directly to the socket as shown in the following picture.
3.2 Flying wire connection¶
如果新的屏幕模组,排线排列不一致,就需要自己设计排线转接板或者从插针飞线调试。
The design of the adapter board can refer to SF32LB52-DevKit-LCD Adapter Board Production Guide
4 Screen driver configuration¶
4.1 Default IO configuration¶
If the default IO is adopted, this part can be skipped.
4.1.1 IO Mode Settings¶
LCD uses LCDC1 hardware to output waveforms and needs to be configured to the corresponding FUNC mode,
For each IO, which Funtion can refer to the hardware documentation DownloadSF32LB52X_Pin_config
The RESET pins of LCD and TP are in GPIO mode, so they are configured as GPIO mode by default
HAL_PIN_Set(PAD_PA00, GPIO_A0, PIN_NOPULL, 1); // #LCD_RESETB
HAL_PIN_Set(PAD_PA09, GPIO_A9, PIN_NOPULL, 1); // CTP_RESET
4.1.2 IO上下电操作¶
下面是Power-on LCD initialization process
rt_hw_lcd_ini->api_lcd_init->lcd_task->lcd_hw_open->BSP_LCD_PowerUp-find_right_driver->LCD_drv.LCD_Init->LCD_drv.LCD_ReadID->lcd_set_brightness->LCD_drv.LCD_DisplayOn
It can be seen that the power-on BSP_LCD_PowerUp
is before the screen driver initialization LCD_drv.LCD_Init
Therefore, it is necessary to ensure that the LCD power supply has been turned on in BSP_LCD_PowerUp before initializing the LCD
4.1.3 Backlight PWM configuration¶
The pwm software has a default configuration, configured in the file customer\boards\sf32lb52-lcd_n16r8\Kconfig.board
, and this configuration of Kconfig.board
will generate the following three macros in rtconfig.h
after compilation
//PWM3需要打开GPTIM2,PWM和TIMER对应关系,可以查看FAQ的PWM部分或者文件`pwm_config.h`
#define LCD_PWM_BACKLIGHT_INTERFACE_NAME "pwm3" //pwm设备名
#define LCD_PWM_BACKLIGHT_CHANEL_NUM 4 //Channel 4
#define LCD_BACKLIGHT_CONTROL_PIN 1 //PA01
Using PWM3 requires the output of GPTIM2 (located at Hcpu), and it is also necessary to confirm whether the following macros in rtconfig.h
are effective
#define BSP_USING_GPTIM2 1 //如果用PWM3,需要menuconfig --board=sf32lb52-lcd_n16r8打开
#define RT_USING_PWM 1
#define BSP_USING_PWM 1
#define BSP_USING_PWM3 1 //如果没有,需要menuconfig --board=sf32lb52-lcd_n16r8打开
如下文件pwm_config.h
中pwm3
和GPTIM2
的对应关系
#ifdef BSP_USING_PWM3
#define PWM3_CONFIG \
{ \
.tim_handle.Instance = GPTIM2, \
.tim_handle.core = PWM3_CORE, \
.name = "pwm3", \
.channel = 0 \
}
#endif /* BSP_USING_PWM3 */
The software defaults PA01 to output PWM waveform from the "pwm3"
device of GPTIM2
, with the default configuration at
HAL_PIN_Set(PAD_PA01, GPTIM2_CH4, PIN_NOPULL, 1); // LCDC1_BL_PWM_CTRL, LCD backlight PWM
备注:
After configuring through the function HAL_PIN_Set
, the correspondence between GPTIM2_CH4 and PA01 will be established, specifically reflected in the register configuration hwp_hpsys_cfg->GPTIM2_PINR
,如下图:
It can be seen that it can be configured as CH1-CH4 output, and must be PA00-PA44 port
4.2 屏驱复位时序¶
The following delays are critical and need to refer to the initialization timing of the screen drive IC related documents, modify with caution
BSP_LCD_Reset(0);//Reset LCD
HAL_Delay_us(20);
BSP_LCD_Reset(1);
4.3 屏驱寄存器修改¶
每个屏驱IC的初始化寄存器配置差异较大,需要按照屏厂提供的寄存器参数,按照他们的SPI时序依次通过SPI写入屏驱IC,特别注意0x11寄存器后的延时长度要求
LCD_WriteReg_More(hlcdc, 0x11, parameter, 1);
LCD_DRIVER_DELAY_MS(120);
LCD_WriteReg_More(hlcdc, 0xFE, parameter, 0); // internal reg enable
LCD_WriteReg_More(hlcdc, 0xEF, parameter, 0); // internal reg enable
4.4 屏驱参数配置¶
.lcd_itf : 选择LCDC_INTF_SPI_DCX_1DATA表示SPI 1线模式
.freq :选择48000000,表示SPI的clk主频为48Mhz,这个时钟要依据屏驱IC支持的最高时钟来选择,越高每帧送数时间越短,帧率会越高
.color_mode :Choose between RGB565 or RGB888 format
.syn_mode :Choose whether to enable TE anti-tearing function. If TE is enabled and the screen drive IC has no TE signal, the screen will not be sent, and a Timeout crash will occur. It is recommended to disable TE during early debugging
.vsyn_polarity :Choose the polarity of TE
.vsyn_delay_us :Choose how long after the TE waveform arrives, LCDC1 starts sending data to the screen drive IC
.readback_from_Dx : When reading Chipid via QSPI, choose which signal line among D0-D3 the data from the screen drive IC is output from(参照屏驱IC手册)
static LCDC_InitTypeDef lcdc_int_cfg =
{
.lcd_itf = LCDC_INTF_SPI_DCX_1DATA,
.freq = 48000000,
.color_mode = LCDC_PIXEL_FORMAT_RGB565,
.cfg = {
.spi = {
.dummy_clock = 0,
.syn_mode = HAL_LCDC_SYNC_DISABLE,
.vsyn_polarity = 0,
.vsyn_delay_us = 0,
.hsyn_num = 0,
},
},
};
5 Compilation烧录Download结果¶
5.1 显示结果展示¶
As shown in the figure below, if the display is normal, there will be 6 kinds of images displayed in a 3-second timed loop