cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H730VBT6 write user settings in FLASH

Baxtouxe
Associate II

I couldn’t figure out how to write a simple code to write some bytes at the end of the Flash on my STM32H7. I don’t need much bytes, only one uint32_t.

I tried using HAL_FLASH_Program by unlocking the flash first but couldn’t make it work..

Any help?

 

17 REPLIES 17

The STM32H735x would be the closest proxy, but any of them where you limit yourself to the one sector would suffice.

The Value Line parts share the same die as others but less of the Flash is tested to save time on the test equipment and improve throughput. 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Would Option Bytes by a solution to my problem?

Pavel A.
Evangelist III

Would Option Bytes by a solution to my problem?

Option Bytes - not at all. A similar topic was here recently, about some other STM32. A short summary: unless the firmware install procedure has filled the whole flash page, you can find properly aligned empty space past the firmware image and write your data there. Properly aligned here means on 32 bytes boundary.  Write also in multiples of 32 bytes (256 bits). 

Also, as Tesla DeLorean noted, "value line" STM32H7 can actually have more than one flash page, but its up to you to find them and verify they are working. YMMV.

Writing at the end of the firmware sounds like a great idea.

Do I need to erase the bytes first? Or is it a simple as :


uint32_t data[8] = { 0x123456778,
0x123456778,
0x123456778,
0x123456778,
0x123456778,
0x123456778,
0x123456778,
0x123456778,
};
void writeUserSettings(uint32_t* data, uint32_t address)
{
HAL_FLASH_Unlock();
HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, address, data);
HAL_FLASH_Lock();
}

Pavel A.
Evangelist III

As simple as. Locate an empty place and write.

Can you be more specific? I know the address where I want to write but don’t know how to

Pavel A.
Evangelist III

Yes. Unlock, then write. Then lock (optionally). 

The memory must be in an erased state, and then you get one-shot writing it. Perhaps check content first?

When you write/download your test app in the debugger it's going to erase the memory within the whole 128KB sector. You don't need to erase it again, as this will also erase your application, but you'll get one chance to write each block of 32-bytes. You can walk forward, or backward, within memory and write those slots.

https://github.com/STMicroelectronics/STM32CubeH7/blob/master/Projects/NUCLEO-H723ZG/Examples/FLASH/FLASH_EraseProgram/Src/main.c#L131

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..