cancel
Showing results for 
Search instead for 
Did you mean: 

STM32MP1: Persist data in flash memory from Cortex M4 core

Ludovic Feltz
Associate II

Hello,

I want to persist data in flash memory from the Cortex M4 program.

I created a section in the linker file:

.mySection 0x000000001002f000 :
{
    KEEP(*(.mySection))
} >RAM1_data

So i know where my data is in the RAM memory but i don't know how to write this data in flash memory so it can be persisted.

I saw a lot of examples for other STM products that use function similar to this:

void Write_Flash(uint8_t data)
{
      HAL_FLASH_Unlock();
     __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGSERR );
     FLASH_Erase_Sector(FLASH_SECTOR_6, VOLTAGE_RANGE_3);
     HAL_FLASH_Program(TYPEPROGRAM_WORD, FlashAddress, data);
     HAL_FLASH_Lock();
}

But i can't find the HAL library containing HAL_FLASH_XXXX function for the STM32mp1 series... Does this library exists?

How can i save the data in the flash memory or somewhere that is persisted after a hardware reboot?

Do i need to transfert data from M4 Core to A7 Core or does another solution exists for the STM32mp1 series? (i prefer to avoid to transfert data between the 2 core)

Best regards,

Ludovic Feltz.

5 REPLIES 5
Olivier GALLIEN
ST Employee

Hi @Ludovic Feltz​ ,

There is NO embedded flash in stm32mp1 and MCURAM is not persistent.

Only persistent storage would be the backup RAM if you power VBAT, or an external flash storage.

Hope it help,

Olivier

Olivier GALLIEN
In order 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 @Community member​ 

I saw in the linker file the following section:

/* Memories definition */
MEMORY
{
  RETRAM_interrupts		(xrw)	: ORIGIN = 0x00000000,	LENGTH = 0x00000298 
  FLASH_text		(rx)	: ORIGIN = 0x10000000,	LENGTH = 128K
  RAM1_data		(xrw)	: ORIGIN = 0x10020000,	LENGTH = 128K 
  RAM2_ipc_shm		(xrw)	: ORIGIN = 0x10040000,	LENGTH = 0x00008000
}

Isn't the FLASH_text memory a flash memory that can be used to persist data?

So you are telling me that i should transfert data to the A7 core and save theses data in the SD Card?

Or can i access SD Card from the M4 Core?

Olivier GALLIEN
ST Employee

Hi @Ludovic Feltz​ 

Where did you get this linker script ?

The one from template delivered in Cube 1.4 looks like this :

MEMORY

{

 m_interrupts (RX) : ORIGIN = 0x00000000, LENGTH = 0x00000298

 m_text    (RX) : ORIGIN = 0x10000000, LENGTH = 0x00020000

 m_data    (RW) : ORIGIN = 0x10020000, LENGTH = 0x00020000

 m_ipc_shm  (RW) : ORIGIN = 0x10040000, LENGTH = 0x00008000

}

Anyway, reference to FLASH is probably legacy from MCU kept by mistake.

Storage inside an SDCard drive on A7 side is indeed an option.

You can also directly access to a mass storage device M4 side through sdmmc3, QSPI or FMC interfaces.

Else, M4 can access directly to Backup RAM, taking care begin of this area is used by OpenSTLinux for low power management.

Olivier

Olivier GALLIEN
In order 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.
Ludovic Feltz
Associate II

@Community member​ 

Thank you for your quick response.

I use STM32CubeMX version 6.3.0 to generate the code (and so the linker script).

Ok i will try to find a way using sdmmc3 and reading some documentation about backup RAM. (is the creation of a section possible as with the normal RAM?)


@Olivier GALLIEN wrote:

Storage inside an SDCard drive on A7 side is indeed an option.

You can also directly access to a mass storage device M4 side through sdmmc3, QSPI or FMC interfaces.

I guess it is not possible to share one flash device (SD or eMMC) by both the A7 and M4 cores. I can't imagine how this could possibly work and how both cores would synchronize access to the device. Definitely shouldn't work with QSPI as one slave device cannot be accessed by multiple master devices at the same time.

In other words, if you already have a Linux running on your A7 and being in control of the SD or eMMC, the only chance to store data persistently from the firmware running on the M4 is to have some user-space daemon in Linux-land taking care of it, communicating via OpenAMP. Am I right?