diff --git a/cpu/cc2538/Kconfig b/cpu/cc2538/Kconfig index 50d27267c9..88972540eb 100644 --- a/cpu/cc2538/Kconfig +++ b/cpu/cc2538/Kconfig @@ -12,6 +12,7 @@ config CPU_FAM_CC2538 select HAS_CPU_CC2538 select HAS_PERIPH_CPUID select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_GPIO select HAS_PERIPH_GPIO_IRQ diff --git a/cpu/cc2538/Makefile.features b/cpu/cc2538/Makefile.features index a25dc67994..e19f99cf64 100644 --- a/cpu/cc2538/Makefile.features +++ b/cpu/cc2538/Makefile.features @@ -3,6 +3,7 @@ CPU_FAM = cc2538 FEATURES_PROVIDED += periph_cpuid FEATURES_PROVIDED += periph_flashpage +FEATURES_PROVIDED += periph_flashpage_in_address_space FEATURES_PROVIDED += periph_flashpage_pagewise FEATURES_PROVIDED += periph_gpio periph_gpio_irq FEATURES_PROVIDED += periph_hwrng diff --git a/cpu/cortexm_common/ldscripts/cortexm_base.ld b/cpu/cortexm_common/ldscripts/cortexm_base.ld index 91428dcc43..4145e9219c 100644 --- a/cpu/cortexm_common/ldscripts/cortexm_base.ld +++ b/cpu/cortexm_common/ldscripts/cortexm_base.ld @@ -233,6 +233,10 @@ SECTIONS _eheap1 = ORIGIN(bkup_ram) + LENGTH(bkup_ram); } > bkup_ram + .flash_writable (NOLOAD) : { + KEEP(*(SORT(.flash_writable.*))) + } > rom + .end_fw (NOLOAD) : ALIGN(4) { _end_fw = . ; } > rom diff --git a/cpu/efm32/Kconfig b/cpu/efm32/Kconfig index b3cb7fe977..7c39a5a769 100644 --- a/cpu/efm32/Kconfig +++ b/cpu/efm32/Kconfig @@ -10,6 +10,7 @@ config CPU_COMMON_EFM32 select HAS_CPU_EFM32 select HAS_PERIPH_CPUID select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_GPIO select HAS_PERIPH_GPIO_IRQ diff --git a/cpu/efm32/Makefile.features b/cpu/efm32/Makefile.features index 47e9bb76b0..e5e49fe300 100644 --- a/cpu/efm32/Makefile.features +++ b/cpu/efm32/Makefile.features @@ -11,6 +11,7 @@ endif FEATURES_PROVIDED += arch_efm32 FEATURES_PROVIDED += periph_cpuid FEATURES_PROVIDED += periph_flashpage +FEATURES_PROVIDED += periph_flashpage_in_address_space FEATURES_PROVIDED += periph_flashpage_pagewise FEATURES_PROVIDED += periph_gpio periph_gpio_irq FEATURES_PROVIDED += periph_rtt_set_counter diff --git a/cpu/gd32v/Kconfig b/cpu/gd32v/Kconfig index d34071cc44..7e6b245d97 100644 --- a/cpu/gd32v/Kconfig +++ b/cpu/gd32v/Kconfig @@ -12,6 +12,7 @@ config CPU_FAM_GD32V select HAS_PERIPH_CLIC select HAS_PERIPH_GPIO select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_PM select HAS_PERIPH_TIMER diff --git a/cpu/gd32v/Makefile.features b/cpu/gd32v/Makefile.features index 7dd18287e6..efe6509f76 100644 --- a/cpu/gd32v/Makefile.features +++ b/cpu/gd32v/Makefile.features @@ -7,6 +7,7 @@ FEATURES_PROVIDED += periph_timer_periodic FEATURES_PROVIDED += periph_wdt FEATURES_PROVIDED += periph_pm FEATURES_PROVIDED += periph_flashpage +FEATURES_PROVIDED += periph_flashpage_in_address_space FEATURES_PROVIDED += periph_flashpage_pagewise include $(RIOTCPU)/riscv_common/Makefile.features diff --git a/cpu/kinetis/Kconfig b/cpu/kinetis/Kconfig index 0a867907fc..5281715314 100644 --- a/cpu/kinetis/Kconfig +++ b/cpu/kinetis/Kconfig @@ -30,6 +30,7 @@ config CPU_FAM_K bool select CPU_COMMON_KINETIS select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_MCG @@ -42,6 +43,7 @@ config CPU_FAM_W bool select CPU_COMMON_KINETIS select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_MCG diff --git a/cpu/kinetis/Makefile.features b/cpu/kinetis/Makefile.features index 3a47100142..6ef7edd96e 100644 --- a/cpu/kinetis/Makefile.features +++ b/cpu/kinetis/Makefile.features @@ -21,6 +21,7 @@ include $(LAST_MAKEFILEDIR)/kinetis-info.mk ifneq (,$(filter k w,$(CPU_FAM))) FEATURES_PROVIDED += periph_flashpage + FEATURES_PROVIDED += periph_flashpage_in_address_space FEATURES_PROVIDED += periph_flashpage_pagewise endif diff --git a/cpu/msp430_common/Kconfig b/cpu/msp430_common/Kconfig index 6f5b27df0d..aaf2b5d1cc 100644 --- a/cpu/msp430_common/Kconfig +++ b/cpu/msp430_common/Kconfig @@ -33,6 +33,7 @@ config CPU_ARCH_MSP430 select HAS_ARCH_MSP430 select HAS_DBGPIN select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_NEWLIB select HAS_PERIPH_PM diff --git a/cpu/msp430_common/Makefile.features b/cpu/msp430_common/Makefile.features index f6dafead7c..b2d2886aa8 100644 --- a/cpu/msp430_common/Makefile.features +++ b/cpu/msp430_common/Makefile.features @@ -6,5 +6,6 @@ FEATURES_PROVIDED += arch_msp430 FEATURES_PROVIDED += dbgpin FEATURES_PROVIDED += newlib FEATURES_PROVIDED += periph_flashpage +FEATURES_PROVIDED += periph_flashpage_in_address_space FEATURES_PROVIDED += periph_flashpage_pagewise FEATURES_PROVIDED += periph_pm diff --git a/cpu/msp430_common/ldscripts/msp430_common.ld b/cpu/msp430_common/ldscripts/msp430_common.ld index 56b08ac9af..93474c22db 100644 --- a/cpu/msp430_common/ldscripts/msp430_common.ld +++ b/cpu/msp430_common/ldscripts/msp430_common.ld @@ -12,6 +12,10 @@ SECTIONS _srom = ORIGIN(ROM); _erom = ORIGIN(ROM) + LENGTH(ROM); + .flash_writable (NOLOAD) : { + KEEP(*(SORT(.flash_writable.*))) + } > ROM + .end_fw (NOLOAD) : ALIGN(4) { _end_fw = . ; } > ROM diff --git a/cpu/nrf5x_common/Kconfig b/cpu/nrf5x_common/Kconfig index 63ce5e863e..e4897d3fc2 100644 --- a/cpu/nrf5x_common/Kconfig +++ b/cpu/nrf5x_common/Kconfig @@ -9,6 +9,7 @@ config CPU_COMMON_NRF5X select HAS_BLE_NIMBLE select HAS_PERIPH_CPUID select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_GPIO select HAS_PERIPH_GPIO_IRQ diff --git a/cpu/nrf5x_common/Makefile.features b/cpu/nrf5x_common/Makefile.features index babf9ae4d4..1ba09ebd57 100644 --- a/cpu/nrf5x_common/Makefile.features +++ b/cpu/nrf5x_common/Makefile.features @@ -1,6 +1,7 @@ # Put defined MCU peripherals here (in alphabetical order) FEATURES_PROVIDED += periph_cpuid FEATURES_PROVIDED += periph_flashpage +FEATURES_PROVIDED += periph_flashpage_in_address_space FEATURES_PROVIDED += periph_flashpage_pagewise FEATURES_PROVIDED += periph_gpio periph_gpio_irq FEATURES_PROVIDED += periph_timer_periodic diff --git a/cpu/nrf9160/Kconfig b/cpu/nrf9160/Kconfig index 3854277c39..efc36bb285 100644 --- a/cpu/nrf9160/Kconfig +++ b/cpu/nrf9160/Kconfig @@ -9,6 +9,7 @@ config CPU_FAM_NRF9160 select HAS_CPU_NRF9160 select HAS_PERIPH_CPUID select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_GPIO select HAS_PERIPH_GPIO_IRQ diff --git a/cpu/riscv_common/ldscripts/riscv_base.ld b/cpu/riscv_common/ldscripts/riscv_base.ld index 719567b59b..5e56a47832 100644 --- a/cpu/riscv_common/ldscripts/riscv_base.ld +++ b/cpu/riscv_common/ldscripts/riscv_base.ld @@ -229,6 +229,10 @@ SECTIONS PROVIDE( _sp = . ); } >ram AT>ram :ram + .flash_writable (NOLOAD) : { + KEEP(*(SORT(.flash_writable.*))) + } > rom + .end_fw (NOLOAD) : ALIGN(4) { _end_fw = . ; } > flash diff --git a/cpu/sam0_common/Kconfig b/cpu/sam0_common/Kconfig index 262908a991..909dee8733 100644 --- a/cpu/sam0_common/Kconfig +++ b/cpu/sam0_common/Kconfig @@ -9,6 +9,7 @@ config CPU_COMMON_SAM0 bool select HAS_PERIPH_CPUID select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_FLASHPAGE_RWEE select HAS_PERIPH_GPIO diff --git a/cpu/sam0_common/Makefile.features b/cpu/sam0_common/Makefile.features index d23c8b095f..aad3211a38 100644 --- a/cpu/sam0_common/Makefile.features +++ b/cpu/sam0_common/Makefile.features @@ -8,6 +8,7 @@ ifeq (,$(filter $(CPU_MODELS_WITHOUT_DMA),$(CPU_MODEL))) endif FEATURES_PROVIDED += periph_flashpage +FEATURES_PROVIDED += periph_flashpage_in_address_space FEATURES_PROVIDED += periph_flashpage_pagewise FEATURES_PROVIDED += periph_flashpage_rwee FEATURES_PROVIDED += periph_gpio periph_gpio_irq diff --git a/cpu/stm32/Makefile.features b/cpu/stm32/Makefile.features index 3ebfa16edb..bedaa6971d 100644 --- a/cpu/stm32/Makefile.features +++ b/cpu/stm32/Makefile.features @@ -14,6 +14,7 @@ FEATURES_PROVIDED += periph_uart_nonblocking ifneq (,$(filter $(CPU_FAM),f0 f1 f3 g0 g4 l0 l1 l4 l5 u5 wb wl)) FEATURES_PROVIDED += periph_flashpage + FEATURES_PROVIDED += periph_flashpage_in_address_space FEATURES_PROVIDED += periph_flashpage_pagewise endif diff --git a/cpu/stm32/kconfigs/f0/Kconfig b/cpu/stm32/kconfigs/f0/Kconfig index d0c1d49834..b77840c956 100644 --- a/cpu/stm32/kconfigs/f0/Kconfig +++ b/cpu/stm32/kconfigs/f0/Kconfig @@ -14,6 +14,7 @@ config CPU_FAM_F0 select CPU_CORE_CORTEX_M0 select HAS_CPU_STM32F0 select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_FLASHPAGE_RAW select HAS_PERIPH_WDT diff --git a/cpu/stm32/kconfigs/f1/Kconfig b/cpu/stm32/kconfigs/f1/Kconfig index 5692629af7..37cf169c1b 100644 --- a/cpu/stm32/kconfigs/f1/Kconfig +++ b/cpu/stm32/kconfigs/f1/Kconfig @@ -13,6 +13,7 @@ config CPU_FAM_F1 select HAS_BOOTLOADER_STM32 select HAS_CPU_STM32F1 select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_FLASHPAGE_RAW select HAS_PERIPH_RTT_SET_COUNTER diff --git a/cpu/stm32/kconfigs/f3/Kconfig b/cpu/stm32/kconfigs/f3/Kconfig index 2cd5983079..53a20d8559 100644 --- a/cpu/stm32/kconfigs/f3/Kconfig +++ b/cpu/stm32/kconfigs/f3/Kconfig @@ -11,6 +11,7 @@ config CPU_FAM_F3 select CPU_CORE_CORTEX_M4F select HAS_CPU_STM32F3 select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_FLASHPAGE_RAW select HAS_PERIPH_RTC_MEM diff --git a/cpu/stm32/kconfigs/g0/Kconfig b/cpu/stm32/kconfigs/g0/Kconfig index 891b429c8b..ad722cceb4 100644 --- a/cpu/stm32/kconfigs/g0/Kconfig +++ b/cpu/stm32/kconfigs/g0/Kconfig @@ -11,6 +11,7 @@ config CPU_FAM_G0 select CPU_CORE_CORTEX_M0PLUS select HAS_CPU_STM32G0 select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_FLASHPAGE_RAW select HAS_PERIPH_VBAT diff --git a/cpu/stm32/kconfigs/g4/Kconfig b/cpu/stm32/kconfigs/g4/Kconfig index 89e85d8c94..3648768eb4 100644 --- a/cpu/stm32/kconfigs/g4/Kconfig +++ b/cpu/stm32/kconfigs/g4/Kconfig @@ -12,6 +12,7 @@ config CPU_FAM_G4 select HAS_CPU_STM32G4 select HAS_CORTEXM_MPU select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_HWRNG select HAS_PERIPH_VBAT diff --git a/cpu/stm32/kconfigs/l0/Kconfig b/cpu/stm32/kconfigs/l0/Kconfig index 53c263dd2b..27d18d5be8 100644 --- a/cpu/stm32/kconfigs/l0/Kconfig +++ b/cpu/stm32/kconfigs/l0/Kconfig @@ -11,6 +11,7 @@ config CPU_FAM_L0 select CPU_CORE_CORTEX_M0PLUS select HAS_CPU_STM32L0 select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_EEPROM select HAS_PERIPH_RTC_MEM diff --git a/cpu/stm32/kconfigs/l1/Kconfig b/cpu/stm32/kconfigs/l1/Kconfig index 0e662839b8..21504b9a79 100644 --- a/cpu/stm32/kconfigs/l1/Kconfig +++ b/cpu/stm32/kconfigs/l1/Kconfig @@ -12,6 +12,7 @@ config CPU_FAM_L1 select HAS_CPU_STM32L1 select HAS_CORTEXM_MPU select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_EEPROM select HAS_PERIPH_RTC_MEM diff --git a/cpu/stm32/kconfigs/l4/Kconfig b/cpu/stm32/kconfigs/l4/Kconfig index d4fa612f40..4247d172ef 100644 --- a/cpu/stm32/kconfigs/l4/Kconfig +++ b/cpu/stm32/kconfigs/l4/Kconfig @@ -12,6 +12,7 @@ config CPU_FAM_L4 select HAS_CPU_STM32L4 select HAS_CORTEXM_MPU select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_HWRNG select HAS_PERIPH_RTC_MEM diff --git a/cpu/stm32/kconfigs/l5/Kconfig b/cpu/stm32/kconfigs/l5/Kconfig index 5a227b62ac..d302634b8d 100644 --- a/cpu/stm32/kconfigs/l5/Kconfig +++ b/cpu/stm32/kconfigs/l5/Kconfig @@ -11,6 +11,7 @@ config CPU_FAM_L5 select CPU_CORE_CORTEX_M33 select HAS_CPU_STM32L5 select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_HWRNG select HAS_PERIPH_RTC_MEM diff --git a/cpu/stm32/kconfigs/u5/Kconfig b/cpu/stm32/kconfigs/u5/Kconfig index 7304394a98..5bcac0efb4 100644 --- a/cpu/stm32/kconfigs/u5/Kconfig +++ b/cpu/stm32/kconfigs/u5/Kconfig @@ -12,6 +12,7 @@ config CPU_FAM_U5 select HAS_BACKUP_RAM select HAS_CPU_STM32U5 select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_HWRNG select HAS_PERIPH_RTC_MEM diff --git a/cpu/stm32/kconfigs/wb/Kconfig b/cpu/stm32/kconfigs/wb/Kconfig index c49cc9b9dc..81ae240ce4 100644 --- a/cpu/stm32/kconfigs/wb/Kconfig +++ b/cpu/stm32/kconfigs/wb/Kconfig @@ -11,6 +11,7 @@ config CPU_FAM_WB select CPU_CORE_CORTEX_M4 select HAS_CPU_STM32WB select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_HWRNG select HAS_PERIPH_RTC_MEM diff --git a/cpu/stm32/kconfigs/wl/Kconfig b/cpu/stm32/kconfigs/wl/Kconfig index a887221b6a..3ab1e02b8b 100644 --- a/cpu/stm32/kconfigs/wl/Kconfig +++ b/cpu/stm32/kconfigs/wl/Kconfig @@ -12,6 +12,7 @@ config CPU_FAM_WL select CPU_CORE_CORTEX_M4 select HAS_CPU_STM32WL select HAS_PERIPH_FLASHPAGE + select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_RTC_MEM select HAS_PERIPH_VBAT diff --git a/drivers/include/periph/flashpage.h b/drivers/include/periph/flashpage.h index 2ae1a62eec..6f52b8c55b 100644 --- a/drivers/include/periph/flashpage.h +++ b/drivers/include/periph/flashpage.h @@ -151,6 +151,31 @@ enum { #error "periph/flashpage: FLASHPAGE_NUMOF not defined" #endif +#ifdef MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE +/** + * @def FLASH_WRITABLE_INIT(name, size) + * @brief Define an array in flash memory + * + * This macro defines an array stored in the ".flash_writable" section + * which is part of flash memory. With this macro it is possible to + * reserve flash memory at build time. + * + * E.g. FLASH_WRITABLE_INIT(a, 2); will create a array with name 'a' + * of size 2 * @ref FLASHPAGE_SIZE which is stored in flash memory and takes up + * 2 flash pages. + * + * Symbols created by using this macro are sorted in ascending order by name. + * Therefore, &a < &b where a and b are arrays created using this macro. + * + * @param[in] name name of the array + * @param[in] size size of the array in unit of @ref FLASHPAGE_SIZE + */ +#define FLASH_WRITABLE_INIT(name, size) \ + __attribute__((aligned(FLASHPAGE_SIZE))) \ + __attribute__((section(".flash_writable." #name))) \ + static const uint8_t name [size * FLASHPAGE_SIZE] +#endif + /** * @brief Get the page size of the given page number * diff --git a/drivers/periph_common/Kconfig.flashpage b/drivers/periph_common/Kconfig.flashpage index 1b266b0d45..50dca80480 100644 --- a/drivers/periph_common/Kconfig.flashpage +++ b/drivers/periph_common/Kconfig.flashpage @@ -14,6 +14,11 @@ menuconfig MODULE_PERIPH_FLASHPAGE # periph_init_% modules are handled in Makefile. We need to define them to keep # the list the same for now. We should be able to remove them later on. +config MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE + bool "Static memory sections can fundamentally be turned into flash pages" + depends on HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE + depends on MODULE_PERIPH_FLASHPAGE_PAGEWISE + config MODULE_PERIPH_INIT_FLASHPAGE bool "Auto initialize Flashpage peripheral" default y if MODULE_PERIPH_INIT diff --git a/kconfigs/Kconfig.features b/kconfigs/Kconfig.features index c178989a29..aca9665304 100644 --- a/kconfigs/Kconfig.features +++ b/kconfigs/Kconfig.features @@ -73,6 +73,12 @@ config HAS_ETHERNET help Indicates that Ethernet connectivity is present. +config HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE + bool + help + Indicates that static memory sections can fundamentally be turned + into flash pages. + config HAS_HIGHLEVEL_STDIO bool help diff --git a/tests/periph_flashpage/Kconfig b/tests/periph_flashpage/Kconfig index 7c77bcac7d..0e5583a074 100644 --- a/tests/periph_flashpage/Kconfig +++ b/tests/periph_flashpage/Kconfig @@ -8,6 +8,7 @@ config APPLICATION bool default y + imply MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE imply MODULE_PERIPH_FLASHPAGE_PAGEWISE imply MODULE_PERIPH_FLASHPAGE_RWEE depends on TEST_KCONFIG diff --git a/tests/periph_flashpage/Makefile b/tests/periph_flashpage/Makefile index eee35808b0..6271ee8f8a 100644 --- a/tests/periph_flashpage/Makefile +++ b/tests/periph_flashpage/Makefile @@ -2,6 +2,7 @@ BOARD ?= iotlab-m3 include ../Makefile.tests_common FEATURES_REQUIRED += periph_flashpage +FEATURES_OPTIONAL += periph_flashpage_in_address_space FEATURES_OPTIONAL += periph_flashpage_pagewise FEATURES_OPTIONAL += periph_flashpage_rwee diff --git a/tests/periph_flashpage/main.c b/tests/periph_flashpage/main.c index a18ffdc7b1..48932cf5ff 100644 --- a/tests/periph_flashpage/main.c +++ b/tests/periph_flashpage/main.c @@ -18,6 +18,7 @@ * @} */ +#include #include #include #include @@ -55,7 +56,19 @@ static char raw_buf[RAW_BUF_SIZE] ALIGNMENT_ATTR; * requires 64 bit alignment. */ static uint8_t page_mem[FLASHPAGE_SIZE] ALIGNMENT_ATTR; -#endif + +#ifdef MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE +/** + * @brief Reserve 1 page of flash memory + */ +FLASH_WRITABLE_INIT(_backing_memory, 0x1); + +/* +* @brief Created to test the sorting of symbols in .flash_writable section +*/ +FLASH_WRITABLE_INIT(_abacking_memory, 0x1); +#endif /* MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE */ +#endif /* MODULE_PERIPH_FLASHPAGE_PAGEWISE */ static int getpage(const char *str) { @@ -361,7 +374,63 @@ static int cmd_test_last(int argc, char **argv) puts("wrote local page buffer to last flash page"); return 0; } -#endif + +#ifdef MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE +/** + * @brief Does a write and verify test on reserved page + */ +static int cmd_test_reserved(int argc, char **argv) +{ + (void) argc; + (void) argv; + + /** + * Arrays created by the FLASH_WRITABLE_INIT macro should be sorted in + * ascending order by name. + */ + assert(&_abacking_memory < &_backing_memory); + + char fill = 'a'; + const char sig[] = {"RIOT"}; + unsigned page = flashpage_page((void *)_backing_memory); + + printf("Reserved page num: %u \n", page); + + flashpage_read(page, page_mem); + + /* test is running for the first time so initialize flash */ + if (memcmp(sig, &page_mem[1], sizeof(sig)) != 0) { + page_mem[0] = 0; + memcpy(&page_mem[1], sig, sizeof(sig)); + } + else { + page_mem[0]++; + } + + printf("Since the last firmware update this test has been run " + "%u times \n", page_mem[0]); + + /* fill memory after counter and signature */ + for (unsigned i = 0x1 + sizeof(sig); i < sizeof(page_mem); i++) { + page_mem[i] = (uint8_t)fill++; + if (fill > 'z') { + fill = 'a'; + } + } + + if (flashpage_write_and_verify(page, page_mem) != FLASHPAGE_OK) { + puts("error verifying the content of reserved page"); + return 1; + } + + puts("wrote local page buffer to reserved flash page"); + puts("\nWhen running on a bootloader, as an extra check, try restarting " + "the board and check whether this application still comes up."); + + return 0; +} +#endif /* MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE */ +#endif /* MODULE_PERIPH_FLASHPAGE_PAGEWISE */ /** * @brief Does a short raw write on last page available @@ -641,6 +710,9 @@ static const shell_command_t shell_commands[] = { { "edit", "Write bytes to the local page buffer", cmd_edit }, { "test", "Write and verify test pattern", cmd_test }, { "test_last_pagewise", "Write and verify test pattern on last page available", cmd_test_last }, +#endif +#ifdef MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE + { "test_reserved_pagewise", "Write and verify short write on reserved page", cmd_test_reserved}, #endif { "test_last_raw", "Write and verify raw short write on last page available", cmd_test_last_raw }, #ifdef FLASHPAGE_RWWEE_NUMOF diff --git a/tests/periph_flashpage/tests/01-run.py b/tests/periph_flashpage/tests/01-run.py index 48a5ac0bb9..21b3e1bf41 100755 --- a/tests/periph_flashpage/tests/01-run.py +++ b/tests/periph_flashpage/tests/01-run.py @@ -29,6 +29,15 @@ def testfunc(child): child.expect_exact('wrote local page buffer to last flash page') child.expect('>') + # check if board has flash page reservation capability and if so test that as well + # capability is deduced from help contents + child.sendline("help") + index = child.expect(['test_reserved_pagewise', '>']) + if index == 0: + child.sendline("test_reserved_pagewise") + child.expect_exact('wrote local page buffer to reserved flash page') + child.expect('>') + # check if board has RWWEE capability and if so test that as well # capability is deduced from help contents child.sendline("help")