1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

trezorhal: add flash_set_option_bytes function

This commit is contained in:
Pavol Rusnak 2017-03-13 18:55:06 +01:00
parent ab1888fe15
commit 715d25a93b
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 36 additions and 0 deletions

View File

@ -21,3 +21,37 @@ void FLASH_IRQHandler(void) {
// This call the storage IRQ handler, to check if the flash cache needs flushing
// storage_irq_handler();
}
#define WANTED_WRP (OB_WRP_SECTOR_0 | OB_WRP_SECTOR_1)
#define WANTED_RDP (OB_RDP_LEVEL_2)
#define WANTED_BOR (OB_BOR_LEVEL3)
void flash_set_option_bytes(void)
{
FLASH_OBProgramInitTypeDef opts;
HAL_FLASHEx_OBGetConfig(&opts);
opts.OptionType = 0;
if (opts.WRPSector != WANTED_WRP) {
opts.OptionType = OPTIONBYTE_WRP;
opts.WRPState = OB_WRPSTATE_ENABLE;
opts.WRPSector = WANTED_WRP;
opts.Banks = FLASH_BANK_1;
}
if (opts.RDPLevel != WANTED_RDP) {
opts.OptionType = OPTIONBYTE_RDP;
opts.RDPLevel = WANTED_RDP;
}
if (opts.BORLevel != WANTED_BOR) {
opts.OptionType = OPTIONBYTE_BOR;
opts.BORLevel = WANTED_BOR;
}
if (opts.OptionType != 0) {
HAL_FLASHEx_OBProgram(&opts);
}
}

View File

@ -3,4 +3,6 @@
int flash_init(void);
void flash_set_option_bytes(void);
#endif