STMicroelectronics / STM32CubeF3

STM32Cube MCU Full Package for the STM32F3 series - (HAL + LL Drivers, CMSIS Core, CMSIS Device, MW libraries plus a set of Projects running on all boards provided by ST (Nucleo, Evaluation and Discovery Kits))
Other
140 stars 55 forks source link

FLASH_OB_DisableWRP() disables write protection of all pages #21

Closed P5pDev closed 12 months ago

P5pDev commented 1 year ago

Problem in https://github.com/STMicroelectronics/STM32CubeF3/blob/master/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_flash_ex.c

Describe the set-up

Describe the bug Because of calling HAL_FLASHEx_OBErase() https://github.com/STMicroelectronics/STM32CubeF3/blob/e805a235c431db2e01cea47d795fa83d597c64af/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_flash_ex.c#L679 the FLASH_OBR register is reset and because of that the OB->WRPx contains 0xffff

This means that the following instructions https://github.com/STMicroelectronics/STM32CubeF3/blob/e805a235c431db2e01cea47d795fa83d597c64af/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_flash_ex.c#L687 https://github.com/STMicroelectronics/STM32CubeF3/blob/e805a235c431db2e01cea47d795fa83d597c64af/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_flash_ex.c#L697 https://github.com/STMicroelectronics/STM32CubeF3/blob/e805a235c431db2e01cea47d795fa83d597c64af/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_flash_ex.c#L707 https://github.com/STMicroelectronics/STM32CubeF3/blob/e805a235c431db2e01cea47d795fa83d597c64af/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_flash_ex.c#L717 will always write 0xffff to the registers.

In my opinion, the solution would be OB->WRPx &= WRPx_Data instead, because the WriteProtectPage was already initialized correctly : https://github.com/STMicroelectronics/STM32CubeF3/blob/e805a235c431db2e01cea47d795fa83d597c64af/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_flash_ex.c#L649

Please compare FLASH_OB_EnableWRP(): https://github.com/STMicroelectronics/STM32CubeF3/blob/e805a235c431db2e01cea47d795fa83d597c64af/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_flash_ex.c#L519

RJMSTM commented 1 year ago

Hi @P5pDev ,

Thank you for this report. We will get back to you as soon as we analyze it further. This may take some time. Thank you for your comprehension.

With regards,

TOUNSTM commented 1 year ago

ST Internal Reference: 149343

ALABSTM commented 12 months ago

Fixed in commit 121e4039445ba59f284ebff013d8b3782d503e9f