stm32: flash_unlock_option_bytes is common code.

The keys differ between some familes, but the documentation and
implementation are standard.
This commit is contained in:
Karl Palsson 2018-07-22 21:31:00 +00:00
parent c5a3350a7d
commit 850931dbcd
13 changed files with 18 additions and 68 deletions

View File

@ -65,4 +65,10 @@ void flash_lock(void);
*/
void flash_unlock(void);
/** Unlock the Option Byte Access.
* This enables write access to the option bytes. It is locked by default on
* reset.
*/
void flash_unlock_option_bytes(void);
END_DECLS

View File

@ -95,6 +95,9 @@
#define FLASH_KEYR_KEY1 ((uint32_t)0x45670123)
#define FLASH_KEYR_KEY2 ((uint32_t)0xcdef89ab)
#define FLASH_OPTKEYR_KEY1 FLASH_KEYR_KEY1
#define FLASH_OPTKEYR_KEY2 FLASH_KEYR_KEY2
/* --- Function prototypes ------------------------------------------------- */
BEGIN_DECLS
@ -108,7 +111,6 @@ void flash_program_word(uint32_t address, uint32_t data);
void flash_program_half_word(uint32_t address, uint16_t data);
void flash_erase_page(uint32_t page_address);
void flash_erase_all_pages(void);
void flash_unlock_option_bytes(void);
void flash_erase_option_bytes(void);
void flash_program_option_bytes(uint32_t address, uint16_t data);

View File

@ -112,7 +112,6 @@
BEGIN_DECLS
void flash_unlock_option_bytes(void);
void flash_lock_option_bytes(void);
void flash_clear_pgserr_flag(void);
void flash_clear_wrperr_flag(void);

View File

@ -118,7 +118,6 @@ void flash_unlock_pecr(void);
void flash_lock_pecr(void);
void flash_unlock_progmem(void);
void flash_lock_progmem(void);
void flash_unlock_option_bytes(void);
void flash_lock_option_bytes(void);
void eeprom_program_word(uint32_t address, uint32_t data);

View File

@ -72,6 +72,10 @@
#define FLASH_CR_PER (1 << 1)
#define FLASH_CR_PG (1 << 0)
/* F3 uses the same keys for option bytes */
#define FLASH_OPTKEYR_KEY1 FLASH_KEYR_KEY1
#define FLASH_OPTKEYR_KEY2 FLASH_KEYR_KEY2
BEGIN_DECLS

View File

@ -157,7 +157,6 @@ BEGIN_DECLS
void flash_clear_pgperr_flag(void);
void flash_wait_for_last_operation(void);
void flash_unlock_option_bytes(void);
void flash_lock_option_bytes(void);
void flash_clear_erserr_flag(void);
void flash_clear_wrperr_flag(void);

View File

@ -228,7 +228,6 @@ void flash_clear_pgserr_flag(void);
void flash_clear_pgaerr_flag(void);
void flash_clear_wrperr_flag(void);
void flash_clear_status_flags(void);
void flash_unlock_option_bytes(void);
void flash_lock_option_bytes(void);
void flash_program_word(uint32_t address, uint32_t data);
void flash_program(uint32_t address, uint8_t *data, uint32_t len);

View File

@ -43,6 +43,10 @@ void flash_set_ws(uint32_t ws)
FLASH_ACR = reg32;
}
void flash_unlock_option_bytes(void)
{
FLASH_OPTKEYR = FLASH_OPTKEYR_KEY1;
FLASH_OPTKEYR = FLASH_OPTKEYR_KEY2;
}
/*@}*/

View File

@ -85,20 +85,6 @@ void flash_program_word(uint32_t address, uint32_t data)
flash_program_half_word(address+2, (uint16_t)(data>>16));
}
/*---------------------------------------------------------------------------*/
/** @brief Unlock the Option Byte Access
This enables write access to the option bytes. It is locked by default on
reset.
*/
void flash_unlock_option_bytes(void)
{
/* F1 uses same keys for flash and option */
FLASH_OPTKEYR = FLASH_KEYR_KEY1;
FLASH_OPTKEYR = FLASH_KEYR_KEY2;
}
/*---------------------------------------------------------------------------*/
/** @brief Erase All Option Bytes

View File

@ -87,19 +87,6 @@ void flash_clear_status_flags(void)
flash_clear_eop_flag();
}
/*---------------------------------------------------------------------------*/
/** @brief Unlock the Option Byte Access
This enables write access to the option bytes. It is locked by default on
reset.
*/
void flash_unlock_option_bytes(void)
{
FLASH_OPTKEYR = FLASH_OPTKEYR_KEY1;
FLASH_OPTKEYR = FLASH_OPTKEYR_KEY2;
}
/*---------------------------------------------------------------------------*/
/** @brief Lock the Option Byte Access

View File

@ -64,18 +64,6 @@ void flash_lock_progmem(void)
FLASH_PECR |= FLASH_PECR_PRGLOCK;
}
/**
* Unlock option bytes.
* Writes the magic sequence to unlock the option bytes,
* you must have already unlocked access to this register!
* @sa flash_unlock_pecr
*/
void flash_unlock_option_bytes(void)
{
FLASH_OPTKEYR = FLASH_OPTKEYR_KEY1;
FLASH_OPTKEYR = FLASH_OPTKEYR_KEY2;
}
void flash_lock_option_bytes(void)
{
FLASH_PECR |= FLASH_PECR_OPTLOCK;

View File

@ -82,19 +82,6 @@ void flash_wait_for_last_operation(void)
while ((FLASH_SR & FLASH_SR_BSY) == FLASH_SR_BSY);
}
/*---------------------------------------------------------------------------*/
/** @brief Unlock the Option Byte Access
This enables write access to the option bytes. It is locked by default on
reset.
*/
void flash_unlock_option_bytes(void)
{
FLASH_OPTKEYR = FLASH_OPTKEYR_KEY1;
FLASH_OPTKEYR = FLASH_OPTKEYR_KEY2;
}
/*---------------------------------------------------------------------------*/
/** @brief Lock the Option Byte Access

View File

@ -92,16 +92,6 @@ void flash_clear_status_flags(void)
flash_clear_eop_flag();
}
/** @brief Unlock the Option Byte Access
* This enables write access to the option bytes. It is locked by default on
* reset.
*/
void flash_unlock_option_bytes(void)
{
FLASH_OPTKEYR = FLASH_OPTKEYR_KEY1;
FLASH_OPTKEYR = FLASH_OPTKEYR_KEY2;
}
/** @brief Lock the Option Byte Access
* This disables write access to the option bytes. It is locked by default on
* reset.