Skip to main content
Explorer II
February 26, 2025
Solved

STM32H7 Flash write in XIP mode using Zephyr

  • February 26, 2025
  • 4 replies
  • 1571 views

Hi,

I am running my Zephyr application from an OSPI external flash and would like to write to the same flash. The MCU is an STM32H730, and the flash is an IS25LP128.

However, the flash_stm32_ospi_write method in zephyr/drivers/flash/flash_stm32_ospi.c causes my application to hang. The issue seems to be that the relevant semaphores are not initialized in the flash_stm32_ospi_init function.

To address this, I added the following two lines to flash_stm32_ospi_init:

 

 

k_sem_init(&dev_data->sem, 1, 1);
k_sem_init(&dev_data->sync, 0, 1);

 

 

After this modification, I am having problems in aborting the ongoing memory-mapped operation.

Could anyone provide guidance on properly handling flash write in XIP mode. Any pointers or suggestions would be greatly appreciated! 

Thanks.

    This topic has been closed for replies.
    Best answer by Sarra.S

    Hello @karsparskambala

    The STM32H723 supports both read and write operations in memory-mapped mode, but not simultaneously. This means you cannot perform write operations while the flash is being accessed for execution in memory-mapped mode

    I suggest you to program the external memory from the internal flash. So you will XIP from external memory, then jump to internal flash in order to program the external memory then jump back to XIP

     

    4 replies

    Sarra.SAnswer
    ST Employee
    February 27, 2025

    Hello @karsparskambala

    The STM32H723 supports both read and write operations in memory-mapped mode, but not simultaneously. This means you cannot perform write operations while the flash is being accessed for execution in memory-mapped mode

    I suggest you to program the external memory from the internal flash. So you will XIP from external memory, then jump to internal flash in order to program the external memory then jump back to XIP

     

    Explorer II
    February 27, 2025

    Hello @Sarra.S 

    Thank you very much for your response!

    I am going to try programming the flash from internal flash.

    However, to fully understand my other options:

    Would it be technically possible to relocate some of my code (such as the OSPI flash driver) to RAM and then attempt to write to flash?

    Below is a snippet from the OSPI flash driver (zephyr/drivers/flash/flash_stm32_ospi.c):"

    Also, doesn't calling stm32_ospi_abort exit XIP mode, allowing me to proceed with the flash write operation?

     

    	ospi_lock_thread(dev);
    
    #ifdef CONFIG_STM32_MEMMAP
    	if (stm32_ospi_is_memorymap(dev)) {
    		/* Abort ongoing transfer to force CS high/BUSY deasserted */
    		ret = stm32_ospi_abort(dev);
    		if (ret != 0) {
    			LOG_ERR("Failed to abort memory-mapped access before write");
    			goto end_write;
    		}
    	}
    	/* Continue with Indirect Mode */
    #endif /* CONFIG_STM32_MEMMAP */
    	/* page program for STR or DTR mode */
    	OSPI_RegularCmdTypeDef cmd_pp = ospi_prepare_cmd(dev_cfg->data_mode, dev_cfg->data_rate);

     

     

    Explorer II
    February 28, 2025

    I mistakenly wrote MCU as h723 instead of h730, but I guess it won’t change your answer.

    Visitor II
    September 17, 2025

    Hello @karsparskambala.

    We are also searching for such a solution. Did you have any luck in remapping and using the flash access routines out of the internal RAM?

    Regards