2025-10-06 9:37 AM
Chip Model: STM32F030RBT6
HAL Version: HAL Package "FW.F0.1.11.0", Patch="FW.F0.1.11.5"
Symptom: After writing Data0 and Data1 to the Option Bytes (OB), debugging becomes unavailable. When checked with a programming tool, the protection level of the OB field changes to "BB". The system returns to normal after rewriting the protection level to "AA".
Analysis:
HAL API Function:
HAL_StatusTypeDef HAL_SLASHEx_OBProgram (FLASH-OBProgramInitTypeDef * pOBInit)
The parameters, uint8_t RDPLevel; There is no complement.
and then, another function was called to rewrite configuration:
FLASH-OB_RDP_LevelConfig (pOBInit ->RDPLevel);
The register written here is only an 8-bit protection mode parameter whitout complement code.
During option byte loading, the bit-wise complementarity of the option byte and its corresponding complemented option byte is verified. In case of failure, an option byte error (OPTERR) is generated and the corresponding option byte is considered as 0xFF. So the RDP will bacame to Level 1 (0xFF, except 0xAA & 0xCC ).
Abandon the HAL API option byte operation function and rewrite the function with LL API.
The program runs normally after rewriting.