Skip to main content
hp26
Associate II
April 18, 2023
Solved

OctoSpi in QuadSpi mode

  • April 18, 2023
  • 2 replies
  • 1782 views

Hello,

I am trying to access an external flash memory (32 mbit) using stm32L4. Stm32L4 has OctoSpi. i have configured the OctoSpi with dual quad disabled but yet, i am not able to access the external flash mem. The external flash memory supports single, dual and quad spi modes. I tried to set the octo spi to use just 1 line inorder to read the manufacturer id from the flash memory chip but it always returns 0.Is there any example/stater guide available for OctoSpi on stm32L4xx.

​Thanks!

This topic has been closed for replies.
Best answer by Tesla DeLorean

I have it working on a H7Ax part

//****************************************************************************
 
static uint8_t OSPI_ReadID(OSPI_HandleTypeDef *hospi, uint32_t *pID)
{
 OSPI_RegularCmdTypeDef sCommand = {0};
 uint32_t data[1];
 
 sCommand.OperationType = HAL_OSPI_OPTYPE_COMMON_CFG;
 sCommand.FlashId = HAL_OSPI_FLASH_ID_1;
 
 sCommand.Instruction = 0x9F;
 
 sCommand.InstructionMode = HAL_OSPI_INSTRUCTION_1_LINE;
 sCommand.InstructionSize = HAL_OSPI_INSTRUCTION_8_BITS;
 sCommand.InstructionDtrMode = HAL_OSPI_INSTRUCTION_DTR_DISABLE;
 sCommand.AddressMode = HAL_OSPI_ADDRESS_NONE;
 sCommand.AlternateBytesMode = HAL_OSPI_ALTERNATE_BYTES_NONE;
 sCommand.DataMode = HAL_OSPI_DATA_1_LINE;
 sCommand.DataDtrMode = HAL_OSPI_DATA_DTR_DISABLE;
 sCommand.DummyCycles = 0;
 sCommand.NbData = sizeof(data);
 sCommand.DQSMode = HAL_OSPI_DQS_DISABLE;
 sCommand.SIOOMode = HAL_OSPI_SIOO_INST_EVERY_CMD;
 
 if (HAL_OSPI_Command(hospi, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
 {
 return(OSPI_ERROR);
 }
 
 if (HAL_OSPI_Receive(hospi, (void *)data, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
 {
 return(OSPI_ERROR);
 }
 
 if (pID)
 *pID = data[0];
 
 return(OSPI_OK);
}
 
//****************************************************************************

2 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
April 18, 2023

I have it working on a H7Ax part

//****************************************************************************
 
static uint8_t OSPI_ReadID(OSPI_HandleTypeDef *hospi, uint32_t *pID)
{
 OSPI_RegularCmdTypeDef sCommand = {0};
 uint32_t data[1];
 
 sCommand.OperationType = HAL_OSPI_OPTYPE_COMMON_CFG;
 sCommand.FlashId = HAL_OSPI_FLASH_ID_1;
 
 sCommand.Instruction = 0x9F;
 
 sCommand.InstructionMode = HAL_OSPI_INSTRUCTION_1_LINE;
 sCommand.InstructionSize = HAL_OSPI_INSTRUCTION_8_BITS;
 sCommand.InstructionDtrMode = HAL_OSPI_INSTRUCTION_DTR_DISABLE;
 sCommand.AddressMode = HAL_OSPI_ADDRESS_NONE;
 sCommand.AlternateBytesMode = HAL_OSPI_ALTERNATE_BYTES_NONE;
 sCommand.DataMode = HAL_OSPI_DATA_1_LINE;
 sCommand.DataDtrMode = HAL_OSPI_DATA_DTR_DISABLE;
 sCommand.DummyCycles = 0;
 sCommand.NbData = sizeof(data);
 sCommand.DQSMode = HAL_OSPI_DQS_DISABLE;
 sCommand.SIOOMode = HAL_OSPI_SIOO_INST_EVERY_CMD;
 
 if (HAL_OSPI_Command(hospi, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
 {
 return(OSPI_ERROR);
 }
 
 if (HAL_OSPI_Receive(hospi, (void *)data, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
 {
 return(OSPI_ERROR);
 }
 
 if (pID)
 *pID = data[0];
 
 return(OSPI_OK);
}
 
//****************************************************************************

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
hp26
hp26Author
Associate II
April 21, 2023

Thank you for the response.