cancel
Showing results for 
Search instead for 
Did you mean: 

Updating password stored on MCU flash

A Maq
Senior

Hi All,

I have a situation where I would like to allow STM32H7 based embedded web server users to update the password which is originally hardcoded in the code using const keyword. Which effectively means password is placed in internal flash memory of the microcontroller.

I can remove const but question is that:

Is there any way to update password run time which is available on next power cycle without using anything external to STM32H7 microcontroller?

I​ am using STM32H747 MCU and IAR embedded workbench environment for development. Currently using the Nucleo board.

The application is a embedded web server while browser is the client where user logs in to the device to change settings etc. ​.

I did come across some articles which did say it is possible to update password stored on flash of MCU’S but didn't give much detail about how to do it in a way once device switched off and back ON the updated password is still available or next login will require new password.

Thanks in advance

Regards

A Maq​

1 ACCEPTED SOLUTION

Accepted Solutions

> Is there any way to update password run time which is available on next power cycle without using anything external to STM32H7 microcontroller?

​You'd need to program it into FLASH, read the FLASH chapter in RM. As long as the number of password reprogramming can be limited, you can simply reserve some space for them in FLASH (taking into account the programming granularity); otherwise you would need also to erase a sector, with all its problems (it takes relatively long time, sectors are large).

If you have a backup battery connected to VBAT, you can conveniently store the password in the backup SRAM.

JW

View solution in original post

3 REPLIES 3

> Is there any way to update password run time which is available on next power cycle without using anything external to STM32H7 microcontroller?

​You'd need to program it into FLASH, read the FLASH chapter in RM. As long as the number of password reprogramming can be limited, you can simply reserve some space for them in FLASH (taking into account the programming granularity); otherwise you would need also to erase a sector, with all its problems (it takes relatively long time, sectors are large).

If you have a backup battery connected to VBAT, you can conveniently store the password in the backup SRAM.

JW

KnarfB
Principal III

There is a HAL flash API for accessing the flash. Note that writing a new value implies an erase plus a program operation which work on larger chunks of flash memory, not individual variables. Typically, one sets aside few pages of flash memory for such a purpose and works with raw memory adresses, compiler/linker pragmas etc.. There is also an EEPROM emulation library which might be helpful.

hth

KnarfB

Thanks for response. Can you please share any example code which describes how to do it?​