From 9c1455d55fdadd09178e4bfb3a70c1a1cb82323d Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 27 Jan 2021 11:48:08 +0100 Subject: [PATCH 1/7] cpu: make pm_layered a DEFAULT_MODULE Allow to disable pm_layered in the bootloader to save some ROM. --- cpu/cc2538/Makefile.default | 1 + cpu/cc2538/Makefile.dep | 2 -- cpu/efm32/Makefile.default | 1 + cpu/efm32/Makefile.dep | 3 --- cpu/esp32/Makefile.default | 1 + cpu/esp32/Makefile.dep | 1 - cpu/kinetis/Makefile.default | 1 + cpu/kinetis/Makefile.dep | 1 - cpu/lpc1768/Makefile.default | 1 + cpu/lpc1768/Makefile.dep | 2 -- cpu/lpc23xx/Makefile.default | 1 + cpu/lpc23xx/Makefile.dep | 1 - cpu/sam0_common/Makefile.default | 1 + cpu/sam0_common/Makefile.dep | 3 --- cpu/samd21/Makefile.default | 1 + cpu/samd5x/Makefile.default | 1 + cpu/saml1x/Makefile.default | 1 + cpu/saml21/Makefile.default | 1 + cpu/stm32/Makefile.default | 1 + cpu/stm32/Makefile.dep | 1 - sys/include/pm_layered.h | 8 ++++++++ 21 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 cpu/cc2538/Makefile.default create mode 100644 cpu/efm32/Makefile.default create mode 100644 cpu/esp32/Makefile.default create mode 100644 cpu/kinetis/Makefile.default create mode 100644 cpu/lpc1768/Makefile.default create mode 100644 cpu/lpc23xx/Makefile.default create mode 100644 cpu/sam0_common/Makefile.default create mode 100644 cpu/samd21/Makefile.default create mode 100644 cpu/samd5x/Makefile.default create mode 100644 cpu/saml1x/Makefile.default create mode 100644 cpu/saml21/Makefile.default create mode 100644 cpu/stm32/Makefile.default diff --git a/cpu/cc2538/Makefile.default b/cpu/cc2538/Makefile.default new file mode 100644 index 0000000000..034f8c7848 --- /dev/null +++ b/cpu/cc2538/Makefile.default @@ -0,0 +1 @@ +DEFAULT_MODULE += pm_layered diff --git a/cpu/cc2538/Makefile.dep b/cpu/cc2538/Makefile.dep index 39bdd75366..d8489f01b0 100644 --- a/cpu/cc2538/Makefile.dep +++ b/cpu/cc2538/Makefile.dep @@ -13,6 +13,4 @@ ifneq (,$(filter periph_uart_nonblocking,$(USEMODULE))) USEMODULE += tsrb endif -USEMODULE += pm_layered - include $(RIOTCPU)/cortexm_common/Makefile.dep diff --git a/cpu/efm32/Makefile.default b/cpu/efm32/Makefile.default new file mode 100644 index 0000000000..034f8c7848 --- /dev/null +++ b/cpu/efm32/Makefile.default @@ -0,0 +1 @@ +DEFAULT_MODULE += pm_layered diff --git a/cpu/efm32/Makefile.dep b/cpu/efm32/Makefile.dep index 2d83ee7ed5..b7f90bf5ae 100644 --- a/cpu/efm32/Makefile.dep +++ b/cpu/efm32/Makefile.dep @@ -13,9 +13,6 @@ endif # include Gecko SDK package USEPKG += gecko_sdk -# include layered power management -USEMODULE += pm_layered - ifneq (,$(filter efm32_coretemp,$(USEMODULE))) FEATURES_REQUIRED += periph_adc endif diff --git a/cpu/esp32/Makefile.default b/cpu/esp32/Makefile.default new file mode 100644 index 0000000000..034f8c7848 --- /dev/null +++ b/cpu/esp32/Makefile.default @@ -0,0 +1 @@ +DEFAULT_MODULE += pm_layered diff --git a/cpu/esp32/Makefile.dep b/cpu/esp32/Makefile.dep index 73630031f8..99a0fcb39c 100644 --- a/cpu/esp32/Makefile.dep +++ b/cpu/esp32/Makefile.dep @@ -5,7 +5,6 @@ include $(RIOTCPU)/esp_common/Makefile.dep USEMODULE += esp_idf_driver USEMODULE += esp_idf_esp32 USEMODULE += esp_idf_soc -USEMODULE += pm_layered ifneq (,$(filter newlib,$(USEMODULE))) USEMODULE += newlib_nano diff --git a/cpu/kinetis/Makefile.default b/cpu/kinetis/Makefile.default new file mode 100644 index 0000000000..034f8c7848 --- /dev/null +++ b/cpu/kinetis/Makefile.default @@ -0,0 +1 @@ +DEFAULT_MODULE += pm_layered diff --git a/cpu/kinetis/Makefile.dep b/cpu/kinetis/Makefile.dep index 4b4eba3a72..309c3ffd60 100644 --- a/cpu/kinetis/Makefile.dep +++ b/cpu/kinetis/Makefile.dep @@ -21,6 +21,5 @@ else ifneq (,$(filter periph_mcg_lite,$(FEATURES_USED))) endif USEMODULE += periph_wdog -USEMODULE += pm_layered include $(RIOTCPU)/cortexm_common/Makefile.dep diff --git a/cpu/lpc1768/Makefile.default b/cpu/lpc1768/Makefile.default new file mode 100644 index 0000000000..034f8c7848 --- /dev/null +++ b/cpu/lpc1768/Makefile.default @@ -0,0 +1 @@ +DEFAULT_MODULE += pm_layered diff --git a/cpu/lpc1768/Makefile.dep b/cpu/lpc1768/Makefile.dep index f0a929e7f1..849cc8d116 100644 --- a/cpu/lpc1768/Makefile.dep +++ b/cpu/lpc1768/Makefile.dep @@ -1,3 +1 @@ -USEMODULE += pm_layered - include $(RIOTCPU)/cortexm_common/Makefile.dep diff --git a/cpu/lpc23xx/Makefile.default b/cpu/lpc23xx/Makefile.default new file mode 100644 index 0000000000..034f8c7848 --- /dev/null +++ b/cpu/lpc23xx/Makefile.default @@ -0,0 +1 @@ +DEFAULT_MODULE += pm_layered diff --git a/cpu/lpc23xx/Makefile.dep b/cpu/lpc23xx/Makefile.dep index 2751e15f57..c72ba6ec12 100644 --- a/cpu/lpc23xx/Makefile.dep +++ b/cpu/lpc23xx/Makefile.dep @@ -1,7 +1,6 @@ USEMODULE += arm7_common USEMODULE += bitfield USEMODULE += periph -USEMODULE += pm_layered ifneq (,$(filter mci,$(USEMODULE))) USEMODULE += xtimer diff --git a/cpu/sam0_common/Makefile.default b/cpu/sam0_common/Makefile.default new file mode 100644 index 0000000000..034f8c7848 --- /dev/null +++ b/cpu/sam0_common/Makefile.default @@ -0,0 +1 @@ +DEFAULT_MODULE += pm_layered diff --git a/cpu/sam0_common/Makefile.dep b/cpu/sam0_common/Makefile.dep index 276bd6531c..13b8a500fc 100644 --- a/cpu/sam0_common/Makefile.dep +++ b/cpu/sam0_common/Makefile.dep @@ -6,9 +6,6 @@ ifneq (,$(filter periph_rtc periph_rtt,$(USEMODULE))) USEMODULE += periph_rtc_rtt endif -# All SAM0 based CPUs provide PM -USEMODULE += pm_layered - # include sam0 common periph drivers USEMODULE += sam0_common_periph diff --git a/cpu/samd21/Makefile.default b/cpu/samd21/Makefile.default new file mode 100644 index 0000000000..482f492884 --- /dev/null +++ b/cpu/samd21/Makefile.default @@ -0,0 +1 @@ +include $(RIOTCPU)/sam0_common/Makefile.default diff --git a/cpu/samd5x/Makefile.default b/cpu/samd5x/Makefile.default new file mode 100644 index 0000000000..482f492884 --- /dev/null +++ b/cpu/samd5x/Makefile.default @@ -0,0 +1 @@ +include $(RIOTCPU)/sam0_common/Makefile.default diff --git a/cpu/saml1x/Makefile.default b/cpu/saml1x/Makefile.default new file mode 100644 index 0000000000..482f492884 --- /dev/null +++ b/cpu/saml1x/Makefile.default @@ -0,0 +1 @@ +include $(RIOTCPU)/sam0_common/Makefile.default diff --git a/cpu/saml21/Makefile.default b/cpu/saml21/Makefile.default new file mode 100644 index 0000000000..482f492884 --- /dev/null +++ b/cpu/saml21/Makefile.default @@ -0,0 +1 @@ +include $(RIOTCPU)/sam0_common/Makefile.default diff --git a/cpu/stm32/Makefile.default b/cpu/stm32/Makefile.default new file mode 100644 index 0000000000..034f8c7848 --- /dev/null +++ b/cpu/stm32/Makefile.default @@ -0,0 +1 @@ +DEFAULT_MODULE += pm_layered diff --git a/cpu/stm32/Makefile.dep b/cpu/stm32/Makefile.dep index 63b3ec9af9..a8fc68c9eb 100644 --- a/cpu/stm32/Makefile.dep +++ b/cpu/stm32/Makefile.dep @@ -1,5 +1,4 @@ # All stm32 families provide pm support -USEMODULE += pm_layered # include stm32 common periph drivers, clock configurations and vectors USEMODULE += periph stm32_clk stm32_vectors diff --git a/sys/include/pm_layered.h b/sys/include/pm_layered.h index 4cba7ee6a0..cc4ab6ea1e 100644 --- a/sys/include/pm_layered.h +++ b/sys/include/pm_layered.h @@ -62,14 +62,22 @@ typedef union { * * @param[in] mode power mode to block */ +#ifdef MODULE_PM_LAYERED void pm_block(unsigned mode); +#else +static inline void pm_block(unsigned mode) { (void)mode; } +#endif /** * @brief Unblock a power mode * * @param[in] mode power mode to unblock */ +#ifdef MODULE_PM_LAYERED void pm_unblock(unsigned mode); +#else +static inline void pm_unblock(unsigned mode) { (void)mode; } +#endif /** * @brief Switches the MCU to a new power mode From b6c96b101bf9eafc0121726c8a6b2b3fc5abd834 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 27 Jan 2021 11:55:13 +0100 Subject: [PATCH 2/7] riotboot: disable pm_layered On `same54-xpro` this saves 212 bytes of ROM. --- bootloaders/riotboot/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/bootloaders/riotboot/Makefile b/bootloaders/riotboot/Makefile index c2695e8073..bc19fbe7e0 100644 --- a/bootloaders/riotboot/Makefile +++ b/bootloaders/riotboot/Makefile @@ -16,6 +16,7 @@ CFLAGS += -DRIOTBOOT CFLAGS += -DNDEBUG -DLOG_LEVEL=LOG_NONE DISABLE_MODULE += core_init core_msg core_panic DISABLE_MODULE += auto_init auto_init_% +DISABLE_MODULE += pm_layered # avoid using stdio USEMODULE += stdio_null From f12a82e4f9408837bef0440aa93656cec2bea08d Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 27 Jan 2021 14:07:22 +0100 Subject: [PATCH 3/7] cpu/stm32: use common pm_off() function The code is identical to the one found in sys/pm_layered/pm.c --- cpu/stm32/include/periph_cpu.h | 5 ----- cpu/stm32/periph/pm.c | 6 ------ 2 files changed, 11 deletions(-) diff --git a/cpu/stm32/include/periph_cpu.h b/cpu/stm32/include/periph_cpu.h index e7c9808e8b..325eb13f24 100644 --- a/cpu/stm32/include/periph_cpu.h +++ b/cpu/stm32/include/periph_cpu.h @@ -98,11 +98,6 @@ extern "C" { #define CPUID_ADDR (UID_BASE) #endif -/** - * @brief We provide our own pm_off() function for all STM32-based CPUs - */ -#define PROVIDES_PM_LAYERED_OFF - /** * @brief All STM timers have 4 capture-compare channels */ diff --git a/cpu/stm32/periph/pm.c b/cpu/stm32/periph/pm.c index 371c0f1604..91e72ca45e 100644 --- a/cpu/stm32/periph/pm.c +++ b/cpu/stm32/periph/pm.c @@ -151,9 +151,3 @@ void pm_set(unsigned mode) #endif } } - -void pm_off(void) -{ - irq_disable(); - pm_set(0); -} From 00289b08a4579b5e666aa15c9589a6d4395ed3c6 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 27 Jan 2021 14:16:17 +0100 Subject: [PATCH 4/7] riotboot: don't select periph_pm --- Makefile.dep | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile.dep b/Makefile.dep index c7b9ced15b..eb82d7cd7b 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -86,8 +86,11 @@ endif # always select gpio (until explicit dependencies are sorted out) FEATURES_OPTIONAL += periph_gpio -# always select power management if available -FEATURES_OPTIONAL += periph_pm +# always select power management unless building the bootloader +# pm is not needed by the bootloader and omitting it saves some ROM +ifneq (1, $(RIOTBOOT_BUILD)) + FEATURES_OPTIONAL += periph_pm +endif # always select provided architecture features FEATURES_REQUIRED += $(filter arch_%,$(FEATURES_PROVIDED)) From 32c30aaeaa55a84c756a540a31ab5f21876c20e9 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 27 Jan 2021 14:23:31 +0100 Subject: [PATCH 5/7] pm_layered: depend on periph_pm --- sys/Makefile.dep | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sys/Makefile.dep b/sys/Makefile.dep index c24137c409..c85642fadc 100644 --- a/sys/Makefile.dep +++ b/sys/Makefile.dep @@ -732,6 +732,10 @@ ifneq (,$(filter phydat,$(USEMODULE))) USEMODULE += fmt endif +ifneq (,$(filter pm_layered,$(USEMODULE))) + FEATURES_REQUIRED += periph_pm +endif + ifneq (,$(filter evtimer_mbox,$(USEMODULE))) USEMODULE += evtimer USEMODULE += core_mbox From 118cf0e9e6e4a63553b535feedadb180330e6ec7 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 27 Jan 2021 15:29:19 +0100 Subject: [PATCH 6/7] riotboot_usb_dfu: depend on periph_pm --- sys/Makefile.dep | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/Makefile.dep b/sys/Makefile.dep index c85642fadc..0aeeaaa7f5 100644 --- a/sys/Makefile.dep +++ b/sys/Makefile.dep @@ -1019,6 +1019,7 @@ ifneq (,$(filter riotboot_usb_dfu, $(USEMODULE))) USEMODULE += usbus_dfu USEMODULE += riotboot_flashwrite FEATURES_REQUIRED += no_idle_thread + FEATURES_REQUIRED += periph_pm endif ifneq (,$(filter irq_handler,$(USEMODULE))) From 762decd2075f83533e4dad660bb044ce3acaadd4 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 27 Jan 2021 15:35:48 +0100 Subject: [PATCH 7/7] boards/common/e104-bt50xxa-tb: software reset depends on periph_pm --- boards/common/e104-bt50xxa-tb/Makefile.dep | 1 + 1 file changed, 1 insertion(+) diff --git a/boards/common/e104-bt50xxa-tb/Makefile.dep b/boards/common/e104-bt50xxa-tb/Makefile.dep index 0cb51653e7..6d8bd098b2 100644 --- a/boards/common/e104-bt50xxa-tb/Makefile.dep +++ b/boards/common/e104-bt50xxa-tb/Makefile.dep @@ -5,6 +5,7 @@ endif # used for software reset ifneq (,$(filter board_software_reset,$(USEMODULE))) FEATURES_REQUIRED += periph_gpio_irq + FEATURES_REQUIRED += periph_pm endif include $(RIOTBOARD)/common/nrf52/Makefile.dep