2025-06-04 2:43 AM
Hello dear community,
I’m a beginner with STM32 and I’m trying to interface an APS6404L PSRAM to my STM32H7S3L8H6H using the XSPI1 peripheral. Despite configuring XSPI in CubeMX and generating the initialization code, I see no activity on any of the XSPI1 pins (CS, CLK, D0, D1, etc.) when I attempt a simple “Read ID” command. However, if I reconfigure those same pins as GPIO outputs and toggle them manually, they toggle just fine, so I know the pins themselves are physically working.
I suspect that something is missing or mis‐configured in the MX_XSPI1_Init() code, but I’m not sure what to look for next. Below is my XSPI1 initialization and the test routine I’m using:
XSPI1 Initialization (generated by CubeMX)
static void MX_XSPI1_Init(void)
{
XSPIM_CfgTypeDef sXspiManagerCfg = {0};
hxspi1.Instance = XSPI1;
hxspi1.Init.FifoThresholdByte = 1;
hxspi1.Init.MemoryMode = HAL_XSPI_SINGLE_MEM;
hxspi1.Init.MemoryType = HAL_XSPI_MEMTYPE_APMEM;
hxspi1.Init.MemorySize = HAL_XSPI_SIZE_64MB;
hxspi1.Init.ChipSelectHighTimeCycle = 1;
hxspi1.Init.FreeRunningClock = HAL_XSPI_FREERUNCLK_DISABLE;
hxspi1.Init.ClockMode = HAL_XSPI_CLOCK_MODE_0;
hxspi1.Init.WrapSize = HAL_XSPI_WRAP_NOT_SUPPORTED;
hxspi1.Init.ClockPrescaler = 3;
hxspi1.Init.SampleShifting = HAL_XSPI_SAMPLE_SHIFT_NONE;
hxspi1.Init.DelayHoldQuarterCycle = HAL_XSPI_DHQC_DISABLE;
hxspi1.Init.ChipSelectBoundary = HAL_XSPI_BONDARYOF_NONE;
hxspi1.Init.MaxTran = 0;
hxspi1.Init.Refresh = 0;
hxspi1.Init.MemorySelect = HAL_XSPI_CSSEL_NCS1;
if (HAL_XSPI_Init(&hxspi1) != HAL_OK)
{
Error_Handler();
}
sXspiManagerCfg.nCSOverride = HAL_XSPI_CSSEL_OVR_NCS1;
sXspiManagerCfg.IOPort = HAL_XSPIM_IOPORT_1;
if (HAL_XSPIM_Config(&hxspi1, &sXspiManagerCfg, HAL_XSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
Error_Handler();
}
}
Test Routines
HAL_StatusTypeDef PSRAM_Reset(void) {
XSPI_RegularCmdTypeDef sCommand;
HAL_StatusTypeDef status;
memset(&sCommand, 0, sizeof(sCommand));
sCommand.OperationType = HAL_XSPI_OPTYPE_COMMON_CFG;
sCommand.InstructionMode = HAL_XSPI_INSTRUCTION_1_LINE;
sCommand.Instruction = 0x66;
sCommand.AddressMode = HAL_XSPI_ADDRESS_NONE;
sCommand.DataMode = HAL_XSPI_DATA_NONE;
sCommand.DummyCycles = 0;
status = HAL_XSPI_Command(&hxspi1, &sCommand, HAL_TIMEOUT);
if (status != HAL_OK) {
return status;
}
sCommand.Instruction = 0x99;
status = HAL_XSPI_Command(&hxspi1, &sCommand, HAL_TIMEOUT);
return status;
}
HAL_StatusTypeDef PSRAM_ReadID(uint8_t *pID) {
XSPI_RegularCmdTypeDef sCommand;
HAL_StatusTypeDef status;
memset(&sCommand, 0, sizeof(sCommand));
sCommand.OperationType = HAL_XSPI_OPTYPE_COMMON_CFG;
sCommand.InstructionMode = HAL_XSPI_INSTRUCTION_1_LINE;
sCommand.Instruction = 0x9F;
sCommand.AddressMode = HAL_XSPI_ADDRESS_NONE;
sCommand.AlternateBytesMode = HAL_XSPI_ALT_BYTES_NONE;
sCommand.DataMode = HAL_XSPI_DATA_1_LINE;
sCommand.DataLength = 3;
sCommand.DummyCycles = 0;
status = HAL_XSPI_Command(&hxspi1, &sCommand, HAL_TIMEOUT);
if (status != HAL_OK) {
return status;
}
return HAL_XSPI_Receive(&hxspi1, pID, HAL_TIMEOUT);
}
// In main():
HAL_Delay(1);
PSRAM_Reset();
HAL_Delay(1);
uint8_t id[3];
char msg[50];
if (PSRAM_ReadID(id) == HAL_OK) {
snprintf(msg, sizeof(msg), "ID: %02X %02X %02X\r\n", id[0], id[1],
id[2]);
HAL_UART_Transmit(&huart4, (uint8_t*) msg, strlen(msg), HAL_MAX_DELAY);
} else {
HAL_UART_Transmit(&huart4, (uint8_t*) "Read ID failed\r\n", 16,
HAL_MAX_DELAY);
}
Thank you very much in advance for any suggestions or advice.
I'm still learning, so please excuse any naive mistakes. I'd greatly appreciate any guidance on which registry bits to check or what CubeMX settings might be wrong.
2025-06-04 3:51 AM
Hello @andgarriv and welcome to the community;
To start with XSPI interface, I recommend you to look at these resources:
Could you please check the XSPI configuration:
Thank you.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-06-05 12:37 AM - edited 2025-06-05 12:40 AM
Hi Kaouthar,
Thank you for the pointers. I’ve already reviewed the XSPI documentation and examples, and I even connected an external flash device the same as the one on the STM32 Nucleo board. Everything seemed straightforward, but my issue is that I’m not seeing any activity on the CS line (it stays high) nor on the clock pin.
I’ve double-checked my pin assignments and clock setup, and I believe that the settings are as per the PSRAM datasheet. Still, CS never toggles and CLK remains idle. Could you suggest what might be causing CS to stay high? Are there any common pitfalls in the HAL initialization for XSPI that I should verify?
Thanks again for your help!
Best regards,
Andrés
2025-06-05 2:26 AM
Hello @andgarriv,
Please make sure that all GPIOs configured to very-high speed.
Which Refresh rate are you using?
Thank you.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-06-05 2:41 AM
Hi Kaouthar,
The GPIOs are already configured to Very High speed by default. As for the refresh rate, I have tried several values. Currently, the XSPI clock is running at 50 MHz with a prescaler of 1 (so the PSRAM sees 25 MHz), and I am using a refresh value of 200.
Thanks,
Andrés