cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 qspi: reading registers

Posted on March 14, 2018 at 13:28

Hello there,

I am using STM32L4 series MCU and I am trying to interface with a M25Q Micron memory using QSPI. Following the examples given from ST I have noticed that there are no HAL functions allowing registers reading, that is:

  • READ STATUS REGISTER (05h),
  • READ FLAG STATUS REGISTER (70h),
  • READ NONVOLATILE CONFIGURATION REGISTER (B5h).

and etc.

In the examples the &sharpdefines for those commands are defined, but never used. Looking into the stm32l4xx_hal_qspi.h/c files, there is no read register command. All I could find is AutoPolling, which I am not sure either it works.

Does those functionalities need to be implemented by myself? I would appreciate all help.

#quad-spi #qspi-flash
43 REPLIES 43

Pretty sure you can't write to it in mapped mode.

I think in the loaders it reinitializes it when switching operational modes.

Afraid I can't commit resources to chasing this down currently.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
John3
Associate II

Hi @Community member​ 

Thanks for the reply.

Yes I know, memory mapped mode only works for reading. The driver has to switch back to indirect mode in order to do any write operation.

Could you please help me, how to switch to Indirect mode for write operation.

As i see in example code, we are setting reg "MEMRMP". I couldn't able to find details of this reg.

SET_BIT(SYSCFG->MEMRMP, 0x00000008);

Do i need to reconfigure this register to change it back to indirect mode for write operation?

I have added my code here :

uint8_t BSP_QSPI_Init(void)
{
  QSPIHandle.Instance = QUADSPI;
 
  /* QSPI initialization */
  QSPIHandle.Init.ClockPrescaler     = 1; /* QSPI clock = 80MHz / (ClockPrescaler+1) = 40MHz */
  QSPIHandle.Init.FifoThreshold      = 4;
  QSPIHandle.Init.SampleShifting     = QSPI_SAMPLE_SHIFTING_HALFCYCLE;
  QSPIHandle.Init.FlashSize          = POSITION_VAL(MT25Q128A_FLASH_SIZE) - 1;
  QSPIHandle.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_1_CYCLE;
  QSPIHandle.Init.ClockMode          = QSPI_CLOCK_MODE_0;
  
  if (HAL_QSPI_Init(&QSPIHandle) != HAL_OK)
  {
    return QSPI_ERROR;
  }
 
  /* QSPI memory reset */
  if (QSPI_ResetMemory(&QSPIHandle) != QSPI_OK)
  {
    return QSPI_NOT_SUPPORTED;
  }
 
  /* Configuration of the dummy cycles on QSPI memory side */
  if (QSPI_DummyCyclesCfg(&QSPIHandle) != QSPI_OK)
  {
    return QSPI_NOT_SUPPORTED;
  } 
  readID = QSPI_TestReadId(&QSPIHandle); 
  
  return QSPI_OK;
}
 
uint8_t BSP_QSPI_MemoryMapped_Read(uint8_t *pData, uint32_t ReadAddr, uint32_t Size)
{
  QSPI_CommandTypeDef sCommand;
  QSPI_MemoryMappedTypeDef sMemMappedCfg;
  __IO uint8_t *qspi_addr = (__IO uint8_t *)(0x90000000);
 
  /* Initialize the read command */
  sCommand.InstructionMode   = QSPI_INSTRUCTION_1_LINE;
  sCommand.Instruction       = FAST_READ_CMD;
  sCommand.AddressMode       = QSPI_ADDRESS_1_LINE;
  sCommand.AddressSize       = QSPI_ADDRESS_24_BITS;
  //sCommand.Address           = ReadAddr;
  sCommand.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
  sCommand.DataMode          = QSPI_DATA_1_LINE;
  sCommand.DummyCycles       = 8;
  sCommand.NbData            = Size;
  sCommand.DdrMode           = QSPI_DDR_MODE_DISABLE;
  sCommand.DdrHoldHalfCycle  = QSPI_DDR_HHC_ANALOG_DELAY;
  sCommand.SIOOMode          = QSPI_SIOO_INST_EVERY_CMD;
  
  sMemMappedCfg.TimeOutActivation = QSPI_TIMEOUT_COUNTER_DISABLE;
  
  if (HAL_QSPI_MemoryMapped(&QSPIHandle, &sCommand, &sMemMappedCfg) != HAL_OK)
  {
      return QSPI_ERROR;
  }
 
  (void)memcpy(pData,(void *)(qspi_addr + ReadAddr),Size);
  
  return QSPI_OK;
}

Thanks,

John

John3
Associate II

Hi ,

 I am able to fix the issue by calling QSPI Abort API. Now able to read the data in memory mapped mode.

Hi, good to hear that. Share your results in case you'll manage to do mapped mode + xip.