Hello guys. before all, I appreciated your Hint and Help. I use STM32L4R9Z microcontroller to Drive a QuadSPI NAND-Flash(Winbond). I configured OctaSPI of microcontroller as QuadSPI, and tried to write on NAND-Flash at Auto Polling mode.
After the Write-Enable command has been executed, the "HAL_OSPI_AutoPolling()" function will be called but, at the line of :
status = OSPI_WaitFlagStateUntilTimeout(hospi, HAL_OSPI_FLAG_SM, SET, tickstart, Timeout);
time out event will be accrued and so, call the error handler routine.
Question is here, why time out? is there any miss configuration? and how can I solved it?
OctaSPI initisation for Quad NAND-Flash:MX_OCTOSPI1_Init()
static void MX_OCTOSPI1_Init(void)
{
/* USER CODE BEGIN OCTOSPI1_Init 0 */
/* USER CODE END OCTOSPI1_Init 0 */
OSPIM_CfgTypeDef OSPIM_Cfg_Struct = {0};
/* USER CODE BEGIN OCTOSPI1_Init 1 */
/* USER CODE END OCTOSPI1_Init 1 */
/* OCTOSPI1 parameter configuration*/
hospi1.Instance = OCTOSPI1;
hospi1.Init.FifoThreshold = 4;
hospi1.Init.DualQuad = HAL_OSPI_DUALQUAD_DISABLE;
hospi1.Init.MemoryType = HAL_OSPI_MEMTYPE_MICRON;
hospi1.Init.DeviceSize = 27;
hospi1.Init.ChipSelectHighTime = 1;
hospi1.Init.FreeRunningClock = HAL_OSPI_FREERUNCLK_DISABLE;
hospi1.Init.ClockMode = HAL_OSPI_CLOCK_MODE_0;
hospi1.Init.ClockPrescaler = 1;
hospi1.Init.SampleShifting = HAL_OSPI_SAMPLE_SHIFTING_NONE;
hospi1.Init.DelayHoldQuarterCycle = HAL_OSPI_DHQC_DISABLE;
hospi1.Init.ChipSelectBoundary = 0;
hospi1.Init.DelayBlockBypass = HAL_OSPI_DELAY_BLOCK_BYPASSED;
if (HAL_OSPI_Init(&hospi1) != HAL_OK)
{
Error_Handler();
}
OSPIM_Cfg_Struct.ClkPort = 2;
OSPIM_Cfg_Struct.NCSPort = 2;
OSPIM_Cfg_Struct.IOLowPort = HAL_OSPIM_IOPORT_2_LOW;
if (HAL_OSPIM_Config(&hospi1, &OSPIM_Cfg_Struct, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN OCTOSPI1_Init 2 */
/* USER CODE END OCTOSPI1_Init 2 */
Write Enable Function:
static uint8_t W25M_OCTOSPI_WriteEnable(OSPI_HandleTypeDef OCTOSPIHandle)
{
OSPI_RegularCmdTypeDef s_command;
OSPI_AutoPollingTypeDef s_config;
uint8_t pData[1] ;
/* Enable write operations */
s_command.OperationType = HAL_OSPI_OPTYPE_COMMON_CFG ;
s_command.InstructionMode = HAL_OSPI_INSTRUCTION_1_LINE;
s_command.Instruction = W25M_WRITE_ENABLE_CMD;
s_command.InstructionSize = HAL_OSPI_INSTRUCTION_8_BITS;
s_command.InstructionDtrMode = HAL_OSPI_INSTRUCTION_DTR_DISABLE; // Hosbital
s_command.AddressDtrMode = HAL_OSPI_ADDRESS_DTR_DISABLE; // Hosbital
s_command.AddressMode = HAL_OSPI_ADDRESS_NONE;
s_command.AlternateBytesMode = HAL_OSPI_ALTERNATE_BYTES_NONE;
s_command.AlternateBytesDtrMode = HAL_OSPI_ALTERNATE_BYTES_DTR_DISABLE; //Hosbital
s_command.DQSMode = HAL_OSPI_DQS_DISABLE; //Hosbital
s_command.DataMode = HAL_OSPI_DATA_NONE;
s_command.DummyCycles = 0;
s_command.DataDtrMode = HAL_OSPI_DATA_DTR_DISABLE;
s_command.SIOOMode = HAL_OSPI_SIOO_INST_EVERY_CMD;
if (HAL_OSPI_Command(&OCTOSPIHandle, &s_command, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return 0;
}
s_config.Match = WRITE_ENABLE_MATCH_VALUE;
s_config.Mask = WRITE_ENABLE_MASK_VALUE;
s_config.MatchMode = HAL_OSPI_MATCH_MODE_AND;
s_config.Interval = AUTO_POLLING_INTERVAL;
s_config.AutomaticStop = HAL_OSPI_AUTOMATIC_STOP_ENABLE;
s_command.OperationType = HAL_OSPI_OPTYPE_READ_CFG ;
s_command.InstructionMode = HAL_OSPI_INSTRUCTION_1_LINE;
s_command.Instruction = W25M_READ_STATUS_REG_CMD;
s_command.InstructionSize = HAL_OSPI_INSTRUCTION_8_BITS;
s_command.InstructionDtrMode = HAL_OSPI_INSTRUCTION_DTR_DISABLE; // Hosbital
s_command.AddressDtrMode = HAL_OSPI_ADDRESS_DTR_DISABLE; // Hosbital
s_command.AddressMode = HAL_OSPI_ADDRESS_1_LINE;
s_command.AddressSize = HAL_OSPI_ADDRESS_8_BITS;
s_command.Address = W25M_STATUS_REG3_ADR;
s_command.AlternateBytesMode = HAL_OSPI_ALTERNATE_BYTES_NONE;
s_command.AlternateBytesDtrMode = HAL_OSPI_ALTERNATE_BYTES_DTR_DISABLE; //Hosbital
s_command.DQSMode = HAL_OSPI_DQS_DISABLE; //Hosbital
s_command.DataMode = HAL_OSPI_DATA_1_LINE;
s_command.DummyCycles = 0;
s_command.NbData = 1;
s_command.DataDtrMode = HAL_OSPI_DATA_DTR_DISABLE;
s_command.SIOOMode = HAL_OSPI_SIOO_INST_EVERY_CMD;
if (HAL_OSPI_Command(&OCTOSPIHandle, &s_command, HAL_OSPI_TIMEOUT_DEFAULT_VALUE ) != HAL_OK)
{
return 0;
}
if (HAL_QSPI_AutoPolling(&hospi1,&s_command, &s_config, HAL_OSPI_TIMEOUT_DEFAULT_VALUE))
{
return 0;
}
return 1;
}