How to use the PSRAM in 32L4R9IDISCOVERY for FrameBuffer?
How to use the PSRAM of 32L4R9IDISCOVERY as the LCD Framebuffer?
I have a evaluation board 32L4R9IDISCOVERY.
And use the Demo program as start: STM32Cube_FW_L4_V1.14.0\Projects\32L4R9IDISCOVERY\Examples\DSI\DSI_CmdMode_SingleBuffer.
and then, added the PSRAM init function in stm32l4r9i_discovery_psram.c.
The PSRAM worked well, and used as heap.
First I setted the FrameBUffer in ISRAM.
The code work well, and LCD display the LOGO.
After I setted the FrameBuffer to PSRAM.
//__attribute__((section(".FrameBufferSection")))
__attribute__((section(".XRAMSection")))
__align(16) uint32_t PhysFrameBuffer[91260]; // 5 char buffer, 5*16 = 80 pixer
The code jump to LTDC_ER_IRQHandler, after the function
if(HAL_LTDC_ConfigLayer(&LtdcHandle, &LayerCfg, LTDC_LAYER_1) != HAL_OK)
{
return(LCD_ERROR);
}
attch BSP init
static void k_BspInit(void)
{
/* Configure IO expanders */
BSP_IO_Init();
/* Configure LED1 and LED2 */
BSP_LED_Init(LED1);
BSP_LED_Init(LED2);
/* PSRAM device configuration */
if(BSP_PSRAM_Init() != PSRAM_OK)
{
while(1);
}
/* Initialize the NOR OctoSPI flash */
if (BSP_OSPI_NOR_Init() != OSPI_NOR_OK)
{
/* Initialization Error */
while(1);
}
else
{
if(BSP_OSPI_NOR_EnableMemoryMappedMode() != OSPI_NOR_OK)
{
/* Configuring Memory Mapped mode failed */
while(1);
}
}
/* Enable CRC to Unlock GUI */
// __HAL_RCC_CRC_CLK_ENABLE();
}
And the PSRAM init code:
/* PSRAM device configuration */
/* Timing configuration derived from system clock (up to 120Mhz)
for 60Mhz as PSRAM clock frequency */
Timing.AddressSetupTime = 4;
Timing.AddressHoldTime = 2;
Timing.DataSetupTime = 6;
Timing.BusTurnAroundDuration = 1;
Timing.CLKDivision = 2;
Timing.DataLatency = 2;
Timing.AccessMode = FMC_ACCESS_MODE_A; //FMC_ACCESS_MODE_A;
psramHandle.Init.NSBank = FMC_NORSRAM_BANK1;
psramHandle.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
psramHandle.Init.MemoryType = FMC_MEMORY_TYPE_PSRAM;
psramHandle.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16;
psramHandle.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
psramHandle.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_HIGH;
psramHandle.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
psramHandle.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;
psramHandle.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
psramHandle.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
psramHandle.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE;
psramHandle.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
psramHandle.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ASYNC;
psramHandle.Init.WriteFifo = FMC_WRITE_FIFO_DISABLE;
psramHandle.Init.NBLSetupTime = 0;
psramHandle.Init.PageSize = FMC_PAGE_SIZE_NONE;
psramHandle.Instance = FMC_NORSRAM_DEVICE;
psramHandle.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
And the Scatter file:
LR_IROM1 0x08000000 0x00200000 { ; load region size_region
ER_IROM1 0x08000000 0x00200000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
}
RW_IRAM1 0x20000000 0xA0000 { ; RW data
.ANY (+RW +ZI)
}
RW_SRAM1 0x20000000 0x30000 { ; RW data
.ANY (+RW +ZI)
}
RW_SRAM2 0x10000000 0x10000 { ; RW data
*(.FreeRTOSHeapSection)
.ANY(STACK)
}
RW_SRAM3 0x20040000 0x60000 { ; RW data
.ANY(PHYS_FB)
*(.FrameBufferSection)
}
RW_XRAM 0x60000000 0x400000 {
.ANY(HEAP)
*(.XRAMSection)
}
}
Thanks.
