Browse Source

stm32: flash: pull lock/unlock up to common_f.

This is a common operation, so definition in _all, and every part except
l0/l1 have the same implementation.  Bring in an _f file too.
pull/942/merge
Karl Palsson 6 years ago
parent
commit
da7ebafcbe
  1. 11
      include/libopencm3/stm32/common/flash_common_all.h
  2. 2
      include/libopencm3/stm32/common/flash_common_f01.h
  3. 2
      include/libopencm3/stm32/common/flash_common_f234.h
  4. 2
      include/libopencm3/stm32/common/flash_common_l01.h
  5. 2
      include/libopencm3/stm32/f7/flash.h
  6. 2
      include/libopencm3/stm32/l4/flash.h
  7. 41
      lib/stm32/common/flash_common_f.c
  8. 20
      lib/stm32/common/flash_common_f01.c
  9. 27
      lib/stm32/common/flash_common_f234.c
  10. 2
      lib/stm32/f0/Makefile
  11. 2
      lib/stm32/f1/Makefile
  12. 2
      lib/stm32/f2/Makefile
  13. 2
      lib/stm32/f3/Makefile
  14. 2
      lib/stm32/f4/Makefile
  15. 2
      lib/stm32/f7/Makefile
  16. 28
      lib/stm32/f7/flash.c
  17. 2
      lib/stm32/l4/Makefile
  18. 22
      lib/stm32/l4/flash.c

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

@ -45,4 +45,15 @@ void flash_prefetch_disable(void);
void flash_set_ws(uint32_t ws);
/** Lock the Flash Program and Erase Controller
* Used to prevent spurious writes to FLASH.
*/
void flash_lock(void);
/** Unlock the Flash Program and Erase Controller
* This enables write access to the Flash memory. It is locked by default on
* reset.
*/
void flash_unlock(void);
END_DECLS

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

@ -99,8 +99,6 @@
BEGIN_DECLS
void flash_unlock(void);
void flash_lock(void);
void flash_clear_pgerr_flag(void);
void flash_clear_eop_flag(void);
void flash_clear_wrprterr_flag(void);

2
include/libopencm3/stm32/common/flash_common_f234.h

@ -74,8 +74,6 @@
BEGIN_DECLS
void flash_unlock(void);
void flash_lock(void);
void flash_clear_pgperr_flag(void);
void flash_clear_eop_flag(void);
void flash_clear_status_flags(void);

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

@ -118,8 +118,6 @@ void flash_unlock_progmem(void);
void flash_lock_progmem(void);
void flash_unlock_option_bytes(void);
void flash_lock_option_bytes(void);
void flash_unlock(void);
void flash_lock(void);
void eeprom_program_word(uint32_t address, uint32_t data);
void eeprom_program_words(uint32_t address, uint32_t *data, int length_in_words);

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

@ -152,8 +152,6 @@
BEGIN_DECLS
void flash_unlock(void);
void flash_lock(void);
void flash_clear_pgperr_flag(void);
void flash_clear_eop_flag(void);
void flash_wait_for_last_operation(void);

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

@ -224,8 +224,6 @@
BEGIN_DECLS
void flash_unlock(void);
void flash_lock(void);
void flash_clear_pgperr_flag(void);
void flash_clear_eop_flag(void);
void flash_wait_for_last_operation(void);

41
lib/stm32/common/flash_common_f.c

@ -0,0 +1,41 @@
/** @addtogroup flash_file
*
*/
/*
* This file is part of the libopencm3 project.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/**@{*/
#include <libopencm3/stm32/flash.h>
void flash_unlock(void)
{
/* Clear the unlock state. */
FLASH_CR |= FLASH_CR_LOCK;
/* Authorize the FPEC access. */
FLASH_KEYR = FLASH_KEYR_KEY1;
FLASH_KEYR = FLASH_KEYR_KEY2;
}
void flash_lock(void)
{
FLASH_CR |= FLASH_CR_LOCK;
}

20
lib/stm32/common/flash_common_f01.c

@ -48,26 +48,6 @@ This enables write access to the Flash memory. It is locked by default on
reset.
*/
void flash_unlock(void)
{
/* Clear the unlock state. */
FLASH_CR |= FLASH_CR_LOCK;
/* Authorize the FPEC access. */
FLASH_KEYR = FLASH_KEYR_KEY1;
FLASH_KEYR = FLASH_KEYR_KEY2;
}
/*---------------------------------------------------------------------------*/
/** @brief Lock the Flash Program and Erase Controller
Used to prevent spurious writes to FLASH.
*/
void flash_lock(void)
{
FLASH_CR |= FLASH_CR_LOCK;
}
/*---------------------------------------------------------------------------*/
/** @brief Clear the Programming Error Status Flag

27
lib/stm32/common/flash_common_f234.c

@ -44,33 +44,6 @@ void flash_set_ws(uint32_t ws)
FLASH_ACR = reg32;
}
/*---------------------------------------------------------------------------*/
/** @brief Unlock the Flash Program and Erase Controller
This enables write access to the Flash memory. It is locked by default on
reset.
*/
void flash_unlock(void)
{
/* Clear the unlock sequence state. */
FLASH_CR |= FLASH_CR_LOCK;
/* Authorize the FPEC access. */
FLASH_KEYR = FLASH_KEYR_KEY1;
FLASH_KEYR = FLASH_KEYR_KEY2;
}
/*---------------------------------------------------------------------------*/
/** @brief Lock the Flash Program and Erase Controller
Used to prevent spurious writes to FLASH.
*/
void flash_lock(void)
{
FLASH_CR |= FLASH_CR_LOCK;
}
/*---------------------------------------------------------------------------*/
/** @brief Clear the Programming Error Status Flag

2
lib/stm32/f0/Makefile

@ -47,7 +47,7 @@ OBJS += gpio_common_all.o gpio_common_f0234.o crc_common_all.o crc_v2
OBJS += adc_common_v2.o
OBJS += crs_common_all.o
OBJS += flash_common_all.o flash_common_f01.o
OBJS += flash_common_all.o flash_common_f.o flash_common_f01.o
OBJS += usart_common_all.o usart_common_v2.o
OBJS += i2c_common_v2.o
OBJS += spi_common_all.o spi_common_v2.o

2
lib/stm32/f1/Makefile

@ -46,7 +46,7 @@ OBJS += crc_common_all.o dac_common_all.o dma_common_l1f013.o \
timer_common_all.o usart_common_all.o usart_common_f124.o \
rcc_common_all.o exti_common_all.o
OBJS += flash_common_all.o flash_common_f01.o
OBJS += flash_common_all.o flash_common_f.o flash_common_f01.o
OBJS += spi_common_all.o spi_common_v1.o
OBJS += usb.o usb_control.o usb_standard.o usb_msc.o

2
lib/stm32/f2/Makefile

@ -45,7 +45,7 @@ OBJS += crc_common_all.o dac_common_all.o dma_common_f24.o \
timer_common_f24.o usart_common_all.o usart_common_f124.o \
hash_common_f24.o \
crypto_common_f24.o exti_common_all.o rcc_common_all.o
OBJS += flash_common_all.o flash_common_f234.o flash_common_f24.o
OBJS += flash_common_all.o flash_common_f.o flash_common_f234.o flash_common_f24.o
OBJS += rng_common_v1.o
OBJS += spi_common_all.o spi_common_v1.o spi_common_v1_frf.o

2
lib/stm32/f3/Makefile

@ -45,7 +45,7 @@ OBJS += gpio_common_all.o gpio_common_f0234.o \
timer_common_all.o timer_common_f0234.o \
exti_common_all.o rcc_common_all.o
OBJS += adc_common_v2.o adc_common_v2_multi.o
OBJS += flash_common_all.o flash_common_f234.o
OBJS += flash_common_all.o flash_common_f.o flash_common_f234.o
OBJS += usart_common_v2.o usart_common_all.o
OBJS += i2c_common_v2.o
OBJS += spi_common_all.o spi_common_v2.o

2
lib/stm32/f4/Makefile

@ -50,7 +50,7 @@ OBJS += crc_common_all.o dac_common_all.o dma_common_f24.o \
usart_common_f124.o \
hash_common_f24.o crypto_common_f24.o exti_common_all.o \
rcc_common_all.o
OBJS += flash_common_all.o flash_common_f234.o flash_common_f24.o
OBJS += flash_common_all.o flash_common_f.o flash_common_f234.o flash_common_f24.o
OBJS += rng_common_v1.o
OBJS += spi_common_all.o spi_common_v1.o spi_common_v1_frf.o

2
lib/stm32/f7/Makefile

@ -42,7 +42,7 @@ TGT_CFLAGS += $(STANDARD_FLAGS)
ARFLAGS = rcs
OBJS = flash_common_all.o flash.o pwr.o rcc.o
OBJS = flash_common_all.o flash_common_f.o flash.o pwr.o rcc.o
OBJS += gpio.o gpio_common_all.o gpio_common_f0234.o
OBJS += rcc_common_all.o

28
lib/stm32/f7/flash.c

@ -84,34 +84,6 @@ void flash_set_ws(uint32_t ws)
while ((FLASH_ACR & FLASH_ACR_LATENCY_MASK) != ws);
}
/*---------------------------------------------------------------------------*/
/** @brief Unlock the Flash Program and Erase Controller
This enables write access to the Flash memory. It is locked by default on
reset.
*/
void flash_unlock(void)
{
/* Clear the unlock sequence state. */
FLASH_CR |= FLASH_CR_LOCK;
/* Authorize the FPEC access. */
FLASH_KEYR = FLASH_KEYR_KEY1;
FLASH_KEYR = FLASH_KEYR_KEY2;
}
/*---------------------------------------------------------------------------*/
/** @brief Lock the Flash Program and Erase Controller
Used to prevent spurious writes to FLASH.
*/
void flash_lock(void)
{
FLASH_CR |= FLASH_CR_LOCK;
}
/*---------------------------------------------------------------------------*/
/** @brief Clear the Programming Error Status Flag

2
lib/stm32/l4/Makefile

@ -47,7 +47,7 @@ OBJS += exti_common_all.o
OBJS += adc_common_v2.o adc_common_v2_multi.o
OBJS += crc_common_all.o crc_v2.o
OBJS += crs_common_all.o
OBJS += flash_common_all.o
OBJS += flash_common_all.o flash_common_f.o
OBJS += rng_common_v1.o
OBJS += timer_common_all.o
OBJS += i2c_common_v2.o

22
lib/stm32/l4/flash.c

@ -61,28 +61,6 @@ void flash_set_ws(uint32_t ws)
FLASH_ACR = reg32;
}
/** @brief Unlock the Flash Program and Erase Controller
* This enables write access to the Flash memory. It is locked by default on
* reset.
*/
void flash_unlock(void)
{
/* Clear the unlock sequence state. */
FLASH_CR |= FLASH_CR_LOCK;
/* Authorize the FPEC access. */
FLASH_KEYR = FLASH_KEYR_KEY1;
FLASH_KEYR = FLASH_KEYR_KEY2;
}
/** @brief Lock the Flash Program and Erase Controller
* Used to prevent spurious writes to FLASH.
*/
void flash_lock(void)
{
FLASH_CR |= FLASH_CR_LOCK;
}
/** @brief Clear the Programming Error Status Flag
*/
void flash_clear_pgperr_flag(void)

Loading…
Cancel
Save