cancel
Showing results for 
Search instead for 
Did you mean: 

Single word (32 bit ) Flash programming STM32G0

HPATH.1
Associate II

I am trying to make UART boot loader and programming via Teraterm by sending HEX file.

some hex records have only 4 bytes. how to program only one word.

Reference manual RM0454 page no. 59 says only double word can be programmed.

How to program single word only ?

can I skip writing one word by modifying the below function ? in stm32g0xx_hal_flash.c

Sample Hex records

:1000000000900020690C0008C10B0008C70B000815

:100B60000000000000000000000000000000000085

:0C0B700000000000000000000000000079

:040B7C00E10000088C

:040B8000B9000008B0

:100B84001E00000064000000D007000064000000A4

/**
  * @brief  Program double-word (64-bit) at a specified address.
  * @param  Address Specifies the address to be programmed.
  * @param  Data Specifies the data to be programmed.
  * @retval None
  */
static void FLASH_Program_DoubleWord(uint32_t Address, uint64_t Data)
{
  /* Set PG bit */
  SET_BIT(FLASH->CR, FLASH_CR_PG);
 
  /* Program first word */
  *(uint32_t *)Address = (uint32_t)Data;
 
  /* Barrier to ensure programming is performed in 2 steps, in right order
    (independently of compiler optimization behavior) */
  __ISB();
 
  /* Program second word */
  *(uint32_t *)(Address + 4U) = (uint32_t)(Data >> 32U);
}

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

> Reference manual RM0454 page no. 59 says only double word can be programmed.

> How to program single word only ?

You can only program double words, per the RM. You'll need to pad the value with 0xFF or 0x00 or whatever you want.

The Flash memory is programmed 72 bits (64-bit data plus 8-bit ECC) at a time.

Programming a previously programmed address with a non-zero data is not allowed. Any such attempt sets PROGERR flag of the FLASH status register (FLASH_SR).

It is only possible to program a double word (2 x 32-bit data).

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Guru

> Reference manual RM0454 page no. 59 says only double word can be programmed.

> How to program single word only ?

You can only program double words, per the RM. You'll need to pad the value with 0xFF or 0x00 or whatever you want.

The Flash memory is programmed 72 bits (64-bit data plus 8-bit ECC) at a time.

Programming a previously programmed address with a non-zero data is not allowed. Any such attempt sets PROGERR flag of the FLASH status register (FLASH_SR).

It is only possible to program a double word (2 x 32-bit data).

If you feel a post has answered your question, please click "Accept as Solution".

Thank You. ​