SDRAM 与 STM32F429BI 接口存在闪烁问题

Posted

技术标签:

【中文标题】SDRAM 与 STM32F429BI 接口存在闪烁问题【英文标题】:SDRAM interfacing with STM32F429BI having flickering issue 【发布时间】:2021-02-22 08:19:28 【问题描述】:

我正在使用 800x600 分辨率的 12.1" TFT 显示器并将其与 STM32F429BI 微控制器和 IS42S16400J SDRAM 连接。我的显示器出现闪烁问题。当我绕过 SDRAM 时,它工作正常,没有闪烁,但是在通过 SDRAM 连接时,它开始出现闪烁问题。

#define REFRESH_COUNT           ((uint32_t)(1386))   /* SDRAM refresh counter at 90Mhz*/
#define SDRAM_TIMEOUT         ((uint32_t)0xFFFF)
#define SDRAM_DEVICE_ADDR       ((unsigned int)0xD0000000)

void SystemClock_Config(void)

 RCC_OscInitTypeDef RCC_OscInitStruct;
 RCC_ClkInitTypeDef RCC_ClkInitStruct;
 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
 __PWR_CLK_ENABLE();
 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
 RCC_OscInitStruct.LSEState = RCC_LSE_ON;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
 RCC_OscInitStruct.PLL.PLLM =4;
 RCC_OscInitStruct.PLL.PLLN =180;
 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
 RCC_OscInitStruct.PLL.PLLQ = 4;
 HAL_RCC_OscConfig(&RCC_OscInitStruct);
 HAL_PWREx_ActivateOverDrive();
 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1
               |RCC_CLOCKTYPE_PCLK2;
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC|RCC_PERIPHCLK_RTC;
 PeriphClkInitStruct.PLLSAI.PLLSAIN =144;//18MHz
 PeriphClkInitStruct.PLLSAI.PLLSAIR = 4;
 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_4;
 PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
 HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);


 
void MX_LTDC_Init(void)

LTDC_LayerCfgTypeDef pLayerCfg;
 hltdc.Instance = LTDC;
 hltdc.Init.HSPolarity =LTDC_HSPOLARITY_AH;
 hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
 hltdc.Init.DEPolarity =LTDC_DEPOLARITY_AL; 
 hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
 hltdc.Init.HorizontalSync = 40;
 hltdc.Init.VerticalSync = 9;
 hltdc.Init.AccumulatedHBP = 42;
 hltdc.Init.AccumulatedVBP = 11;
 hltdc.Init.AccumulatedActiveW = 1054;
 hltdc.Init.AccumulatedActiveH = 664;
 hltdc.Init.TotalWidth = 1056;
 hltdc.Init.TotalHeigh = 666;
 hltdc.Init.Backcolor.Blue = 0;
 hltdc.Init.Backcolor.Green = 0;
 hltdc.Init.Backcolor.Red = 0;
 HAL_LTDC_Init(&hltdc);

 pLayerCfg.WindowX0 = 0;
 pLayerCfg.WindowX1 = 800;
 pLayerCfg.WindowY0 = 0;
 pLayerCfg.WindowY1 = 600;
 pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
 pLayerCfg.Alpha = 255;
 pLayerCfg.Alpha0 = 0;
 pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
 pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
 pLayerCfg.FBStartAdress = SDRAM_DEVICE_ADDR;//(uint32_t)&Color;
 pLayerCfg.ImageWidth = 800;
 pLayerCfg.ImageHeight = 600;
 pLayerCfg.Backcolor.Blue = 0;
 pLayerCfg.Backcolor.Green = 0;
 pLayerCfg.Backcolor.Red = 0;
 HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0);


void MX_FMC_Init(void)

 FMC_SDRAM_TimingTypeDef SdramTiming;
 hsdram1.Instance = FMC_SDRAM_DEVICE;
 hsdram1.Init.SDBank = FMC_SDRAM_BANK2;
 hsdram1.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
 hsdram1.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
 hsdram1.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16;
 hsdram1.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
 hsdram1.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3;
 hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
 hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2;
 hsdram1.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE;
 hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1;
 SdramTiming.LoadToActiveDelay  = 2;
 SdramTiming.ExitSelfRefreshDelay = 14;
 SdramTiming.SelfRefreshTime   = 14;
 SdramTiming.RowCycleDelay    = 14;
 SdramTiming.WriteRecoveryTime  = 2;
 SdramTiming.RPDelay       = 4;
 SdramTiming.RCDDelay       = 4;
 HAL_SDRAM_Init(&hsdram1, &SdramTiming);
 BSP_SDRAM_Initialization_sequence(REFRESH_COUNT);


void BSP_SDRAM_Initialization_sequence(uint32_t RefreshCount)

 __IO uint32_t tmpmrd =0;  
 Command.CommandMode       = FMC_SDRAM_CMD_CLK_ENABLE;
 Command.CommandTarget      = FMC_SDRAM_CMD_TARGET_BANK2;
 Command.AutoRefreshNumber    = 1;
 Command.ModeRegisterDefinition = 0;
 HAL_SDRAM_SendCommand(&hsdram1, &Command, SDRAM_TIMEOUT);
 HAL_Delay(1);
 Command.CommandMode       = FMC_SDRAM_CMD_PALL;
 Command.CommandTarget      = FMC_SDRAM_CMD_TARGET_BANK2;
 Command.AutoRefreshNumber    = 1;
 Command.ModeRegisterDefinition = 0;
 HAL_SDRAM_SendCommand(&hsdram1, &Command, SDRAM_TIMEOUT); 
 Command.CommandMode       = FMC_SDRAM_CMD_AUTOREFRESH_MODE;
 Command.CommandTarget      = FMC_SDRAM_CMD_TARGET_BANK2;
 Command.AutoRefreshNumber    = 4;
 Command.ModeRegisterDefinition = 0;
 HAL_SDRAM_SendCommand(&hsdram1, &Command, SDRAM_TIMEOUT);
 tmpmrd = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_1     |
          SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL  |
          SDRAM_MODEREG_CAS_LATENCY_3      |
          SDRAM_MODEREG_OPERATING_MODE_STANDARD |
           SDRAM_MODEREG_WRITEBURST_MODE_SINGLE;
 Command.CommandMode       = FMC_SDRAM_CMD_LOAD_MODE;
 Command.CommandTarget      = FMC_SDRAM_CMD_TARGET_BANK2;
 Command.AutoRefreshNumber    = 1;
 Command.ModeRegisterDefinition = tmpmrd;
 HAL_SDRAM_SendCommand(&hsdram1, &Command, SDRAM_TIMEOUT);
 HAL_SDRAM_ProgramRefreshRate(&hsdram1, RefreshCount); 

【问题讨论】:

【参考方案1】:

这可能是 EMI 问题。 SRAM 会产生大量 EMI,PCB 设计并非易事。

是开发者吗? STM 板还是定制板?

【讨论】:

它是定制板?【参考方案2】:

显示图像(或一系列图像)时

    在“回溯”期间屏幕必须是空白的。 屏幕的任何更新都必须在retrace 时间内进行。

你已经看到了不遵循以上两个目标的结果。

人眼可能会被愚弄,但是当图像在更新的同时更新图像时,结果是人眼会捕捉到的“闪烁”

【讨论】:

以上是关于SDRAM 与 STM32F429BI 接口存在闪烁问题的主要内容,如果未能解决你的问题,请参考以下文章

一个基于STM32F429 HAL库的学习工程模板

STM32F429第3章 ThreadX USBX协议栈移植到STM32F429

关于stm32f429的MDA2D的M2M模式

关于stm32f429的MDA2D的M2M模式

STM32F429第二十八篇之ADC

STM32F429第二十八篇之ADC