Skip to main content
Graduate II
March 18, 2024
Solved

Write to Flash only 64Bit

  • March 18, 2024
  • 3 replies
  • 2029 views

Hello,

Can I only write to the flash with 64 bit variables, or also 32/16/8 bit?
I just used this function for this: HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, activepageaddress + u32_Offset, u64_Data)
I have an STM32L432 uC.

I already found this example: https://github.com/STMicroelectronics/STM32CubeL4/blob/master/Projects/NUCLEO-L4P5ZG/Examples/FLASH/FLASH_FastProgram/Src/main.c

Many thanks in advance.

    This topic has been closed for replies.
    Best answer by STTwo-32

    Hello @Martin42 

    Flash programming is only by 64-bits at a time. On other series it can be 32-bits.

    STTwo32_0-1710763327109.png

    For more details refer to this post.

    Best Reagrds.

    STTwo-32

    3 replies

    STTwo-32Answer
    Technical Moderator
    March 18, 2024

    Hello @Martin42 

    Flash programming is only by 64-bits at a time. On other series it can be 32-bits.

    STTwo32_0-1710763327109.png

    For more details refer to this post.

    Best Reagrds.

    STTwo-32

    Graduate II
    March 18, 2024

    You'd use a structure (packed?) or array to consolidate the smaller variables into a larger / usable block that fits the minimum write width of the FLASH memory. You'd then write as a block.

    Martin42Author
    Graduate II
    March 18, 2024

     

    I would like to write a second firmware via Modbus and delete areas in the flash.
    I send the raw HEX file using a PC tool and then write 64 bits at a time, since the flash only allows access with 64 bits.

    To build the HEX file I use the addition "--gap-fill 0x00 --pad-to 0x08019000" to always get addresses with 32 bytes. This should also ensure that 64 bits are always written.
    e.g. arm-atollic-eabi-objcopy.exe -O ihex --gap-fill 0x00 --pad-to 0x08019000 "${BuildArtifactFileBaseName}.elf" "${BuildArtifactFileBaseName}.hex"

    -> Adds ":04018C00000000006F" the missing values for to fill 64 bit

     

    :1001600059C0000859C0000859C00008000000002C
    :1001700059C0000859C0000800000000000000003D
    :0C01800059C0000859C0000859C0000810
    :04018C00000000006F
    :1001900010B5054C237833B9044B13B10448AFF3C1
    :1001A00000800123237010BD1C010020000000000E

     

     

    Graduate II
    March 18, 2024

    Not sure if there was a question there.

    Either normalize the data on the host. Or as you process it on the target

    Martin42Author
    Graduate II
    March 18, 2024

    No question :)

    I will do it on the target.