Skip to main content
Gz_it
Associate III
August 7, 2017
Question

EEPROM for Cube MX STM32F301C8

  • August 7, 2017
  • 1 reply
  • 1228 views
Posted on August 07, 2017 at 09:13

Hi,

I would like to used EEPROM for STM32F301C8. I am used code below

uint32_t READ_FLASH(

uint32_t

DataAdr)

{

return *(int32u *)DataAdr;

}

void WRITE_FLASH(

uint32_t

DataAdr,

uint32_t

Data)

{

erase_pages.PageAddress=DataAdr;

erase_pages.NbPages=4;

erase_pages.TypeErase=TYPEERASE_PAGES;

HAL_FLASH_Unlock();

HAL_FLASHEx_Erase(&erase_pages, Error);

HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, DataAdr, Data);

HAL_FLASH_Lock();

}

It's not working. Please tell me about EEPROM or How I can learning if I am used to HAL library.

#stm #cube-mx #stm32-f3 #hal
This topic has been closed for replies.

1 reply

Brian TIDAL
Technical Moderator
August 7, 2017
Posted on August 07, 2017 at 15:27

Hi,

As far as I know, there is no EEPROM in STM32F301x6/8 MCUs. EEPROM feature is available on STM32L0 and STM32L1 families. An EEPROM emulation feature is also available on STM32L4 (see

http://www.st.com/content/ccc/resource/technical/document/application_note/group0/b2/94/a6/62/18/c0/4f/e6/DM00311483/files/DM00311483.pdf/jcr:content/translations/en.DM00311483.pdf

).

In your code, the WRITE_FLASH() procedure will erase 4 pages of FLASH memory, i.e. 4 * 2048 bytes which is probably not what you want if trying to emulate EEPROM. See

http://www.st.com/content/ccc/resource/technical/document/reference_manual/a5/e0/21/a3/78/00/41/1e/DM00094350.pdf/files/DM00094350.pdf/jcr:content/translations/en.DM00094350.pdf

for information about FLASH memory organization in STM32F301x6/8 MCUs.

Examples of FLASH programming can be found in STM32Cube_FW_F3_V1.9.0\Projects folder for various STM32F3 MCU:

  • FLASH_EraseProgram: this example describes how to configure and use the FLASH HAL API to erase and program the internal Flash memory. 
  • FLASH_WriteProtection: this example describes how to configure and use the FLASH HAL API to enable and disable the write protection of the internal Flash memory. 

When using the HAL API in your code, make sure to deal with the return code of the API.

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.
Gz_it
Gz_itAuthor
Associate III
August 8, 2017
Posted on August 08, 2017 at 03:19

If I am used to IAP function. Where can I find an example?

Gz_it
Gz_itAuthor
Associate III
August 8, 2017
Posted on August 08, 2017 at 05:25

Thank you very much. I found 

Examples of FLASH programming can be found in STM32Cube_FW_F3_V1.9.0\Projects folder for various STM32F3 MCU:

  • FLASH_EraseProgram: this example describes how to configure and use the FLASH HAL API to erase and program the internal Flash memory. 
  • FLASH_WriteProtection: this example describes how to configure and use the FLASH HAL API to enable and disable the write protection of the internal Flash memory.