cancel
Showing results for 
Search instead for 
Did you mean: 

No Errorflag when writting to Write-Protected Sector

andi z
Associate II
Posted on June 14, 2017 at 14:46

Hi,

I'm evaluating some flash functionalities of the STM32F469NI. I have configured the Sector 12 of my STM32F469 Flash (2MB) with a Write-Protection. When I debug my Firmware I see that the corresponding bit gets set in the FLASH_OPTCR1 Register.

I also run a test when I initialize my Flash Driver which only writes a word (32bit) into the beginning of Sector 12 (0x08100000). Now there should be an error in the SR of the Flash Module. But I don't see anything here.

So I tried to rise an other error and wrote a half word into a word-configured Data Register. Now I got an Error.

But why do I not get any error when writting into a Write-Protected area? Did I misconfigure something? I don't see anything else in the UserManual.

Here is my code

enReturn_t HAL_UserFlash::setWriteProtection(void)
{
enReturn_t errorCode = RET_ERROR;
HAL_StatusTypeDef status = HAL_OK;
//FLASH_OBProgramInitTypeDef flashInit;
kprintf(0,'%s...\n',__FUNCTION__);
/*Unlock Option Bytes*/
status = HAL_FLASH_OB_Unlock();
if(status == HAL_ERROR)
return RET_ERROR;
/*write option bytes and set errorCode RET_OK */
status = HAL_FLASHEx_OBProgram(&(FLASH_OBProgramInitTypeDef)flashConfig);
if(status == HAL_OK)
errorCode = RET_OK;
/*Lock Option Bytes again*/
status = HAL_FLASH_OB_Lock();
if(status == HAL_ERROR)
return RET_ERROR;

return errorCode;
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

my flashConfig Variable:

static const FLASH_OBProgramInitTypeDef flashConfig = {
OPTIONBYTE_WRP,
OB_WRPSTATE_ENABLE,
WP_FLASH_SECTOR, //<-- this is set to OB_WRP_SECTOR_12
FLASH_BANK_2
};�?�?�?�?�?�?�?�?�?�?�?�?

I use the STM32F4 Cube Lib in Version 1.14

Is there anything I have to activated also?

PS.: I don't need a Read-out Protection now. I just need to make sure that writes on protected areas are now allowed.

Kind regards

Andreas

1 ACCEPTED SOLUTION

Accepted Solutions
andi z
Associate II
Posted on June 20, 2017 at 11:32

Hi,

Problem solved.

I had to set the OPTSTART Bit in the FLASH_OPT Regsiter. This triggers a write of the Option Bits.

This was a little bit confusing in the Reference Manual Rev.13 as it had only been mentioned at 'Modify Option Bytes' (Ch 3.4.2). The description of this Bit in the Register Description refers only on the User Byte Options.

Kind regards

Andreas

View solution in original post

2 REPLIES 2
andi z
Associate II
Posted on June 20, 2017 at 08:28

Hi again,

does anyone have an idea how to set the Write-Protection to get Error Flags when writing on the sector?

Kind regards

Andreas

andi z
Associate II
Posted on June 20, 2017 at 11:32

Hi,

Problem solved.

I had to set the OPTSTART Bit in the FLASH_OPT Regsiter. This triggers a write of the Option Bits.

This was a little bit confusing in the Reference Manual Rev.13 as it had only been mentioned at 'Modify Option Bytes' (Ch 3.4.2). The description of this Bit in the Register Description refers only on the User Byte Options.

Kind regards

Andreas