cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot read ID from external flash (OSPI1) on STM32H735-DK

NRedd.2
Associate II

Hello all,

 

I was trying to follow the example in MOOC - STM32H72x/3x hands-on workshop - 6 Code execution from external FLASH

I have configured the OSPI as per the board requirements in CubeMX. But the `OSPI_Init()` function fails while trying to read the device ID.

 

When I comment out the code, I am able to jump to an external application that is loaded by the CubeProgrammer.

I am not sure what is going wrong here. Can somebody help?

I have attached the project as a 7Z file.

 

 

 

OSPI_Init();
OSPI_MemoryMap();

printf("Device will jump to: %X\r\n", IMAGE_DEFAULT_ADD);

if ((((*(__IO uint32_t *) IMAGE_DEFAULT_ADD) & 0x2FFC0000) >= 0x20000000) && (((*(__IO uint32_t *) IMAGE_DEFAULT_ADD) & 0x2FFC0000) <=  0x2FFC0000))
	  {
	    /* Jump to user application */
            JumpAddress = *(__IO uint32_t *) (IMAGE_DEFAULT_ADD + 4);/*address +4 is an reset vector*/
	    JumpToApplication = (pFunction) JumpAddress;

	    /* Initialize user application's Stack Pointer */
	    __set_MSP(*(__IO uint32_t *) IMAGE_DEFAULT_ADD);
	    JumpToApplication();
}

 

 

 

The main looks similar to the one in the MOOC video.

 

I believe that the GPIO configuration is correct because I am able to jump to the external application located at OSP1_BASE.

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Ok, so what's the error reported?

uint32_t OSPI_Init()
{
  uint8_t id[20];

  OSPI_RegularCmdTypeDef  sCommand;

  hospi1.Instance = OCTOSPI1;
  HAL_OSPI_DeInit(&hospi1);

  hospi1.Init.FifoThreshold         = 32;
  hospi1.Init.DualQuad              = HAL_OSPI_DUALQUAD_DISABLE;
  hospi1.Init.MemoryType            = HAL_OSPI_MEMTYPE_MACRONIX;
  hospi1.Init.DeviceSize            = 26;
  hospi1.Init.ChipSelectHighTime    = 2;
  hospi1.Init.FreeRunningClock      = HAL_OSPI_FREERUNCLK_DISABLE;
  hospi1.Init.ClockMode             = HAL_OSPI_CLOCK_MODE_0;
  hospi1.Init.WrapSize              = HAL_OSPI_WRAP_NOT_SUPPORTED;
  hospi1.Init.ClockPrescaler        = 0x3;
  hospi1.Init.SampleShifting        = HAL_OSPI_SAMPLE_SHIFTING_NONE;
  hospi1.Init.DelayHoldQuarterCycle = HAL_OSPI_DHQC_ENABLE;
  hospi1.Init.ChipSelectBoundary    = 0;

  if (HAL_OSPI_Init(&hospi1) != HAL_OK)
  {
    Error_Handler();
  }

  OSPI_ResetMemory();/*reset OSPI memory*/

  /* read ospi memory ID */
  sCommand.OperationType         = HAL_OSPI_OPTYPE_COMMON_CFG;
  sCommand.FlashId               = HAL_OSPI_FLASH_ID_1;
  sCommand.InstructionMode       = HAL_OSPI_INSTRUCTION_1_LINE;
  sCommand.InstructionSize       = HAL_OSPI_INSTRUCTION_8_BITS;
  sCommand.InstructionDtrMode    = HAL_OSPI_INSTRUCTION_DTR_DISABLE;
  sCommand.AddressDtrMode        = HAL_OSPI_ADDRESS_DTR_DISABLE;
  sCommand.AlternateBytes        = 0x00;
  sCommand.AlternateBytesMode    = HAL_OSPI_ALTERNATE_BYTES_NONE;
  sCommand.AlternateBytesSize    = HAL_OSPI_ALTERNATE_BYTES_8_BITS;
  sCommand.AlternateBytesDtrMode = HAL_OSPI_ALTERNATE_BYTES_DTR_DISABLE;
  sCommand.DataDtrMode           = HAL_OSPI_DATA_DTR_DISABLE;
  sCommand.DummyCycles           = 0;
  sCommand.DQSMode               = HAL_OSPI_DQS_DISABLE;
  sCommand.SIOOMode              = HAL_OSPI_SIOO_INST_EVERY_CMD;

  sCommand.Instruction           = READ_ID_CMD;
  sCommand.AddressMode           = HAL_OSPI_ADDRESS_NONE;
  sCommand.NbData                = 20;
  sCommand.DataMode              = OSPIDataMode;
  /*send cmd to read ID*/
  if (HAL_OSPI_Command(&hospi1, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
  {
    Error_Handler();
  }
  /*receive the ID*/
//  if (HAL_OSPI_Receive(&hospi1, id, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
//  {
//    Error_Handler();
//  }

  OSPI_OctalStrModeCfg(&hospi1);/*set OSPI mode to 8bit DTR*/

  return 0;
}

Make sure the data mode is correct

...
  sCommand.NbData                = 3; // Only reports 3
  sCommand.DataMode              = HAL_OSPI_DATA_1_LINE; // Use SPI mode

  /*send cmd to read ID*/
  if (HAL_OSPI_Command(&hospi1, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
  {
    Error_Handler();
  }
  /*receive the ID*/
  if (HAL_OSPI_Receive(&hospi1, id, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
  {
    Error_Handler();
  }

 

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

View solution in original post

4 REPLIES 4

You can't send commands in Memory Mapped mode, so either don't do that, or send a HAL_OSPI_Abort() to stop it.

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

@Tesla DeLorean 

The command to read ID is sent before the memory mapping is enabled. It is called within the OSPI_Init(); function. 

The command is sent in SPI non-DTR mode.

Ok, so what's the error reported?

uint32_t OSPI_Init()
{
  uint8_t id[20];

  OSPI_RegularCmdTypeDef  sCommand;

  hospi1.Instance = OCTOSPI1;
  HAL_OSPI_DeInit(&hospi1);

  hospi1.Init.FifoThreshold         = 32;
  hospi1.Init.DualQuad              = HAL_OSPI_DUALQUAD_DISABLE;
  hospi1.Init.MemoryType            = HAL_OSPI_MEMTYPE_MACRONIX;
  hospi1.Init.DeviceSize            = 26;
  hospi1.Init.ChipSelectHighTime    = 2;
  hospi1.Init.FreeRunningClock      = HAL_OSPI_FREERUNCLK_DISABLE;
  hospi1.Init.ClockMode             = HAL_OSPI_CLOCK_MODE_0;
  hospi1.Init.WrapSize              = HAL_OSPI_WRAP_NOT_SUPPORTED;
  hospi1.Init.ClockPrescaler        = 0x3;
  hospi1.Init.SampleShifting        = HAL_OSPI_SAMPLE_SHIFTING_NONE;
  hospi1.Init.DelayHoldQuarterCycle = HAL_OSPI_DHQC_ENABLE;
  hospi1.Init.ChipSelectBoundary    = 0;

  if (HAL_OSPI_Init(&hospi1) != HAL_OK)
  {
    Error_Handler();
  }

  OSPI_ResetMemory();/*reset OSPI memory*/

  /* read ospi memory ID */
  sCommand.OperationType         = HAL_OSPI_OPTYPE_COMMON_CFG;
  sCommand.FlashId               = HAL_OSPI_FLASH_ID_1;
  sCommand.InstructionMode       = HAL_OSPI_INSTRUCTION_1_LINE;
  sCommand.InstructionSize       = HAL_OSPI_INSTRUCTION_8_BITS;
  sCommand.InstructionDtrMode    = HAL_OSPI_INSTRUCTION_DTR_DISABLE;
  sCommand.AddressDtrMode        = HAL_OSPI_ADDRESS_DTR_DISABLE;
  sCommand.AlternateBytes        = 0x00;
  sCommand.AlternateBytesMode    = HAL_OSPI_ALTERNATE_BYTES_NONE;
  sCommand.AlternateBytesSize    = HAL_OSPI_ALTERNATE_BYTES_8_BITS;
  sCommand.AlternateBytesDtrMode = HAL_OSPI_ALTERNATE_BYTES_DTR_DISABLE;
  sCommand.DataDtrMode           = HAL_OSPI_DATA_DTR_DISABLE;
  sCommand.DummyCycles           = 0;
  sCommand.DQSMode               = HAL_OSPI_DQS_DISABLE;
  sCommand.SIOOMode              = HAL_OSPI_SIOO_INST_EVERY_CMD;

  sCommand.Instruction           = READ_ID_CMD;
  sCommand.AddressMode           = HAL_OSPI_ADDRESS_NONE;
  sCommand.NbData                = 20;
  sCommand.DataMode              = OSPIDataMode;
  /*send cmd to read ID*/
  if (HAL_OSPI_Command(&hospi1, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
  {
    Error_Handler();
  }
  /*receive the ID*/
//  if (HAL_OSPI_Receive(&hospi1, id, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
//  {
//    Error_Handler();
//  }

  OSPI_OctalStrModeCfg(&hospi1);/*set OSPI mode to 8bit DTR*/

  return 0;
}

Make sure the data mode is correct

...
  sCommand.NbData                = 3; // Only reports 3
  sCommand.DataMode              = HAL_OSPI_DATA_1_LINE; // Use SPI mode

  /*send cmd to read ID*/
  if (HAL_OSPI_Command(&hospi1, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
  {
    Error_Handler();
  }
  /*receive the ID*/
  if (HAL_OSPI_Receive(&hospi1, id, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
  {
    Error_Handler();
  }

 

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

@Tesla DeLorean 

Thank you for the solution, it works now with the changes.