STM32H7Sx - read OBK without FLASH_OPTCR_PG_OPT
In my application on an STM32H7S3 I’ll have to often read option byte keys, and I want to limit the possibility of accidentally writing to option byte keys.
According to the reference manual, that’s where the PG_OPT bit of FLASH_OPTCR comes in:
PG_OPT: Program options
0: Update operations to user option bytes and option byte keys do not start
1: Write operation to user option bytes and option byte keys is enabled
Perfect, so I just need to be sure this bit is not set when I don’t want writes.
To double check this bit is not needed to be set during the configuration of FLASH_OBKCR to initiate read operations, the description of the KEYPROG bit - when set to 0 - seems to hint the PG_OPT bit doesn’t need to be set according to the reference manual:
KEYPROG: Key program
This bit must be set to write option byte keys (keys are read otherwise).
0: Read key. Result of the operation is stored in FLASH_OBKDRx registers, if applicable.
1: Program key if PG_OPT is set in FLASH_OPTCR register, and KDREF flag is cleared in
FLASH_OPTISR register. Correct key information must be stored in FLASH_OBKDRx
register before setting PROG and START bits.
So then my first question is, why does HAL_FLASHEx_GetKey() set the FLASH_OPTCR_PG_OPT bit?
/* Set PG_OPT Bit */
SET_BIT(FLASH->OPTCR, FLASH_OPTCR_PG_OPT);When I uncomment that line, configuring FLASH_OBKCR is ineffective - even when I make sure the OPTLOCK bit of FLASH_OPTCR reads as 0.
Note that OB (instead of OBK) alternative of HAL_FLASHEx_GetKey(), named HAL_FLASHEx_OBGetConfig(), doesn’t set the OPTLOCK bit. So the OB version seems to be according to the reference manual, but the OKB version doesn’t seem to be and hence is also inconsistent with the OB version.
Is this a hardware bug?
