Skip to main content
Visitor II
February 1, 2022
Question

Why is a single 23-bit value not correctly written to the flash memory when I use 'HAL_FLASH_Program()'?

  • February 1, 2022
  • 3 replies
  • 1877 views

Hello

I've managed to get the 'FLASH_EraseProgram' example program for the Nucleo-F413ZH that comes with 'STM32Cube_FW_F4_V1.25.0' working on a Nucleo-F413ZH board.

It erases sectors 2 to 15 and fills them with data - i.e. 0x78563412 that shows up repeatedly as '12 34 56 78 12 34 56 78 12 34 56 78...' in all the sectors.

However, when I try to use 'HAL_FLASH_Program()' to add a single 32 bit number to the first 4 bytes of sector 15 (starting at address 0x08160000), it does not show up correctly. For example:

// Value Expecting Shows up in 
// to be added in memory memory as
0x00000000 00 00 00 00 00 00 00 00
0x00000001 01 00 00 00 00 00 00 00 
0x00000011 11 00 00 00 10 00 00 00
0x00000111 11 01 00 00 10 00 00 00
0x00001111 11 11 00 00 10 10 00 00
0x00011111 11 11 01 00 10 10 00 00
0x00111111 11 11 11 00 10 10 10 00
0x01111111 11 11 11 01 10 10 10 00
0x11111111 11 11 11 11 10 10 10 10
34 22 00 00 00 02 00 00 00

Considering that the padding works okay can anyone suggest what I'm doing incorrectly, please?

I'm using a Nucleo-F413ZH, MDK-ARM version 5, ARM version 5 and a ST-LINK V2 debugger.

The code (main.c and main.h) are attached.

Thanks.

Ron

    This topic has been closed for replies.

    3 replies

    Graduate II
    February 1, 2022

    You don't get multiple bites of the apple. You can write each flash line ONCE after ERASURE

    Graduate II
    February 1, 2022

    Or better is say you can only reprogram bits with HIGH state to zero, then after progr 0x78563412

    you can only AND with this value.example

    0x00011111 11 11 01 00 10 10 00 00
     12 34 56 78 & = 10 10 00 00

    ron_wAuthor
    Visitor II
    February 2, 2022

    Thanks, @MM..1​ . Good to know what is happening

    ron_wAuthor
    Visitor II
    February 2, 2022

    Thanks, @Community member​ . That makes everything clear