Skip to main content
Graduate
August 20, 2025
Solved

How to read and write variables into Flash memory in STM32C092CCT6 (STM32C0 series)

  • August 20, 2025
  • 1 reply
  • 834 views

I am working with an STM32C092CCT6 (STM32C0 series) and I need help with reading and writing variables into Flash memory.

  • I want to store a few configuration values (like integers or structures) that should persist after reset or power cycle.

  • From what I understand, I need to erase a Flash page first and then program data at a specific address.

  • I am not sure about the correct sequence for the C0 series (unlocking Flash, erasing, programming, and locking again).

  • I would like to know the best practice for data alignment (word/halfword).

  • Should I use HAL functions like  HAL_FLASH_Program() or is direct register access recommended for reliability?

  • If anyone has a working example code snippet or reference for reading/writing user variables into Flash on STM32C0, it would be really helpful.

Thanks in advance!

    This topic has been closed for replies.
    Best answer by NesrynELMK

    Hello @anuj18ap ,

    Please find below the steps for Flash Memory Operations:

    Unlock Flash Memory:
    Before performing any operation, the Flash memory must be unlocked. Use the HAL_FLASH_Unlock() function.

    Erase Flash Page:
    Flash memory must be erased prior to writing new data. Use the HAL_FLASHEx_Erase() function to erase a specific Flash page.

    Program Flash Memory:
    Write data to Flash memory using the HAL_FLASH_Program() function

    Lock Flash Memory:
    After completing all operations, lock the Flash memory by calling HAL_FLASH_Lock() to prevent accidental writes.

    For a practical implementation, you can refer to the example FLASH_EraseProgram provided in the STM32CubeFW for the C0 series.

    Kind regards,

    1 reply

    ST Employee
    August 20, 2025

    Hello @anuj18ap ,

    Please find below the steps for Flash Memory Operations:

    Unlock Flash Memory:
    Before performing any operation, the Flash memory must be unlocked. Use the HAL_FLASH_Unlock() function.

    Erase Flash Page:
    Flash memory must be erased prior to writing new data. Use the HAL_FLASHEx_Erase() function to erase a specific Flash page.

    Program Flash Memory:
    Write data to Flash memory using the HAL_FLASH_Program() function

    Lock Flash Memory:
    After completing all operations, lock the Flash memory by calling HAL_FLASH_Lock() to prevent accidental writes.

    For a practical implementation, you can refer to the example FLASH_EraseProgram provided in the STM32CubeFW for the C0 series.

    Kind regards,