cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 Flash write in XIP mode using Zephyr

karsparskambala
Associate II

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 STM32H723, 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.

1 ACCEPTED SOLUTION

Accepted Solutions
Sarra.S
ST Employee

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

 

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.

View solution in original post

2 REPLIES 2
Sarra.S
ST Employee

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

 

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.

karsparskambala
Associate II

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);