Browse Source

stm32: flash_unlock_option_bytes is common code.

The keys differ between some familes, but the documentation and
implementation are standard.
pull/942/merge
Karl Palsson 6 years ago
parent
commit
850931dbcd
  1. 6
      include/libopencm3/stm32/common/flash_common_all.h
  2. 4
      include/libopencm3/stm32/common/flash_common_f01.h
  3. 1
      include/libopencm3/stm32/common/flash_common_f24.h
  4. 1
      include/libopencm3/stm32/common/flash_common_l01.h
  5. 4
      include/libopencm3/stm32/f3/flash.h
  6. 1
      include/libopencm3/stm32/f7/flash.h
  7. 1
      include/libopencm3/stm32/l4/flash.h
  8. 6
      lib/stm32/common/flash_common_all.c
  9. 14
      lib/stm32/common/flash_common_f01.c
  10. 13
      lib/stm32/common/flash_common_f24.c
  11. 12
      lib/stm32/common/flash_common_l01.c
  12. 13
      lib/stm32/f7/flash.c
  13. 10
      lib/stm32/l4/flash.c

6
include/libopencm3/stm32/common/flash_common_all.h

@ -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

4
include/libopencm3/stm32/common/flash_common_f01.h

@ -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);

1
include/libopencm3/stm32/common/flash_common_f24.h

@ -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);

1
include/libopencm3/stm32/common/flash_common_l01.h

@ -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);

4
include/libopencm3/stm32/f3/flash.h

@ -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

1
include/libopencm3/stm32/f7/flash.h

@ -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);

1
include/libopencm3/stm32/l4/flash.h

@ -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);

6
lib/stm32/common/flash_common_all.c

@ -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;
}
/*@}*/

14
lib/stm32/common/flash_common_f01.c

@ -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

13
lib/stm32/common/flash_common_f24.c

@ -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

12
lib/stm32/common/flash_common_l01.c

@ -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;

13
lib/stm32/f7/flash.c

@ -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

10
lib/stm32/l4/flash.c

@ -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.

Loading…
Cancel
Save