Skip to main content
Explorer
July 6, 2023
Question

STM32G030 - FLASH - Fail to use FLASH_Program_Fast

  • July 6, 2023
  • 4 replies
  • 1682 views

Hi!

I am using STMCube IDE and a STM32G030F6

I am trying to implement a code that writes variables to the flash. And I was able to make it work, with some limitations...

THIS CODE WORKS

union
  {
  uint8_t regs[6];
  uint64_t data;
  } mem;  

  uint64_t *my_pointer;
  my_pointer = (uint64_t *)0x08007000; // base address of page 14
  if(*my_pointer == 0xFFFFFFFFFFFFFFFF) // if the memory is blank
  {
  HAL_FLASH_Unlock();
  mem.regs[0] = 25;
  mem.regs[1] = 50;
  mem.regs[2] = 75;
  mem.regs[3] = 100;
  mem.regs[4] = 1;
  mem.regs[5] = 0;

  HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, 0x08007000, mem.data);
  HAL_FLASH_Lock();
  }

I run this code in the initialization of the board, the first time the program runs it will enter the if...

Instead of using

HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD...

 I'd like to use:

HAL_FLASH_Program(FLASH_TYPEPROGRAM_FAST...

But i am not able to make it work... it crashes all the time in the function:

static void FLASH_Program_Fast(uint32_t Address, uint32_t DataAddress);

What is the best way to write a series of variables in the flash? I plan to write more than 20 uint16_t...

 

    This topic has been closed for replies.

    4 replies

    Explorer
    April 15, 2024

    Same here. The Flash_Program_Fast keeps crashing.

     

    Graduate II
    December 24, 2024

    Anyone at ST that has just a little interest in helping its customers?

    Visitor II
    May 28, 2025

    I have encountered the same issue, the FLASH_TYPEPROGRAM_FAST method crashes the micro and even aborts the debugging session.

    A workaround has been to wrap FLASH_TYPEPROGRAM_DOUBLEWORD in a function that behaves (takes in the same parameters) as FLASH_TYPEPROGRAM_FAST, which then executes as expected and without an issue.

    Super User
    May 28, 2025

    Would guess the issue here is that code has not been placed properly in RAM leading to unacceptable delays during fast programming. The __RAM_FUNC macro needs some help.