Skip to main content
Freedom_Neo
Senior
March 4, 2022
Solved

How External OCTO SPI Flash activete for custom board design?

  • March 4, 2022
  • 35 replies
  • 17000 views

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

This topic has been closed for replies.
Best answer by PChia.2237

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?

35 replies

ChahinezC
Associate II
March 4, 2022

Hello @Community member​,

Have you tried to reproduce the issue on ST board?

Chahinez.

Freedom_Neo
Senior
March 7, 2022

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

Osman SOYKURT
ST Technical Moderator
March 4, 2022

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

ST Software Developer | TouchGFX
Freedom_Neo
Senior
March 7, 2022

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 

Tesla DeLorean
Guru
March 4, 2022

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Freedom_Neo
Senior
March 7, 2022

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
March 7, 2022

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
March 7, 2022

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
March 7, 2022
Freedom_Neo
Senior
March 7, 2022

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;

Freedom_Neo
Senior
March 7, 2022

Hi Everyone,

I've made progress. But I am getting an error while uploading. What do you think could be the reason?

0693W00000Kbe4lQAB.png

Osman SOYKURT
ST Technical Moderator
March 7, 2022

Hello Freedom_Neo,

We have a software called STM32CubeProgrammer that can help you erasing your memory. You can try to install it and then follow this steps :

1- Connect your board to your PC and click on "Connect" button (top right)

0693W00000KbeNnQAJ.png 

2- Click on the 2nd button on the left panel (with the arrow) and click on "Erase flash memory" and "Full chip erase".

0693W00000KbeU0QAJ.png 

3) If you want to erase your external memory, you can do the same with "Erase external memory"

You can also try to remove your breakpoints as it says there is a error with them.

/Osman

ST Software Developer | TouchGFX
Freedom_Neo
Senior
March 7, 2022

Hi @Osman SOYKURT​ 

I did 1. and 2. steps. But The failure accurs 3. step. The deletion process takes 4-5 minutes, but at the end it gives an error as follows.

You can also try to remove your breakpoints as it says there is a error with them.

Dont have any breakpoint anywhere

0693W00000Kbf9IQAR.png 

Peter Chang
Associate
March 8, 2022

If BSP_OSPI_NOR_Init() function fail then you can not do anything.

We need detail to known which point failed.

I think this Flash is damaged. Please replace it.

And, Make sure the Flash was come from authorized channel.

Freedom_Neo
Senior
March 8, 2022

Hello @molecule.192g​ I replaced with new FLASH. But this problem continues. FLASH came from Macronicx sample

Peter Chang
Associate
March 9, 2022
Dear Freedom, So, finally you solve external loader problem by set Flash interface to SPI-STR mode. It means OPI-DTR work in your project, but it can not work in external loader. Am I right ? If yes then it's a very strange things. I can help to detail trace this issue if you want. Thanks & best regards ! Peter Chang 張耀�? Macronix International Co., LTD. (O) +886-2-25093300 ext : 207 "ST Community" 2022/03/08 下�?� 07:45 請回信 給 "Reply to ST Community" <0-1bcxwsri99pkaj.yoyaj690n9stx2fk.z41oyo9i2qqn0xj0@66wlj7ts8xn84pya.nwklyxs6rhfswjvt.b-ytg6eak.eu28.chatter.salesforce.com> 收件人 "peterchang01@mxic.com.tw" , 副本抄�? 主旨 Freedom_Neo mentioned you in an answer to: How External OCTO SPI Flash activete for custom board design? Hello @molecule.192g​ I replaced with new FLASH. But this problem continues. FLASH came from Macronicx sample Freedom_Neo (Community Member) Hello @molecule.192g (Community Member)​ I replaced with new FLASH. But this problem continues. FLASH came from Macronicx sample View/Answer or reply to this email Replying to How External OCTO SPI Flash activete for custom board design? Peter Chang (Community Member) Tuesday, March 8, 2022 10:13 AM If BSP_OSPI_NOR_Init() function fail then you can not do anything. We need detail to known which point failed. I think this Flash is damaged. Please replace it. And, Make sure the Flash was come from authorized channel. Freedom_Neo (Community Member) Hello @molecule.192g (Community Member)​ I replaced with new FLASH. But this problem continues. FLASH came from Macronicx sample Tuesday, March 8, 2022 7:45 PM You're receiving emails when someone "Mentions me in a comment." To change or turn off ST Community email, log in as peterchang01@mxic.com.tw.st. STMicroelectronics N.V. CONFIDENTIALITY NOTE: This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation. Macronix International Co., Ltd.
Freedom_Neo
Senior
March 9, 2022

Dear @Community member​ 

Do you have ant opinion this problem?

Tesla DeLorean
Guru
March 10, 2022

Well that's me, and I'm monitoring things, but a week in and I'm not sure which pins you're using, and I don't have this IC or a STM32H7B3-DK board.

https://github.com/cturvey/stm32extldr/blob/main/h7a3_octo_pins.txt

Can we PLEASE establish which pins you're using?

At least with those it might be possible to patch/fix the DK's .stldr to match your hardware configuration, and see if it is simply that causing the issues, or if it's some mode/setting disagreement.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Freedom_Neo
Senior
March 11, 2022

Dear @Community member​ Thank you for support. I am using below pins.

// STM32H7B3IIT6 PIN CHART
// MX25LM51245GMI00 (16-PIN SOP)
 
// OCTOSPIM P1
// D0 PD11:AF9 
// D1 PD12:AF9 
// D2 PE2:AF9 
// D3 PD13:AF9
// D4 PC1:AF10 
// D5 PC2:AF11 
// D6 PC3:AF11 
// D7 PD7:AF10
// CLK PB2:AF9
// NCLK NOT USED
// NCS PB10:AF9 
// DQS PC5:AF10

0693W00000KcCgUQAV.png0693W00000KcCgjQAF.png 

PChia.2237
PChia.2237Best answer
Senior
March 9, 2022

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?

Freedom_Neo
Senior
March 9, 2022

Hi @Patrickhiapello​ Thank you for support. I am working on external loader for my board. The reason for this problem my board pins different of STM32H7B3-DK has pins.