cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U575 + W25Q128JV – Memory‑Mapped Mode returns only 0x00 although Indirect Read/Write works

EniRot99
Associate III

System setup

Component Details
MCUSTM32U575 (OctoSPI1)
FlashWinbond W25Q128JV – Quad‑SPI NOR flash
IDE / FWSTM32CubeIDE 1.18.1, STM32 HAL
ClockingOSPI clock = 50 MHz, Dummy cycles = 8
Supply

VDDL = 3V3, Flash = 3V3

What already works

  • Indirect Read/Write via HAL_OSPI_Command() + HAL_OSPI_TransmitReceive() is fine.

  • External loader built; CubeProgrammer can erase, program, verify and read the entire flash (see screenshot).

  • Constant data is programmed successfully:

const char string2[30] __attribute__((section(".ext_flash"))) __attribute__((aligned(4))) = "Hello Word";

CubeProgrammer shows the text correctly.

The problem

As soon as I switch to Memory‑Mapped mode every word read is 0x00000000.
No hard faults—just empty data.

EniRot99_0-1746532399830.png

Checks so far

  1. MPU region

    • Base = 0x9000 0000, Size = 8 MB, Attributes = Normal, WT, Shareable, Execute‑Never.

  2. Cache

    • I‑ and D‑cache invalidated before/after enabling MM.

    • Also tried with caches fully disabled → still 0x00.

  3. OctoSPI config

    • Quad‑SPI, SDR, DQS disabled.

    • Dummy = 8 (datasheet value @ ≤ 50 MHz).

    • InstructionLine, DataLine, AlternateByteLine all set to 4‑line.

  4. Command sequencer

    • READ (0x6B) + 4‑byte addressing; identical timing to the external loader.

  5. Linear address offset

    • 0x0000 0000 (same as loader).

    • Also tried 0x9000 0000 → no difference.

Memory mapped mode configuration:

HAL_StatusTypeDef OFlash_EnableMemoryMappedMode( void )
{
    OSPI_RegularCmdTypeDef sCommand = {0};
    OSPI_MemoryMappedTypeDef sMemMappedCfg = {0};

    // Set reading command
    OFlash_DefaultCmd(&sCommand);

    // OPTION 1: Quad Output Fast Read (0x6B) - Only data is quad
    sCommand.Instruction = 0x6B;
    sCommand.InstructionMode = HAL_OSPI_INSTRUCTION_1_LINE;
    sCommand.InstructionSize = HAL_OSPI_INSTRUCTION_8_BITS;

    sCommand.AddressMode = HAL_OSPI_ADDRESS_1_LINE;  
    sCommand.AddressSize = HAL_OSPI_ADDRESS_24_BITS;
    sCommand.DummyCycles = 8;

    sCommand.AlternateBytesMode = HAL_OSPI_ALTERNATE_BYTES_NONE;

    sCommand.DataMode = HAL_OSPI_DATA_4_LINES;
    sCommand.SIOOMode = HAL_OSPI_SIOO_INST_EVERY_CMD;

    // Write configuration
    if (HAL_OSPI_Command(&FLASH_OSPI_PORT, &sCommand, QFLASH_DEF_TIMEOUT) != HAL_OK)
    {
        return HAL_ERROR;
    }

    // Set memory-mapped mode configuration
    sMemMappedCfg.TimeOutActivation = HAL_OSPI_TIMEOUT_COUNTER_DISABLE;

    // Enable memory-mapped mode
    if (HAL_OSPI_MemoryMapped(&FLASH_OSPI_PORT, &sMemMappedCfg) != HAL_OK)
    {
        return HAL_ERROR;
    }

    return HAL_OK;
}

MPU is setup like: 

  /** Initializes and configures the Region 2 and the memory to be protected
  */
  MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  MPU_InitStruct.Number = MPU_REGION_NUMBER0;
  MPU_InitStruct.BaseAddress = 0x90000000;                /* External flash base address */
  MPU_InitStruct.LimitAddress = 0x90000000 + (8 * 1024 * 1024) - 1; /* Base + 8MB - 1 */
  MPU_InitStruct.AttributesIndex = MPU_ATTRIBUTES_NUMBER0; /* Use the attributes we defined */
  MPU_InitStruct.AccessPermission = MPU_REGION_ALL_RW;     /* Read/write permission */
  MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE; /* Enable instruction access */
  MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;

  HAL_MPU_ConfigRegion(&MPU_InitStruct);

 

With STM32CubeProgrammer and the external loader I could read the data: 

EniRot99_2-1746532646797.png

 

Questions for the community

  1. Is there a special OSPI or MPU setting required to make Memory‑Mapped mode work on the U5?

  2. Does the flash need to be explicitly put into “Continuous Read” before MM is enabled?

  3. Any known STM32U5 OctoSPI issues in Quad‑SPI MM?

  4. Common cache / DQS pitfalls when switching from Indirect to MM that I might have missed?

I’m running out of ideas any hint?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @KDJEM.1 

thanks for you response, and sorry for posting in the wrong topic. 

The code I shared actually works fine. The issue turned out to be a faulty high‑side switch I was using to turn the flash on and off.

 

I haven’t analysed the root cause in detail yet, but it looks as though power consumption in memory‑mapped mode is higher than in normal read/write mode. Each time I called

HAL_StatusTypeDef OFlash_EnableMemoryMappedMode( void )

the flash’s VCC line sagged and the device performed an unwanted reset.

View solution in original post

2 REPLIES 2
KDJEM.1
ST Employee

Hello @EniRot99;

 

I recommend you to look at the STM32U5 errata sheet for OCTOSPI errata. You can find in this document the OCTOSPI errata related to memory mapped and the workaround.

Make sure that the memory is ready after the programming. For that, you can add a delay corresponding to the max page programming time before the reading sequence.

I advise you to get inspired from OSPI_NOR_MemoryMapped example may help you. This example describes how to erase a part of an OSPI NOR memory, write data, and access to OSPI NOR memory in memory-mapped mode to check the data in an infinite loop.

 

Thank you.

Kaouthar

 

  

 

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi @KDJEM.1 

thanks for you response, and sorry for posting in the wrong topic. 

The code I shared actually works fine. The issue turned out to be a faulty high‑side switch I was using to turn the flash on and off.

 

I haven’t analysed the root cause in detail yet, but it looks as though power consumption in memory‑mapped mode is higher than in normal read/write mode. Each time I called

HAL_StatusTypeDef OFlash_EnableMemoryMappedMode( void )

the flash’s VCC line sagged and the device performed an unwanted reset.