Using STM32U599 Hex SPI connect with PSRAM(256MBits, 32 MBytes), configure Hex SPI as QSPI, command/address is 4 Lines and 32 Bits. Only use IO0/1/2/3 and CS/CLK and IO15(used to make PSRAM enter OSPI or QSPI mode)
Now, we could read/write PSRAM Mode Register, but could not read any data from PSRAM.
Neither indirect or memory - map mode, could not read data from PSRAM. (Enable DQS when write to PSRAM in SDR mode, but still not work.)
void PSRAM_Init_QSPI()
{
XSPI_RegularCmdTypeDef cmd={0};
uint8_t str[] ="*** Hello World ***";
cmd.OperationType = HAL_XSPI_OPTYPE_COMMON_CFG;
cmd.IOSelect =HAL_XSPI_SELECT_IO_3_0;
cmd.DummyCycles = 0;
cmd.DQSMode = HAL_XSPI_DQS_ENABLE;
cmd.Instruction = 0x38;
cmd.InstructionMode =HAL_XSPI_INSTRUCTION_4_LINES; //HAL_XSPI_INSTRUCTION_4_LINES;
cmd.InstructionWidth=HAL_XSPI_INSTRUCTION_8_LINES;
cmd.InstructionDTRMode = HAL_XSPI_INSTRUCTION_DTR_DISABLE;
cmd.AddressMode = HAL_XSPI_ADDRESS_4_LINES;
cmd.AddressWidth = HAL_XSPI_ADDRESS_32_BITS;
cmd.AddressDTRMode = HAL_XSPI_ADDRESS_DTR_DISABLE;
cmd.Address = 0x0;
cmd.DataMode = HAL_XSPI_DATA_4_LINES;
cmd.DataLength = sizeof(str);
cmd.DataDTRMode = HAL_XSPI_DATA_DTR_DISABLE;
cmd.AlternateBytesMode = HAL_XSPI_ALT_BYTES_NONE;
if(HAL_XSPI_Command(&hxspi1,&cmd,1000)!=HAL_OK)
{
printf("[Error]:PSRAM_Init_QSPI, HAL_XSPI_Command\n");
}
if(HAL_XSPI_Transmit(&hxspi1,str,1000)!=HAL_OK)
{
printf("[Error]:PSRAM_Init_QSPI,HAL_XSPI_Transmit\n");
}
//Set read configuration
cmd.OperationType = HAL_XSPI_OPTYPE_READ_CFG;
cmd.IOSelect=HAL_XSPI_SELECT_IO_3_0;
cmd.DummyCycles = 4;
cmd.DQSMode = HAL_XSPI_DQS_DISABLE;
cmd.SIOOMode = HAL_XSPI_SIOO_INST_EVERY_CMD;
cmd.InstructionMode = HAL_XSPI_INSTRUCTION_4_LINES;
cmd.InstructionWidth = HAL_XSPI_INSTRUCTION_8_BITS;
cmd.InstructionDTRMode = HAL_XSPI_INSTRUCTION_DTR_DISABLE;
cmd.Instruction = 0x0B; //low speed : 0x0B
cmd.AddressMode = HAL_XSPI_ADDRESS_4_LINES;
cmd.AddressWidth = HAL_XSPI_ADDRESS_32_BITS;
cmd.AddressDTRMode = HAL_XSPI_ADDRESS_DTR_DISABLE;
cmd.Address = 0x0; //===================
cmd.DataLength = 1;
cmd.DataMode = HAL_XSPI_DATA_4_LINES;
cmd.DataDTRMode = HAL_XSPI_DATA_DTR_DISABLE;
cmd.AlternateBytesMode = HAL_XSPI_ALT_BYTES_NONE;
if(HAL_XSPI_Command(&hxspi1,&cmd,2000)!=HAL_OK)
{
printf("[Error]:PSRAM_Init_QSPI,HAL_XSPI_Comm--HAL_XSPI_OPTYPE_READ_CFG\n");
}
//Set Write configuration
cmd.OperationType = HAL_XSPI_OPTYPE_WRITE_CFG;
cmd.IOSelect=HAL_XSPI_SELECT_IO_3_0;
cmd.DummyCycles = 0;
cmd.DQSMode = HAL_XSPI_DQS_ENABLE; //================Important
cmd.SIOOMode = HAL_XSPI_SIOO_INST_EVERY_CMD;
cmd.InstructionMode = HAL_XSPI_INSTRUCTION_4_LINES;
cmd.InstructionWidth = HAL_XSPI_INSTRUCTION_8_BITS;
cmd.InstructionDTRMode = HAL_XSPI_INSTRUCTION_DTR_DISABLE;
cmd.Instruction = 0x38;
cmd.AddressMode = HAL_XSPI_ADDRESS_4_LINES;
cmd.AddressWidth = HAL_XSPI_ADDRESS_32_BITS;
cmd.AddressDTRMode = HAL_XSPI_ADDRESS_DTR_DISABLE;
cmd.Address = 0x0;
cmd.DataLength = 1;
cmd.DataMode = HAL_XSPI_DATA_4_LINES;
cmd.DataDTRMode = HAL_XSPI_DATA_DTR_DISABLE;
cmd.AlternateBytesMode = HAL_XSPI_ALT_BYTES_NONE;
if(HAL_XSPI_Command(&hxspi1,&cmd,2000)!=HAL_OK)
{
printf("[Error]:PSRAM_Init_QSPI,HAL_XSPI_CommHAL_XSPI_OPTYPE_WRITE_CFG\n");
}
//Map to memory
XSPI_MemoryMappedTypeDef cfg;
cfg.TimeOutActivation = HAL_XSPI_TIMEOUT_COUNTER_ENABLE;
cfg.TimeoutPeriodClock = 10;
if(HAL_XSPI_MemoryMapped(&hxspi1,&cfg)!=HAL_OK)
{
printf("[Error] HAL_XSPI_MemoryMapped\n");
}
uint8_t *psram = (uint8_t *)HSPI1_BASE;
__IO uint8_t *mem_addr;
mem_addr = (__IO uint8_t *)HSPI1_BASE;
printf("Read PSRAM: %s\n",mem_addr); //Print out Hello Dosilicon
printf("Read PSRAM: %s\n",psram); //Print out Hello Dosilicon
//mem_addr = (uint8_t *)"abc";//Hard FAULT!!
//psram = (uint8_t *)"abc";
//mem_addr = (uint8_t *)"*** Hello Maodun ***";
printf("PSRAM test %s\n",mem_addr);
printf("PSRAM test %s\n",psram);
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV1;
RCC_OscInitStruct.PLL.PLLM = 1;
RCC_OscInitStruct.PLL.PLLN = 10;
RCC_OscInitStruct.PLL.PLLP = 2;
RCC_OscInitStruct.PLL.PLLQ = 4;
RCC_OscInitStruct.PLL.PLLR = 1;
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_1;
RCC_OscInitStruct.PLL.PLLFRACN = 0;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|RCC_CLOCKTYPE_PCLK3;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
{
Error_Handler();
}
/** MCO configuration
*/
//HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_SYSCLK, RCC_MCODIV_1);
}
void HAL_XSPI_MspInit(XSPI_HandleTypeDef* hxspi)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(hxspi->Instance==HSPI1)
{
/* USER CODE BEGIN HSPI1_MspInit 0 */
/* USER CODE END HSPI1_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_HSPI;
PeriphClkInit.HspiClockSelection = RCC_HSPICLKSOURCE_PLL1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/* Peripheral clock enable */
__HAL_RCC_HSPI1_CLK_ENABLE();
__HAL_RCC_GPIOJ_CLK_ENABLE();
__HAL_RCC_GPIOI_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
/**HSPI1 GPIO Configuration
PJ0 ------> HSPI1_IO15
PI3 ------> HSPI1_CLK
PH10 ------> HSPI1_IO0
PH11 ------> HSPI1_IO1
PH13 ------> HSPI1_IO3
PH9 ------> HSPI1_NCS
PH12 ------> HSPI1_IO2
*/
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;//GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF8_HSPI1;
HAL_GPIO_Init(GPIOJ, &GPIO_InitStruct);
HAL_GPIO_WritePin(GPIOJ,GPIO_PIN_0,GPIO_PIN_SET);
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF8_HSPI1;
HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_13|GPIO_PIN_9
|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF8_HSPI1;
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
/* USER CODE BEGIN HSPI1_MspInit 1 */
/* USER CODE END HSPI1_MspInit 1 */
}
}
No any clue now, need help urgent, thank you in advance.