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.
Solved! Go to Solution.
2025-10-07 7:13 PM
I accept your answer, but I still believe that the sole purpose of SDK is to help developers quickly build applications, but a textbook. The HAL architecture is becoming bloated, and difficult to understand.
2025-10-06 12:59 PM
> HAL_StatusTypeDef HAL_SLASHEx_OBProgram (FLASH-OBProgramInitTypeDef * pOBInit)
This isn't a HAL function, nor an argument type. This won't even compile.
There is no need for a HAL structure to store the complement to the RDP value in addition to the RDP value. This is not a bug.
If you show the actual code being used and the issue can be replicated, it may be looked at and fixed.
2025-10-07 7:13 PM
I accept your answer, but I still believe that the sole purpose of SDK is to help developers quickly build applications, but a textbook. The HAL architecture is becoming bloated, and difficult to understand.