Commit 32d3063c authored by Bruno FLEURETTE's avatar Bruno FLEURETTE Committed by Spencer Oliver
Browse files

flash: pre-check flash unlock for stm32f2x

add checking of the current flash lock status before performing the unlock sequence (which would fail in an unlocked state)

Change-Id: I693294c9cd2f59e69cb5bf3338120052fd680b1e
Signed-off-by: default avatarBruno FLEURETTE <>
Signed-off-by: default avatarØyvind Harboe <>

Reviewed-by: default avatarØyvind Harboe <>
Reviewed-by: default avatarSpencer Oliver <>
Tested-by: jenkins
Reviewed-by: default avatarMathias Küster <>
parent 06d1580f
......@@ -234,8 +234,18 @@ static int stm32x_unlock_reg(struct target *target)
uint32_t ctrl;
/* first check if not already unlocked
* otherwise writing on STM32_FLASH_KEYR will fail
int retval = target_read_u32(target, STM32_FLASH_CR, &ctrl);
if (retval != ERROR_OK)
return retval;
if ((ctrl & FLASH_LOCK) == 0)
return ERROR_OK;
/* unlock flash registers */
int retval = target_write_u32(target, STM32_FLASH_KEYR, KEY1);
retval = target_write_u32(target, STM32_FLASH_KEYR, KEY1);
if (retval != ERROR_OK)
return retval;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment