cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4P5G-DK OSPI speed gets too slow at ClockPrescaler = 0;

JKim.2
Senior

Hello,

 

I set 120MHz to OCTOSPI for Octo-SPI PSRAM. With the ClockPrescaler 0x02, the PSRAM test takes several seconds. However, with the ClockPrescaler 0x00, it takes over 3 minutes. Does it mean any problem on the clock configuration of STM32CubeIDE? The .ioc file is attached.

 

Thanks.

uint8_t BSP_PSRAM_Init(void)
{
OSPIM_CfgTypeDef OSPIM_Cfg_Struct;
OSPI_RegularCmdTypeDef sCommand = {0};
uint8_t reg[2];

if (bsp_psram_initialized == 0)
{

PSRAM_MspInit();

OSPIM_Cfg_Struct.ClkPort = 1;
OSPIM_Cfg_Struct.DQSPort = 1;
OSPIM_Cfg_Struct.IOHighPort = HAL_OSPIM_IOPORT_1_HIGH;
OSPIM_Cfg_Struct.IOLowPort = HAL_OSPIM_IOPORT_1_LOW;
OSPIM_Cfg_Struct.NCSPort = 1;

OSPIM_Cfg_Struct.Req2AckTime = 1;

OSPIPSRAMHandle.Instance = OCTOSPI1;
HAL_OSPI_DeInit(&OSPIPSRAMHandle);

OSPIPSRAMHandle.Init.FifoThreshold = 2;
OSPIPSRAMHandle.Init.DualQuad = HAL_OSPI_DUALQUAD_DISABLE;
OSPIPSRAMHandle.Init.MemoryType = HAL_OSPI_MEMTYPE_APMEMORY;
OSPIPSRAMHandle.Init.DeviceSize = 23; /* 64 MBits */
OSPIPSRAMHandle.Init.ChipSelectHighTime = 1;
OSPIPSRAMHandle.Init.FreeRunningClock = HAL_OSPI_FREERUNCLK_DISABLE;
OSPIPSRAMHandle.Init.ClockMode = HAL_OSPI_CLOCK_MODE_0;
OSPIPSRAMHandle.Init.ClockPrescaler = 0x02;
OSPIPSRAMHandle.Init.SampleShifting = HAL_OSPI_SAMPLE_SHIFTING_NONE;
OSPIPSRAMHandle.Init.DelayHoldQuarterCycle = HAL_OSPI_DHQC_ENABLE;
OSPIPSRAMHandle.Init.ChipSelectBoundary = 4;
OSPIPSRAMHandle.Init.DelayBlockBypass = HAL_OSPI_DELAY_BLOCK_USED;
OSPIPSRAMHandle.Init.MaxTran = 0;

if (HAL_OSPIM_Config(&OSPIPSRAMHandle, &OSPIM_Cfg_Struct, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return PSRAM_ERROR;
}

if (HAL_OSPI_Init(&OSPIPSRAMHandle) != HAL_OK) {
return PSRAM_ERROR;
}

sCommand.OperationType = HAL_OSPI_OPTYPE_COMMON_CFG;
sCommand.FlashId = HAL_OSPI_FLASH_ID_1;
sCommand.InstructionMode = HAL_OSPI_INSTRUCTION_8_LINES;
sCommand.InstructionSize = HAL_OSPI_INSTRUCTION_8_BITS;
sCommand.InstructionDtrMode = HAL_OSPI_INSTRUCTION_DTR_DISABLE;
sCommand.AddressMode = HAL_OSPI_ADDRESS_8_LINES;
sCommand.AddressSize = HAL_OSPI_ADDRESS_32_BITS;
sCommand.AddressDtrMode = HAL_OSPI_ADDRESS_DTR_ENABLE;
sCommand.AlternateBytesMode = HAL_OSPI_ALTERNATE_BYTES_NONE;
sCommand.DataMode = HAL_OSPI_DATA_8_LINES;
sCommand.DataDtrMode = HAL_OSPI_DATA_DTR_ENABLE;
sCommand.DQSMode = HAL_OSPI_DQS_ENABLE;
sCommand.SIOOMode = HAL_OSPI_SIOO_INST_EVERY_CMD;
sCommand.Instruction = READ_REG_CMD_SRAM;
sCommand.Address = 0;
sCommand.NbData = 2;
sCommand.DummyCycles = 5;

if (HAL_OSPI_Command(&OSPIPSRAMHandle, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
return PSRAM_ERROR;
}

if (HAL_OSPI_Receive(&OSPIPSRAMHandle, reg, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
return PSRAM_ERROR;
}

sCommand.Instruction = WRITE_REG_CMD_SRAM;
sCommand.DummyCycles = 0;
MODIFY_REG(reg[0], 0x03, 0x00);

if (HAL_OSPI_Command(&OSPIPSRAMHandle, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
return PSRAM_ERROR;
}

if (HAL_OSPI_Transmit(&OSPIPSRAMHandle, reg, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
return PSRAM_ERROR;
}

bsp_psram_initialized = 1;
}

return PSRAM_OK;
}

0 REPLIES 0