From 4840b6bc7e98944bbd4647db99a6c9416f7de999 Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Fri, 13 Jul 2018 21:04:28 +0000 Subject: [PATCH] stm32: flash: pull up clear_eop All the "f" type flash parts have an EOP flag, even if it's in different bit positions. Add a header for this common functionality, and move it's implementation to the existing common file. --- .../libopencm3/stm32/common/flash_common_f.h | 32 +++++++++++++++++++ .../stm32/common/flash_common_f01.h | 1 - .../stm32/common/flash_common_f234.h | 1 - include/libopencm3/stm32/f0/flash.h | 1 + include/libopencm3/stm32/f1/flash.h | 1 + include/libopencm3/stm32/f2/flash.h | 1 + include/libopencm3/stm32/f3/flash.h | 1 + include/libopencm3/stm32/f4/flash.h | 1 + include/libopencm3/stm32/f7/flash.h | 2 +- include/libopencm3/stm32/l4/flash.h | 2 +- lib/stm32/common/flash_common_f.c | 7 ++++ lib/stm32/common/flash_common_f01.c | 10 ------ lib/stm32/common/flash_common_f234.c | 11 ------- lib/stm32/f7/flash.c | 10 ------ lib/stm32/l4/flash.c | 7 ---- 15 files changed, 46 insertions(+), 42 deletions(-) create mode 100644 include/libopencm3/stm32/common/flash_common_f.h diff --git a/include/libopencm3/stm32/common/flash_common_f.h b/include/libopencm3/stm32/common/flash_common_f.h new file mode 100644 index 00000000..6a52e60c --- /dev/null +++ b/include/libopencm3/stm32/common/flash_common_f.h @@ -0,0 +1,32 @@ +/** @addtogroup flash_defines + * + */ +/* + * 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 . + */ + +#pragma once + +#include + +BEGIN_DECLS + +/** + * Clear the End of OPeration flag. + */ +void flash_clear_eop_flag(void); + +END_DECLS \ No newline at end of file diff --git a/include/libopencm3/stm32/common/flash_common_f01.h b/include/libopencm3/stm32/common/flash_common_f01.h index 70410f6d..33b02edd 100644 --- a/include/libopencm3/stm32/common/flash_common_f01.h +++ b/include/libopencm3/stm32/common/flash_common_f01.h @@ -100,7 +100,6 @@ BEGIN_DECLS void flash_clear_pgerr_flag(void); -void flash_clear_eop_flag(void); void flash_clear_wrprterr_flag(void); void flash_clear_status_flags(void); uint32_t flash_get_status_flags(void); diff --git a/include/libopencm3/stm32/common/flash_common_f234.h b/include/libopencm3/stm32/common/flash_common_f234.h index 1c52c5bf..0842607b 100644 --- a/include/libopencm3/stm32/common/flash_common_f234.h +++ b/include/libopencm3/stm32/common/flash_common_f234.h @@ -75,7 +75,6 @@ BEGIN_DECLS void flash_clear_pgperr_flag(void); -void flash_clear_eop_flag(void); void flash_clear_status_flags(void); void flash_wait_for_last_operation(void); diff --git a/include/libopencm3/stm32/f0/flash.h b/include/libopencm3/stm32/f0/flash.h index 24ef2809..818e5f2c 100644 --- a/include/libopencm3/stm32/f0/flash.h +++ b/include/libopencm3/stm32/f0/flash.h @@ -37,6 +37,7 @@ /**@{*/ #include +#include #include /* --- FLASH_OPTION values ------------------------------------------------- */ diff --git a/include/libopencm3/stm32/f1/flash.h b/include/libopencm3/stm32/f1/flash.h index 937c83f3..d14df2ba 100644 --- a/include/libopencm3/stm32/f1/flash.h +++ b/include/libopencm3/stm32/f1/flash.h @@ -44,6 +44,7 @@ /**@{*/ #include +#include #include /* --- FLASH_OPTION bytes ------------------------------------------------- */ diff --git a/include/libopencm3/stm32/f2/flash.h b/include/libopencm3/stm32/f2/flash.h index e5b43080..d7d0e046 100644 --- a/include/libopencm3/stm32/f2/flash.h +++ b/include/libopencm3/stm32/f2/flash.h @@ -32,6 +32,7 @@ #define LIBOPENCM3_FLASH_H #include +#include #include #endif diff --git a/include/libopencm3/stm32/f3/flash.h b/include/libopencm3/stm32/f3/flash.h index eaaec2d5..f4024c50 100644 --- a/include/libopencm3/stm32/f3/flash.h +++ b/include/libopencm3/stm32/f3/flash.h @@ -33,6 +33,7 @@ /**@{*/ #include +#include #include /* --- FLASH registers ----------------------------------------------------- */ diff --git a/include/libopencm3/stm32/f4/flash.h b/include/libopencm3/stm32/f4/flash.h index 383cbe8c..5a5d7761 100644 --- a/include/libopencm3/stm32/f4/flash.h +++ b/include/libopencm3/stm32/f4/flash.h @@ -32,6 +32,7 @@ #define LIBOPENCM3_FLASH_H #include +#include #include #endif diff --git a/include/libopencm3/stm32/f7/flash.h b/include/libopencm3/stm32/f7/flash.h index befd63d6..ef3d141b 100644 --- a/include/libopencm3/stm32/f7/flash.h +++ b/include/libopencm3/stm32/f7/flash.h @@ -33,6 +33,7 @@ */ #include +#include /* * For details see: * PM0081 Programming manual: STM32F40xxx and STM32F41xxx Flash programming @@ -153,7 +154,6 @@ BEGIN_DECLS void flash_clear_pgperr_flag(void); -void flash_clear_eop_flag(void); void flash_wait_for_last_operation(void); void flash_unlock_option_bytes(void); diff --git a/include/libopencm3/stm32/l4/flash.h b/include/libopencm3/stm32/l4/flash.h index 90286058..88332a2f 100644 --- a/include/libopencm3/stm32/l4/flash.h +++ b/include/libopencm3/stm32/l4/flash.h @@ -42,6 +42,7 @@ #define LIBOPENCM3_FLASH_H #include +#include /* --- FLASH registers ----------------------------------------------------- */ @@ -225,7 +226,6 @@ BEGIN_DECLS void flash_clear_pgperr_flag(void); -void flash_clear_eop_flag(void); void flash_wait_for_last_operation(void); void flash_dcache_enable(void); void flash_dcache_disable(void); diff --git a/lib/stm32/common/flash_common_f.c b/lib/stm32/common/flash_common_f.c index b6f0ce50..d0a2188a 100644 --- a/lib/stm32/common/flash_common_f.c +++ b/lib/stm32/common/flash_common_f.c @@ -22,6 +22,7 @@ /**@{*/ #include +#include void flash_unlock(void) @@ -39,3 +40,9 @@ void flash_lock(void) FLASH_CR |= FLASH_CR_LOCK; } +/* The bit number for EOP moves sometimes, but it's always a write 1 to clear */ +void flash_clear_eop_flag(void) +{ + FLASH_SR |= FLASH_SR_EOP; +} + diff --git a/lib/stm32/common/flash_common_f01.c b/lib/stm32/common/flash_common_f01.c index 2d8917cc..fe1c1709 100644 --- a/lib/stm32/common/flash_common_f01.c +++ b/lib/stm32/common/flash_common_f01.c @@ -59,16 +59,6 @@ void flash_clear_pgerr_flag(void) FLASH_SR |= FLASH_SR_PGERR; } -/*---------------------------------------------------------------------------*/ -/** @brief Clear the End of Operation Status Flag - -*/ - -void flash_clear_eop_flag(void) -{ - FLASH_SR |= FLASH_SR_EOP; -} - /*---------------------------------------------------------------------------*/ /** @brief Clear the Write Protect Error Status Flag diff --git a/lib/stm32/common/flash_common_f234.c b/lib/stm32/common/flash_common_f234.c index e150ce79..0e01f811 100644 --- a/lib/stm32/common/flash_common_f234.c +++ b/lib/stm32/common/flash_common_f234.c @@ -55,17 +55,6 @@ void flash_clear_pgperr_flag(void) FLASH_SR |= FLASH_SR_PGPERR; } -/*---------------------------------------------------------------------------*/ -/** @brief Clear the End of Operation Status Flag - -*/ - -void flash_clear_eop_flag(void) -{ - FLASH_SR |= FLASH_SR_EOP; -} - - /*---------------------------------------------------------------------------*/ /** @brief Wait until Last Operation has Ended diff --git a/lib/stm32/f7/flash.c b/lib/stm32/f7/flash.c index a78b4bf6..846aa042 100644 --- a/lib/stm32/f7/flash.c +++ b/lib/stm32/f7/flash.c @@ -94,16 +94,6 @@ void flash_clear_pgperr_flag(void) FLASH_SR |= FLASH_SR_PGPERR; } -/*---------------------------------------------------------------------------*/ -/** @brief Clear the End of Operation Status Flag - -*/ - -void flash_clear_eop_flag(void) -{ - FLASH_SR |= FLASH_SR_EOP; -} - /*---------------------------------------------------------------------------*/ /** @brief Wait until Last Operation has Ended diff --git a/lib/stm32/l4/flash.c b/lib/stm32/l4/flash.c index d654ecc8..488017f0 100644 --- a/lib/stm32/l4/flash.c +++ b/lib/stm32/l4/flash.c @@ -68,13 +68,6 @@ void flash_clear_pgperr_flag(void) FLASH_SR |= FLASH_SR_PROGERR; } -/** @brief Clear the End of Operation Status Flag - */ -void flash_clear_eop_flag(void) -{ - FLASH_SR |= FLASH_SR_EOP; -} - /** @brief Wait until Last Operation has Ended * This loops indefinitely until an operation (write or erase) has completed * by testing the busy flag.