cancel
Showing results for 
Search instead for 
Did you mean: 

Writing from Bootloader on STM32H735

HispaEmo
Associate III

Hello everyone,

I am currently working on a bootloader project for the STM32H735, using the pre-configured ExtMem_Boot project provided by the STM32CubeIDE. However, I am encountering an issue when trying to write to the external flash memory at address 0x90000000.

Problem Description

I am using the function BSP_OSPI_NOR_Write to write data to the external flash memory. Here is the code snippet that performs the write operation:

 

HispaEmo_0-1718294101014.png

Issue Encountered

When the code enters the function BSP_OSPI_NOR_Write, it fails at the following point within the HAL_OSPI_Transmit function:

 

/* Wait till transfer complete flag is set to go back in idle state */
status = OSPI_WaitFlagStateUntilTimeout(hospi, HAL_OSPI_FLAG_TC, SET, tickstart, Timeout);

 

This error occurs specifically during the execution of the MX25LM51245G_PageProgramDTR function call:


/* Issue page program command */ if (MX25LM51245G_PageProgramDTR(&hospi_nor[Instance], (uint8_t*)data_addr, current_addr, current_size) != MX25LM51245G_OK) { ret = BSP_ERROR_COMPONENT_FAILURE; }

 

Additional Information

Despite this error, the jumptoapp function seems to execute correctly. However, I am unable to determine the root cause of this issue.

Request for Help

I would greatly appreciate any insights or suggestions on what might be causing this issue. Has anyone encountered similar problems or have experience with writing to external flash memory on the STM32H735? Any tips or advice on how to resolve this would be extremely helpful.

Thank you in advance for your assistance!

Best regards,
Emilio

7 REPLIES 7
HispaEmo
Associate III

I want to provide a bit more context to help you understand my issue and offer some guidance.

Specifically, I'm trying to implement a function that reads a .bin file from the SD card and writes it to the address 0x90000000.

I am using the BSP_OSPI_NOR_Write function for this task. However, I encountered an issue when I comment out the MemoryMapped mode in OSPI_Startup:

 

HispaEmo_0-1718360518315.png

When this section is commented, the code does not get stuck at MX25LM51245G_AutoPollingMemReady, but I always encounter a timeout error with MX25LM51245G_PageProgram.

 

HispaEmo_1-1718360600836.png

 

Has anyone encountered a similar issue or have any suggestions on how to resolve this? Any advice on correctly writing the .bin file to 0x90000000 would be greatly appreciated.

Thank you!

 

 

 

Memory Mapped mode can't be used concurrently with command mode.

When not memory mapped, you can't access / see the memory content at 0x90000000

The OSPI Memory doesn't understand the mapping in the STM32, so it's address is zero based, so you'll want to mask the address passed in.

ie

.Address = address & 0x0FFFFFFF; // Mask to lower 28-bits

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

Thank you, I can run my code.

But Im trying to:

HispaEmo_1-1718370255471.png

with

uint8_t aTxBuffer[] = " ****Memory-mapped OSPI communication**** ****Memory-mapped OSPI communication**** ****Memory-mapped OSPI communication**** ****Memory-mapped OSPI communication**** ****Memory-mapped OSPI communication**** ****Memory-mapped OSPI communication**** ";

but:

 

HispaEmo_2-1718370327734.png

 

is something wrong?

I changed this as you say:

HispaEmo_3-1718370384452.png


many many thanks @Tesla DeLorean 

HispaEmo
Associate III

sorry i didnt uncomment BSP_OSPI_NOR_DisableMemoryMappedMode(0);

HispaEmo_4-1718370969338.png

 

MNapi
Senior III

You can always use this code to write then enable memory mapped mode later and read from 0x90000000

You write to address = 0

This code is working on me on H7 chip and same MX25LM5124

I had some problems too to write in mapped mode.

 

/* Configure the memory in octal mode ------------------------------------- */

OSPI_OctalModeCfg(&hospi1);

sCommand.OperationType = HAL_OSPI_OPTYPE_COMMON_CFG;
sCommand.FlashId = HAL_OSPI_FLASH_ID_1;
sCommand.InstructionMode = HAL_OSPI_INSTRUCTION_8_LINES;
sCommand.InstructionSize = HAL_OSPI_INSTRUCTION_16_BITS;
sCommand.InstructionDtrMode = HAL_OSPI_INSTRUCTION_DTR_DISABLE;
sCommand.AddressSize = HAL_OSPI_ADDRESS_32_BITS;
sCommand.AddressDtrMode = HAL_OSPI_ADDRESS_DTR_DISABLE;
sCommand.AlternateBytesMode = HAL_OSPI_ALTERNATE_BYTES_NONE;
sCommand.DataDtrMode = HAL_OSPI_DATA_DTR_DISABLE;
sCommand.DQSMode = HAL_OSPI_DQS_DISABLE;
sCommand.SIOOMode = HAL_OSPI_SIOO_INST_EVERY_CMD;

 

OSPI_WriteEnable(&hospi1);

/* Erasing Sequence -------------------------------------------------- */
sCommand.Instruction = OCTAL_SECTOR_ERASE_CMD;
sCommand.AddressMode = HAL_OSPI_ADDRESS_8_LINES;
sCommand.Address = address;
sCommand.DataMode = HAL_OSPI_DATA_NONE;
sCommand.DummyCycles = 0;

if (HAL_OSPI_Command_IT(&hospi1, &sCommand) != HAL_OK)
{

Error_Handler();
}

/* Configure automatic polling mode to wait for end of erase ------ */

OSPI_AutoPollingMemReady(&hospi1);

/* Enable write operations ---------------------------------------- */
OSPI_WriteEnable(&hospi1);

/* Writing Sequence ----------------------------------------------- */
sCommand.Instruction = OCTAL_PAGE_PROG_CMD;
sCommand.DataMode = HAL_OSPI_DATA_8_LINES;
sCommand.NbData = BUFFERSIZE;

if (HAL_OSPI_Command(&hospi1, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{

Error_Handler();
}

if (HAL_OSPI_Transmit_IT(&hospi1, aTxBuffer) != HAL_OK)
{

Error_Handler();
}

 

Hello @Tesla DeLorean @MNapi ,

I wanted to share my recent progress and an issue I encountered while working on my bootloader project for the STM32H735, using the pre-configured **ExtMem_Boot** project from STM32CubeIDE.

**Progress and Solution for Writing:**

I was able to resolve the write issue to the external flash memory at address `0x90000000`. The key was understanding that **Memory Mapped mode can't be used concurrently with command mode**. When not in memory-mapped mode, you can't access or see the memory content at `0x90000000`. The OSPI Memory doesn’t understand the mapping in the STM32, so its address is zero-based. Here’s how I masked the address:


.Address = address & 0x0FFFFFFF; // Mask to lower 28-bits

Disabling memory-mapped mode before writing and ensuring the correct address masking resolved the issue for the `BSP_OSPI_NOR_Write` function.

 

**Current Issue with Reading:**

Given that the `write` function works with these adjustments, I expected similar behavior for the `read` function. However, I am running into a timeout issue. Here’s what I did:


if (MX25LM51245G_ReadDTR(&hospi_nor[Instance], pData, ReadAddr, Size) != MX25LM51245G_OK) {
ret = BSP_ERROR_COMPONENT_FAILURE;
}

But I encounter a timeout here:


/* Wait till busy flag is reset */
status = OSPI_WaitFlagStateUntilTimeout(hospi, HAL_OSPI_FLAG_BUSY, RESET, tickstart, Timeout);

**Steps Taken:**

1. Disabling memory-mapped mode using `BSP_OSPI_NOR_DisableMemoryMappedMode()`.
2. Attempting to read data using `BSP_OSPI_NOR_Read` with address masking.

Despite these steps, the read operation times out, unlike the write operation which functions correctly.

**Questions:**

1. What might be the missing step or additional configuration required to make the `read` operation work similarly to the `write` operation in this context?
2. Are there specific considerations for read operations in OSPI that differ from write operations?

Any insights or suggestions would be greatly appreciated. Thank you in advance!

 

Following up on my previous post, I wanted to share more details about the functions I'm implementing for my bootloader project.

Specifically, I am working on writing metadata, reading data, and then loading a .bin file before finally jumping to the application. In these functions, I had initially activated and deactivated memory-mapped mode for each read and write operation. However, I encountered timer errors (timeouts) during both the write and read operations.

I observed that if I only activate memory-mapped mode after completing all command functionalities (read, write, but not erase), these timeouts disappear.

I'm curious if the behavior of activating and deactivating memory-mapped mode can indeed cause these timeouts. It seems that keeping the memory in command mode until all operations are done and then switching to memory-mapped mode is more stable.

Has anyone else experienced similar issues with OSPI memory operations and memory-mapped mode toggling? Any insights or recommendations would be greatly appreciated.

Thank you!