本帖最后由 zhjb1 于 2024-4-28 14:06 编辑
一、TFTLCD测试
看了网友介绍可以用STM的CUBEMX创建同类芯片工程机械测试,尝试建立了一个工程,目标首先是可以驱显各类TFTLCD,并观看驱显速度。
其他功能性测试都有官方工程,应该不会有问题。而官方的TFTLCD估计驱显的LCD较大,实际在操作中用自己的板子始终调试不通,只好放弃。
1.创建工程
首先打开“STM32CubeMX”,本机是V5.3版的,由于已经年久IP失效,时钟设置总是X的禁用符号,导出项目时也报IP失效,Clock设置无效,但看system_clock文档应该还是能设置的,并且应该差不多正确。
2.打开此项目开始设置
本例是采用STM32F103VET6中修改原子驱显项目成功的实例,仅仅将LCD部分导入到新建项目中,设置好项目文件定位、文件链接、设置AMP_LINK等就完了。
在本项目中有MX_FSMC_Init()的代码:
//FSMC initialization function
static void MX_FSMC_Init(void){
//USER CODE END FSMC_Init 0
FSMC_NORSRAM_TimingTypeDef Timing = {0};
FSMC_NORSRAM_TimingTypeDef ExtTiming = {0};
//Perform the SRAM1 memory initialization sequence
hsram1.Instance = FSMC_NORSRAM_DEVICE;
hsram1.Extended = FSMC_NORSRAM_EXTENDED_DEVICE;
//hsram1.Init
hsram1.Init.NSBank = FSMC_NORSRAM_BANK1;
hsram1.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE;
hsram1.Init.MemoryType = FSMC_MEMORY_TYPE_SRAM;
hsram1.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16;
hsram1.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE;
hsram1.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;
hsram1.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;
hsram1.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;
hsram1.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE;
hsram1.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;
hsram1.Init.ExtendedMode = FSMC_EXTENDED_MODE_ENABLE;
hsram1.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;
hsram1.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
hsram1.Init.PageSize = FSMC_PAGE_SIZE_NONE;
//Timing
Timing.AddressSetupTime = 15;
Timing.AddressHoldTime = 15;
Timing.DataSetupTime = 255;
Timing.BusTurnAroundDuration = 15;
Timing.CLKDivision = 16;
Timing.DataLatency = 17;
Timing.AccessMode = FSMC_ACCESS_MODE_A;
//ExtTiming
ExtTiming.AddressSetupTime = 15;
ExtTiming.AddressHoldTime = 15;
ExtTiming.DataSetupTime = 255;
ExtTiming.BusTurnAroundDuration = 15;
ExtTiming.CLKDivision = 16;
ExtTiming.DataLatency = 17;
ExtTiming.AccessMode = FSMC_ACCESS_MODE_A;
if (HAL_SRAM_Init(&hsram1, &Timing, &ExtTiming) != HAL_OK){Error_Handler( );}
}
//This function is executed in case of error occurrence.
void Error_Handler(void){
//User can add his own implementation to report the HAL error return state
}
在遍历项目中搜到一个在stm32f4xx_hal_msp.c中有一个基于FSMC的GPIO设置,见下边:
static uint32_t FSMC_Initialized = 0;
static void HAL_FSMC_MspInit(void){
/* USER CODE BEGIN FSMC_MspInit 0 */
/* USER CODE END FSMC_MspInit 0 */
GPIO_InitTypeDef GPIO_InitStruct ={0};
if (FSMC_Initialized) {
return;
}
FSMC_Initialized = 1;
/* Peripheral clock enable */
__HAL_RCC_FSMC_CLK_ENABLE();
/** FSMC GPIO Configuration
PE7 ------> FSMC_D4
PE8 ------> FSMC_D5
PE9 ------> FSMC_D6
PE10 ------> FSMC_D7
PE11 ------> FSMC_D8
PE12 ------> FSMC_D9
PE13 ------> FSMC_D10
PE14 ------> FSMC_D11
PE15 ------> FSMC_D12
PD8 ------> FSMC_D13
PD9 ------> FSMC_D14
PD10 ------> FSMC_D15
PD11 ------> FSMC_A16
PD14 ------> FSMC_D0
PD15 ------> FSMC_D1
PD0 ------> FSMC_D2
PD1 ------> FSMC_D3
PD4 ------> FSMC_NOE
PD5 ------> FSMC_NWE
PD7 ------> FSMC_NE1
*/
GPIO_InitStruct.Pin = lcdAD4_Pin|lcdAD5_Pin|lcdAD6_Pin|lcdAD7_Pin
|lcdAD8_Pin|lcdAD9_Pin|lcdAD10_Pin|lcdAD11_Pin
|lcdAD12_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
GPIO_InitStruct.Pin = lcdAD13_Pin|lcdAD14_Pin|lcdAD15_Pin|lcdA0_Pin
|lcdAD0_Pin|lcdAD1_Pin|lcdAD2_Pin|lcdAD3_Pin
|lcdRD_Pin|lcdWR_Pin|lcdCS_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/* USER CODE BEGIN FSMC_MspInit 1 */
/* USER CODE END FSMC_MspInit 1 */
}
修改后在本项目中的lcd.c中代码如下:
void LCD_GPIO_Init(void){
//SET FSMC GPIOs
GPIO_InitTypeDef GPIO_InitStruct ={0};
if(FSMC_Initialized){return;}
FSMC_Initialized = 1;
//Peripheral clock enable
__HAL_RCC_FSMC_CLK_ENABLE();
/*FSMC GPIO Configuration:
PD14 ------> FSMC_D0
PD15 ------> FSMC_D1
PD0 ------> FSMC_D2
PD1 ------> FSMC_D3
PE7 ------> FSMC_D4
PE8 ------> FSMC_D5
PE9 ------> FSMC_D6
PE10 ------> FSMC_D7
PE11 ------> FSMC_D8
PE12 ------> FSMC_D9
PE13 ------> FSMC_D10
PE14 ------> FSMC_D11
PE15 ------> FSMC_D12
PD8 ------> FSMC_D13
PD9 ------> FSMC_D14
PD10 ------> FSMC_D15
PD11 ------> FSMC_A0-D/C
PD4 ------> FSMC_NOE
PD5 ------> FSMC_NWE
PD7 ------> FSMC_NE1-CS*/
//SFMC GPIOE pins:GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
GPIO_InitStruct.Pin=lcdAD4_Pin|lcdAD5_Pin|lcdAD6_Pin|lcdAD7_Pin|lcdAD8_Pin|lcdAD9_Pin|lcdAD10_Pin|lcdAD11_Pin|lcdAD12_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;//GPIO_SPEED_FREQ_LOW;//GPIO_SPEED_FREQ_MEDIUM;//
GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
//SFMC GPIO Configure GPIO pins:GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;
GPIO_InitStruct.Pin=lcdAD0_Pin|lcdAD1_Pin|lcdAD2_Pin|lcdAD3_Pin|lcdAD13_Pin|lcdAD14_Pin|lcdAD15_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;//GPIO_SPEED_FREQ_LOW;//GPIO_SPEED_FREQ_MEDIUM;//
GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
//SFMC GPIO Configure GPIO pins:GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_7|GPIO_PIN_11;
GPIO_InitStruct.Pin=lcdRD_Pin|lcdWR_Pin|lcdA0_Pin|lcdCS_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;//GPIO_SPEED_FREQ_LOW;//GPIO_SPEED_FREQ_MEDIUM;//
GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
//RST_PA_15 or NRST
GPIO_InitStruct.Pin = GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;//GPIO_SPEED_FREQ_LOW;//GPIO_SPEED_FREQ_MEDIUM;//
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
//Back light control -PB_0
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;//GPIO_SPEED_FREQ_MEDIUM;//GPIO_SPEED_FREQ_VERY_HIGH;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
PB_0是自制版中LCD背光PWM产生器,如果不用PWM方式,设置1或0即可(取决LCD背光驱动方式)
PA_15是本板的LCDRESET引脚(也可以用芯片NRST)
因为是按照smt32f103vet6改的,所以地址还是原来的:
0x60000000 -> 0x0001FFFE
经过多次修改最后总算驱显成功。
3.体验总结
采用stm32CubeMX生成对应apm32f4xx工程,经过修改可以应用在apm芯片上,说明芯片兼容性比较高,只是在时钟设置上出现问题,目前是168MHz,再高没有试,不知能否成功;项目特意测试了systick——这个非常有用,结果无恙,只是usart1代码并不能使用printf函数,有点遗憾,因为如此,源stm工程中lcddev.id就不能传输,只好定义一个4位数组lcdID[],来存放lcdID在TFTLCD中显示是没有问题的。
因为时钟不好设置,所以没有将sysClock提高,以后有机会再试。目前感觉仅比stm32f103快点,没有GD32F207速度快。刷频还是很明显的。
实际上本人也经常用简单容易使用的工具来测试调通新入手的MCU,比如MBED、以前成功的案例修改等,可以做到事半功倍。此实例又一次证明可行性。
方法总比困难多,多想才能出新招。
下边是芯片板照和视频。小屏幕的CNT:是由SysTick中断产生的计数值,一秒++1000个数。视频好像短了只有10秒
视频比较慢,修小点再传后加进来。
|