cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F030 OPTION BYTE programming failed, HAL API error.

shiweinian
Visitor

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.

  1. Unlock FLASH, OBFLASH
    2. Read all fields of OB, totaling 10 bytes.
    3. Erase the OB area.
    4. Assign new value to the OB data with its complement.
    5. Write back all OB data to FLASH
    6. Lock OB FLASH, lock FLASH
    7. Set the OBL_Launch bit to launch the option byte loading

The program runs normally after rewriting.

0 REPLIES 0