cancel
Showing results for 
Search instead for 
Did you mean: 

How External OCTO SPI Flash activete for custom board design?

Freedom_Neo
Senior

I am using below development tools

MCU: STM32H7B3IIT6

IDE: STM32CubeIDE Version: 1.8.0

GUI: TouchGFX Version: 4.18.1

SDRAM: IS45S16800F-7CTLA1-TR

FLASH: MX25LM51245GMI00

Schematic

0693W00000KbQfoQAF.png

static void MX_OCTOSPI1_Init(void)
{
 
  /* USER CODE BEGIN OCTOSPI1_Init 0 */
 
  /* USER CODE END OCTOSPI1_Init 0 */
 
  OSPIM_CfgTypeDef sOspiManagerCfg = {0};
 
  /* USER CODE BEGIN OCTOSPI1_Init 1 */
 
  /* USER CODE END OCTOSPI1_Init 1 */
  /* OCTOSPI1 parameter configuration*/
  hospi1.Instance = OCTOSPI1;
  hospi1.Init.FifoThreshold = 1;
  hospi1.Init.DualQuad = HAL_OSPI_DUALQUAD_DISABLE;
  hospi1.Init.MemoryType = HAL_OSPI_MEMTYPE_MICRON;
  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 = 3;
  hospi1.Init.SampleShifting = HAL_OSPI_SAMPLE_SHIFTING_NONE;
  hospi1.Init.DelayHoldQuarterCycle = HAL_OSPI_DHQC_DISABLE;
  hospi1.Init.ChipSelectBoundary = 0;
  hospi1.Init.ClkChipSelectHighTime = 0;
  hospi1.Init.DelayBlockBypass = HAL_OSPI_DELAY_BLOCK_BYPASSED;
  hospi1.Init.MaxTran = 0;
  hospi1.Init.Refresh = 0;
  if (HAL_OSPI_Init(&hospi1) != HAL_OK)
  {
    Error_Handler();
  }
  sOspiManagerCfg.ClkPort = 1;
  sOspiManagerCfg.DQSPort = 1;
  sOspiManagerCfg.NCSPort = 1;
  sOspiManagerCfg.IOLowPort = HAL_OSPIM_IOPORT_1_LOW;
  sOspiManagerCfg.IOHighPort = HAL_OSPIM_IOPORT_1_HIGH;
  if (HAL_OSPIM_Config(&hospi1, &sOspiManagerCfg, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN OCTOSPI1_Init 2 */
  BSP_OSPI_NOR_Init_t Flash;
  Flash.InterfaceMode = BSP_OSPI_NOR_OPI_MODE;
  Flash.TransferRate  = BSP_OSPI_NOR_DTR_TRANSFER;
  BSP_OSPI_NOR_DeInit(0);
  int32_t RetVal = BSP_OSPI_NOR_Init(0, &Flash);
  if(RetVal != BSP_ERROR_NONE)
  {
    Error_Handler();
  }
  RetVal = BSP_OSPI_NOR_EnableMemoryMappedMode(0);
  if(RetVal != BSP_ERROR_NONE)
  {
    Error_Handler();
  }
  /* USER CODE END OCTOSPI1_Init 2 */
 
}

I am trying to activate octospi as custom board design, but the program gives an error. The program gets an error at the following place? What do you think could be the reason?

0693W00000KbQopQAF.png

1 ACCEPTED SOLUTION

Accepted Solutions
PChia.2237
Senior

Hi @Community member​ 

at which point you are?

I mean, your code is working with BSP_OSPI_NOR_Init() ?

When you have this working you have to do the external loader.

You post " These files for board not for STM32H7B3IIT6."

Okay.

You have to see the more simular to your application, take the example code and modify for your application to have extenal loader

okay?

View solution in original post

35 REPLIES 35
ChahinezC
Lead

Hello @Community member​,

Have you tried to reproduce the issue on ST board?

Chahinez.

Osman SOYKURT
ST Employee

Hello Freedom_Neo,

The code around BSP_OSPI_NOR_Init() looks good from my point of view, I don't know why you have that error raised line 52, you sure it's here ? I'll try to ask to my colleagues and keep you in touch.

/Osman

Osman SOYKURT
ST Software Developer | TouchGFX

Wouldn't you just debug/instrument your BSP_OSP_NOR_Init() implementation to understand where inside that it failed?

Work backward to the point that generated the error return.

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

Hello @ChahinezC​ I tryed in STM32H7B3I-DK develepment board. It worked. But I use custom board. When I tryed in custom board, this problem occured. I reproduce custom board but this problem continues

Hello @Osman SOYKURT​ This fonction returned -5 value. RetVal = -5

int32_t RetVal = BSP_OSPI_NOR_Init(0, &Flash);

and BSP_ERROR_NONE value is 0. This function must return 0 value. So program goes Error_Handler()'s function 

Hello @Community member​ BSP_OSP_NOR_Init()'s function returned -5 value. So This function must returned 0 value because

#define BSP_ERROR_NONE          0 

Freedom_Neo
Senior

This problem occurs below in stm32h7b3i_discovery_ospi.c source file

0693W00000KbbtgQAB.png 

#define BSP_ERROR_COMPONENT_FAILURE      -5
int32_t BSP_OSPI_NOR_Init(uint32_t Instance, BSP_OSPI_NOR_Init_t *Init)
{
  int32_t ret = BSP_ERROR_NONE;
  BSP_OSPI_NOR_Info_t pInfo;
  MX_OSPI_Config ospi_config;
 
  /* Check if the instance is supported */
  if(Instance >= OSPI_NOR_INSTANCES_NUMBER)
  {
    ret = BSP_ERROR_WRONG_PARAM;
  }
  else
  {
    /* Check if the instance is already initialized */
    if (Ospi_Nor_Ctx[Instance].IsInitialized == OSPI_ACCESS_NONE)
    {
#if (USE_HAL_OSPI_REGISTER_CALLBACKS == 0)
      /* Msp OSPI initialization */
      OSPI_NOR_MspInit(&hospi_nor[Instance]);
#else
      /* Register the OSPI MSP Callbacks */
      if(Ospi_Nor_Ctx[Instance].IsMspCallbacksValid == 0UL)
      {
        if(BSP_OSPI_NOR_RegisterDefaultMspCallbacks(Instance) != BSP_ERROR_NONE)
        {
          ret = BSP_ERROR_PERIPH_FAILURE;
        }
      }
      if(ret == BSP_ERROR_NONE)
      {
#endif /* USE_HAL_OSPI_REGISTER_CALLBACKS */
 
        /* Get Flash informations of one memory */
        (void)MX25LM51245G_GetFlashInfo(&pInfo);
 
        /* Fill config structure */
        ospi_config.ClockPrescaler = 3U;
        ospi_config.MemorySize     = (uint32_t)POSITION_VAL((uint32_t)pInfo.FlashSize);
        ospi_config.SampleShifting = HAL_OSPI_SAMPLE_SHIFTING_NONE;
        ospi_config.TransferRate   = (uint32_t)Init->TransferRate;
 
        /* STM32 OSPI interface initialization */
        if (MX_OSPI_NOR_Init(&hospi_nor[Instance], &ospi_config) != HAL_OK)
        {
          ret = BSP_ERROR_PERIPH_FAILURE;
        }
        /* OSPI memory reset */
        else if (OSPI_NOR_ResetMemory(Instance) != BSP_ERROR_NONE)
        {
          ret = BSP_ERROR_COMPONENT_FAILURE;
        }
        /* Check if memory is ready */
        else if (MX25LM51245G_AutoPollingMemReady(&hospi_nor[Instance], Ospi_Nor_Ctx[Instance].InterfaceMode, Ospi_Nor_Ctx[Instance].TransferRate) != MX25LM51245G_OK)
        {
          ret = BSP_ERROR_COMPONENT_FAILURE;
        }
        else
        {
          /* Configure the memory */
          if (BSP_OSPI_NOR_ConfigFlash(Instance, Init->InterfaceMode, Init->TransferRate) != BSP_ERROR_NONE)
          {
            ret = BSP_ERROR_COMPONENT_FAILURE;
          }
        }
#if (USE_HAL_OSPI_REGISTER_CALLBACKS == 1)
      }
#endif
    }
  }
 
  /* Return BSP status */
  return ret;
}

0693W00000Kbc2xQAB.png0693W00000Kbc4ZQAR.png

/**
  * @brief  This function enables the octal DTR mode of the memory.
  * @param  Instance  OSPI instance
  * @retval BSP status
  */
static int32_t OSPI_NOR_EnterDOPIMode(uint32_t Instance)
{
  int32_t ret = BSP_ERROR_NONE;
  uint8_t reg[2];
 
  /* Enable write operations */
  if (MX25LM51245G_WriteEnable(&hospi_nor[Instance], Ospi_Nor_Ctx[Instance].InterfaceMode, Ospi_Nor_Ctx[Instance].TransferRate) != MX25LM51245G_OK)
  {
    ret = BSP_ERROR_COMPONENT_FAILURE;
  }
  /* Write Configuration register 2 (with new dummy cycles) */
  else if (MX25LM51245G_WriteCfg2Register(&hospi_nor[Instance], Ospi_Nor_Ctx[Instance].InterfaceMode, Ospi_Nor_Ctx[Instance].TransferRate, MX25LM51245G_CR2_REG3_ADDR, MX25LM51245G_CR2_DC_6_CYCLES) != MX25LM51245G_OK)
  {
    ret = BSP_ERROR_COMPONENT_FAILURE;
  }
  /* Enable write operations */
  else if (MX25LM51245G_WriteEnable(&hospi_nor[Instance], Ospi_Nor_Ctx[Instance].InterfaceMode, Ospi_Nor_Ctx[Instance].TransferRate) != MX25LM51245G_OK)
  {
    ret = BSP_ERROR_COMPONENT_FAILURE;
  }
  /* Write Configuration register 2 (with Octal I/O SPI protocol) */
  else if (MX25LM51245G_WriteCfg2Register(&hospi_nor[Instance], Ospi_Nor_Ctx[Instance].InterfaceMode, Ospi_Nor_Ctx[Instance].TransferRate, MX25LM51245G_CR2_REG1_ADDR, MX25LM51245G_CR2_DOPI) != MX25LM51245G_OK)
  {
    ret = BSP_ERROR_COMPONENT_FAILURE;
  }
  else
  {
    /* Wait that the configuration is effective and check that memory is ready */
    HAL_Delay(MX25LM51245G_WRITE_REG_MAX_TIME);
 
    /* Reconfigure the memory type of the peripheral */
    hospi_nor[Instance].Init.MemoryType            = HAL_OSPI_MEMTYPE_MACRONIX;
    hospi_nor[Instance].Init.DelayHoldQuarterCycle = HAL_OSPI_DHQC_ENABLE;
    if (HAL_OSPI_Init(&hospi_nor[Instance]) != HAL_OK)
    {
      ret = BSP_ERROR_PERIPH_FAILURE;
    }
    /* Check Flash busy ? */
    else if (MX25LM51245G_AutoPollingMemReady(&hospi_nor[Instance], BSP_OSPI_NOR_OPI_MODE, BSP_OSPI_NOR_DTR_TRANSFER) != MX25LM51245G_OK)
    {
      ret = BSP_ERROR_COMPONENT_FAILURE;
    }
    /* Check the configuration has been correctly done */
    else if (MX25LM51245G_ReadCfg2Register(&hospi_nor[Instance], BSP_OSPI_NOR_OPI_MODE, BSP_OSPI_NOR_DTR_TRANSFER, MX25LM51245G_CR2_REG1_ADDR, reg) != MX25LM51245G_OK)
    {
      ret = BSP_ERROR_COMPONENT_FAILURE;
    }
    else
    {
      if (reg[0] != MX25LM51245G_CR2_DOPI)
      {
        ret = BSP_ERROR_COMPONENT_FAILURE;
      }
    }
  }
 
  /* Return BSP status */
  return ret;
}

0693W00000KbbvPQAR.png 

PChia.2237
Senior

Hi,

i already replay this in last post.

First edit My flash pin mapping in stm32h735g_discovery_ospi.h with your pin-map

Then set to single SPI so:

 ospi_nor_int.InterfaceMode = BSP_OSPI_NOR_SPI_MODE;

 ospi_nor_int.TransferRate = BSP_OSPI_NOR_STR_TRANSFER;

Freedom_Neo
Senior

Hello @Patrickhiapello​ The error is gone. Thank you for support.

Where we set below code?

Then set to single SPI so:

 ospi_nor_int.InterfaceMode = BSP_OSPI_NOR_SPI_MODE;

 ospi_nor_int.TransferRate = BSP_OSPI_NOR_STR_TRANSFER;