AnsweredAssumed Answered

STM32L152 read memory protection - cannot flash anymore

Question asked by charpentier.ludovic on Dec 10, 2015
Hello

I have a nucleol152 board. As I need to protect a memory area, I used this function to make a read protection + a write protection on zone specific areas:

  __IO uint32_t WPR_Value = 0x0, WriteProtectedPages = 0x0;

  FLASH_Unlock();

  /* Unlock the Option Bytes */
  FLASH_OB_Unlock();
 
  /*Set read protection to 1*/
  FLASH_OB_RDPConfig(OB_RDP_Level_1);

 
  /* Get pages write protection status */
  WPR_Value = FLASH_OB_GetWRP();


 
  /* Get current write protected pages and the new pages to be protected/unprotected */
  WriteProtectedPages = (WPR_Value & FLASH_PAGES_TO_BE_WRITE_PROTECTED);
 
  /* Check if desired pages are not yet write protected */
  if(WriteProtectedPages != FLASH_PAGES_TO_BE_WRITE_PROTECTED)
  {
    /* Enable the pages read/write protection */
    FLASH_OB_WRPConfig(FLASH_PAGES_TO_BE_WRITE_PROTECTED, DISABLE);
 
    /* Generate System Reset to load the new option byte values */
    FLASH_OB_Launch();
  }
 
  /* Lock the Option Bytes */
  FLASH_OB_Lock();


When I try to reflash my board using the stlink, I have a fail. I understand it fails as memory is protected.

I tried several things to unblock the memory:

I use GDB to write the following sequence

unlock flash
(gdb) set {int}0x40023C10 = 0x8C9DAEBF
(gdb) set {int}0x40023C10 = 0x13141516
unlock OB
(gdb) set {int}0x40023C14 = 0xFBEAD9C8
(gdb) set {int}0x40023C14 = 0x24252627

switch to RDP level 0
(gdb) set {int}0x1FF80000 = 0x000000AA

This last operation always fails and GDB returns that it cannot access to this memory area.

I tried to push this sequence into a RAM program but it still has no effect (unless the code I downloaded is not working well).

I saw this type of topic and I was wondering if it was the only solution to unblock my memory.
http://www.mobilewill.us/2015/06/stm32-nucleo-and-dfu-usb-bootloading.html

Could you tell me how I should proceed to unblock the memory?

Thanks for your support







Outcomes