title: I get an Error when setting PCROP STM32H7 (STM32H743)
body: <h2>Goal</h2>
  <p>I'm trying to set a PCROP area on my STM32H743VI microcontroller, but I'm getting the error code <em>HAL_FLASH_ERROR_OB_CHANGE</em> when executing <em>HAL_FLASH_OB_Launch()</em> and my PCROP area is not set.</p>
  <p>The relevant part of the code I'm using should be the following sections</p>
  <h2>My code</h2>
  <pre><code>    #include &quot;stm32h7xx_hal.h&quot;
  
      FLASH_OBProgramInitTypeDef OBInit;
      HAL_FLASHEx_OBGetConfig(&amp;OBInit);
  
      HAL_FLASH_Unlock();
      HAL_FLASH_OB_Unlock();
  
      // program OB
      OBInit.OptionType       = OPTIONBYTE_PCROP;
      OBInit.PCROPStartAddr   = 0x8030000;
      OBInit.PCROPEndAddr     = 0x8031000;
      OBInit.PCROPConfig      = OB_PCROP_RDP_ERASE;
      OBInit.Banks            = FLASH_BANK_1; // (1, 2 oder BOTH)
      HAL_FLASHEx_OBProgram(&amp;OBInit);
  
      /* write Option Bytes */
      if (HAL_FLASH_OB_Launch() != HAL_OK) {
          // Error handling
          while (1)
          {
          }
      }
  
      HAL_FLASH_OB_Lock();
      HAL_FLASH_Lock();
  </code></pre>
  <p>The code is mostly inspired by the youtube video &quot;Security Part3 - STM32 Security features - 07 - PCROP lab&quot; (by STMicroelectronics) and the working code I have to change RDP level.</p>
  <h2>Setup</h2>
  <p>My secret function is in the expected address range, I did that by adding the memory area in the Flash.Id File</p>
  <pre><code>MEMORY
  {
      [...]
      PCROP   (x)     : ORIGIN = 0x08030000,  LENGTH = 16K
  }
  </code></pre>
  <p>and putting the function file into the section accordingly</p>
  <pre><code>SECTIONS
  {
      [...]
      .PCROPed :
      {
          . = ALIGN(4);
          *led_blinking.o (.text .text*)
          . = ALIGN(4);
      } &gt; PCROP
      [...]
  }
  </code></pre>
  <p>I set the flag <em>-mslow-flash-data</em> for the file I'm keeping my secret function in. I did this without really understanding why, following the tutorial in the video (see above).</p>
  <h2>What I tried</h2>
  <p>I debugged my program with my J-Trace Debugger and it seems like I'm doing the <em>Option byte modification sequence</em> described in the STM32H743/753 reference manual (p. 159) succesfully.</p>
  <p>Securing an entire Flashpage (start 0x080020000, end 0x0803FFFF) didn't work either, even though I did not expect it to make a difference.</p>
  <p>I also tried the other option for PCROPConfig, namely the OB_PCROP_RDP_NOT_ERASE option.</p>
  <p><em>HAL_FLASHEx_OBProgram(&amp;OBInit)</em> works as intended and the ObInit Configuration is set correctly into the _FLASH-&gt;<em>PRAR_PRG1</em> register. For my code the content of the register is 0x80880080</p>
  <p>I did disconnect and reconnect the microcontroller from power and debugger in case I did not POR correctly.</p>
  <p>I checked the errata sheet, but there is no errata which would be applicable to my problem.</p>
  <h2>EDIT</h2>
  <p>I changed the area which is protected by PCROP in the <em>My code</em> section.
  I did this, since my code is generally functional and I found out it's not a good idea to protect an area in the first flash page!</p>