cancel
Showing results for 
Search instead for 
Did you mean: 

Write the data into the flash memory

ajimathew
Associate III

Dear @KDJEM.1 

I need to write the data to flash memory also read from the flash memory. I am using STM32L4P5-Dk(1MB of flash is available) in that ,say 0xABFF23 should be stored in the flash memory. How it can be done ?

which hal function should be used?

1 ACCEPTED SOLUTION

Accepted Solutions
KDJEM.1
ST Employee

Hello @ajimathew ,

You can find the HAL_FLASH functions in the stm32l4xx_hal_flash.c drivers.

To read/write data from/to flash memory with HAL functions, I advise you to get inspired from an available example such as FLASH_FastProgram under STM32CubeL4.

This example can help you to understand and use the FLASH HAL API to erase and fast program the internal Flash.

Note that this example has been tested with NUCLEO-L4P5ZG (144 pins) board and can be easily tailored to any other supported device and development board.

When your question is answered, please close this topic by choosing "Accept as Solution". This will help other users find that answer faster.

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.

View solution in original post

2 REPLIES 2
KDJEM.1
ST Employee

Hello @ajimathew ,

You can find the HAL_FLASH functions in the stm32l4xx_hal_flash.c drivers.

To read/write data from/to flash memory with HAL functions, I advise you to get inspired from an available example such as FLASH_FastProgram under STM32CubeL4.

This example can help you to understand and use the FLASH HAL API to erase and fast program the internal Flash.

Note that this example has been tested with NUCLEO-L4P5ZG (144 pins) board and can be easily tailored to any other supported device and development board.

When your question is answered, please close this topic by choosing "Accept as Solution". This will help other users find that answer faster.

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.

ajimathew
Associate III

Thank you @KDJEM.1 . 

I referred the above reference. It worked

But when I read the manual "rm0432" It is given that

The Flash memory programming sequence in standard mode is as follows:

1. Check that no Flash main memory operation is ongoing by checking the BSY bit in the
Flash status register (FLASH_SR).
2. Check and clear all error programming flags due to a previous programming. If not,
PGSERR is set.
3. Set the PG bit in the Flash control register (FLASH_CR).
4. Perform the data write operation at the desired memory address, inside main memory
block or OTP area. Only double word can be programmed.
– Write a first word in an address aligned with double word
– Write the second word
5. Wait until the BSY bit is cleared in the FLASH_SR register.
6. Check that EOP flag is set in the FLASH_SR register (meaning that the programming
operation has succeed), and clear it by software.
7. Clear the PG bit in the FLASH_SR register if there no more programming request
anymore.

My code is

uint64_t data=0x1234567890ABCDEF;

HAL_FLASH_Unlock();
HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD,0x0803F000,data);
HAL_FLASH_Lock();

 

flash.png

 The data have been stored in the desired address. My doubt is, as per the manual I didn't set PG bit and check any status of the flash register but I got an output how?