From e0a5860bb75eeac01a91ccdcd2f6953f2e3acd26 Mon Sep 17 00:00:00 2001
From: cladmi <gaetan.harter@fu-berlin.de>
Date: Thu, 11 Oct 2018 15:20:44 +0200
Subject: [PATCH] cpu/stm32_common: remove inadapted periph_flash_common

The `periph_flash_common` feature was only defined here to trigger
inclusion of a source file with common functions.
It even only defines private symbols `_lock` and `_unlock` so no reason
to expose it to the build system.
And in practice, all stm cpus providing `periph_flashpage` or
`periph_eeprom` were required to provide `periph_flash_common` to allow
including it.

The previous implementation was only parsing in the modules were in
`FEATURES_REQUIRED` wich did not take cases of `FEATURES_OPTIONAL` into
account.
And also, in the same time, as the dependencies was declared in
`Makefile.include` it was processed before `Makefile.dep` so never handled
cases where a module could depend on `periph_flashpage` or
`periph_eeprom` feature.

It is replaced by selecting the common source file when module using it
are included.

The now useless feature `periph_flash_common` is removed from
`FEATURES_PROVIDED`.
---
 cpu/stm32_common/Makefile.include | 6 ------
 cpu/stm32_common/periph/Makefile  | 6 ++++++
 cpu/stm32f0/Makefile.features     | 1 -
 cpu/stm32f1/Makefile.features     | 1 -
 cpu/stm32l0/Makefile.features     | 1 -
 cpu/stm32l1/Makefile.features     | 1 -
 cpu/stm32l4/Makefile.features     | 1 -
 7 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/cpu/stm32_common/Makefile.include b/cpu/stm32_common/Makefile.include
index 6fe4747cd9..13ce83f9c2 100644
--- a/cpu/stm32_common/Makefile.include
+++ b/cpu/stm32_common/Makefile.include
@@ -8,12 +8,6 @@ USEMODULE += periph_common
 # include stm32 common functions and stm32 common periph drivers
 USEMODULE += stm32_common stm32_common_periph
 
-# flashpage and eeprom periph implementations share flash lock/unlock functions
-# in periph_flash_common
-ifneq (,$(filter periph_flashpage periph_eeprom,$(FEATURES_REQUIRED)))
-  FEATURES_REQUIRED += periph_flash_common
-endif
-
 # For stm32 cpu's we use the stm32_common.ld linker script
 export LINKFLAGS += -L$(RIOTCPU)/stm32_common/ldscripts
 LINKER_SCRIPT ?= stm32_common.ld
diff --git a/cpu/stm32_common/periph/Makefile b/cpu/stm32_common/periph/Makefile
index d549119759..f4c1ed49c2 100644
--- a/cpu/stm32_common/periph/Makefile
+++ b/cpu/stm32_common/periph/Makefile
@@ -9,4 +9,10 @@ ifneq (,$(filter periph_i2c,$(USEMODULE)))
   endif
 endif
 
+# flashpage and eeprom periph implementations share flash lock/unlock functions
+# defined in flash_common.c
+ifneq (,$(filter periph_flashpage periph_eeprom,$(USEMODULE)))
+  SRC += flash_common.c
+endif
+
 include $(RIOTMAKE)/periph.mk
diff --git a/cpu/stm32f0/Makefile.features b/cpu/stm32f0/Makefile.features
index e2a50dd865..d286ea06f2 100644
--- a/cpu/stm32f0/Makefile.features
+++ b/cpu/stm32f0/Makefile.features
@@ -1,5 +1,4 @@
 ifeq (,$(filter nucleo-f031k6,$(BOARD)))
-  FEATURES_PROVIDED += periph_flash_common
   FEATURES_PROVIDED += periph_flashpage
   FEATURES_PROVIDED += periph_flashpage_raw
 endif
diff --git a/cpu/stm32f1/Makefile.features b/cpu/stm32f1/Makefile.features
index e5e8c0f6d8..5e5e8b9118 100644
--- a/cpu/stm32f1/Makefile.features
+++ b/cpu/stm32f1/Makefile.features
@@ -1,4 +1,3 @@
-FEATURES_PROVIDED += periph_flash_common
 FEATURES_PROVIDED += periph_flashpage
 FEATURES_PROVIDED += periph_flashpage_raw
 
diff --git a/cpu/stm32l0/Makefile.features b/cpu/stm32l0/Makefile.features
index 5c7e361aee..d76642f390 100644
--- a/cpu/stm32l0/Makefile.features
+++ b/cpu/stm32l0/Makefile.features
@@ -1,5 +1,4 @@
 FEATURES_PROVIDED += periph_eeprom
-FEATURES_PROVIDED += periph_flash_common
 FEATURES_PROVIDED += periph_flashpage
 FEATURES_PROVIDED += periph_flashpage_raw
 FEATURES_PROVIDED += periph_hwrng
diff --git a/cpu/stm32l1/Makefile.features b/cpu/stm32l1/Makefile.features
index d93fc23829..e13289086a 100644
--- a/cpu/stm32l1/Makefile.features
+++ b/cpu/stm32l1/Makefile.features
@@ -1,5 +1,4 @@
 FEATURES_PROVIDED += periph_eeprom
-FEATURES_PROVIDED += periph_flash_common
 FEATURES_PROVIDED += periph_flashpage
 FEATURES_PROVIDED += periph_flashpage_raw
 
diff --git a/cpu/stm32l4/Makefile.features b/cpu/stm32l4/Makefile.features
index f4388f2759..baed9e6078 100644
--- a/cpu/stm32l4/Makefile.features
+++ b/cpu/stm32l4/Makefile.features
@@ -1,4 +1,3 @@
-FEATURES_PROVIDED += periph_flash_common
 FEATURES_PROVIDED += periph_flashpage
 FEATURES_PROVIDED += periph_flashpage_raw
 FEATURES_PROVIDED += periph_hwrng
-- 
GitLab