diff --git a/boards/nucleo-f030/Makefile.features b/boards/nucleo-f030/Makefile.features index 5942339b26cf9947e91bba26b812162822a3870f..e7147b0ecb4ec9b3b5426d245e4ea7aef7e30715 100644 --- a/boards/nucleo-f030/Makefile.features +++ b/boards/nucleo-f030/Makefile.features @@ -1,6 +1,7 @@ # Put defined MCU peripherals here (in alphabetical order) FEATURES_PROVIDED += periph_adc FEATURES_PROVIDED += periph_cpuid +FEATURES_PROVIDED += periph_flashpage FEATURES_PROVIDED += periph_gpio FEATURES_PROVIDED += periph_pwm FEATURES_PROVIDED += periph_rtc diff --git a/boards/nucleo-f070/Makefile.features b/boards/nucleo-f070/Makefile.features index 5942339b26cf9947e91bba26b812162822a3870f..e7147b0ecb4ec9b3b5426d245e4ea7aef7e30715 100644 --- a/boards/nucleo-f070/Makefile.features +++ b/boards/nucleo-f070/Makefile.features @@ -1,6 +1,7 @@ # Put defined MCU peripherals here (in alphabetical order) FEATURES_PROVIDED += periph_adc FEATURES_PROVIDED += periph_cpuid +FEATURES_PROVIDED += periph_flashpage FEATURES_PROVIDED += periph_gpio FEATURES_PROVIDED += periph_pwm FEATURES_PROVIDED += periph_rtc diff --git a/boards/nucleo-f072/Makefile.features b/boards/nucleo-f072/Makefile.features index 4a5c8488bc8d267bedfadc74865727642de82de9..5017d4f193e29506375bd7fea37284b135cc3037 100644 --- a/boards/nucleo-f072/Makefile.features +++ b/boards/nucleo-f072/Makefile.features @@ -1,6 +1,7 @@ # Put defined MCU peripherals here (in alphabetical order) FEATURES_PROVIDED += periph_adc FEATURES_PROVIDED += periph_cpuid +FEATURES_PROVIDED += periph_flashpage FEATURES_PROVIDED += periph_gpio FEATURES_PROVIDED += periph_pwm FEATURES_PROVIDED += periph_rtc diff --git a/boards/nucleo-f091/Makefile.features b/boards/nucleo-f091/Makefile.features index 4a5c8488bc8d267bedfadc74865727642de82de9..5017d4f193e29506375bd7fea37284b135cc3037 100644 --- a/boards/nucleo-f091/Makefile.features +++ b/boards/nucleo-f091/Makefile.features @@ -1,6 +1,7 @@ # Put defined MCU peripherals here (in alphabetical order) FEATURES_PROVIDED += periph_adc FEATURES_PROVIDED += periph_cpuid +FEATURES_PROVIDED += periph_flashpage FEATURES_PROVIDED += periph_gpio FEATURES_PROVIDED += periph_pwm FEATURES_PROVIDED += periph_rtc diff --git a/boards/nucleo-f103/Makefile.features b/boards/nucleo-f103/Makefile.features index 0cdc59f99c96bd269cd80fd8643828dc75b771ba..d1facda2922226cc652f01a7d401668e55ced683 100755 --- a/boards/nucleo-f103/Makefile.features +++ b/boards/nucleo-f103/Makefile.features @@ -1,5 +1,6 @@ # Put defined MCU peripherals here (in alphabetical order) FEATURES_PROVIDED += periph_cpuid +FEATURES_PROVIDED += periph_flashpage FEATURES_PROVIDED += periph_gpio FEATURES_PROVIDED += periph_i2c FEATURES_PROVIDED += periph_spi diff --git a/boards/stm32f0discovery/Makefile.features b/boards/stm32f0discovery/Makefile.features index c5fce98a77f9ed9399084cabf16e7fb6690a27cb..84b33edae3492113c95f85467454ac1071f00332 100644 --- a/boards/stm32f0discovery/Makefile.features +++ b/boards/stm32f0discovery/Makefile.features @@ -1,6 +1,7 @@ # Put defined MCU peripherals here (in alphabetical order) FEATURES_PROVIDED += periph_adc FEATURES_PROVIDED += periph_cpuid +FEATURES_PROVIDED += periph_flashpage FEATURES_PROVIDED += periph_gpio FEATURES_PROVIDED += periph_spi FEATURES_PROVIDED += periph_timer diff --git a/cpu/stm32f0/periph/flashpage.c b/cpu/stm32_common/periph/flashpage.c similarity index 94% rename from cpu/stm32f0/periph/flashpage.c rename to cpu/stm32_common/periph/flashpage.c index 1e708a2b23d0f0be35e8d42fd20c21214b9c4fcc..66ac456b130225ef5f21cdb0883e947c5363b378 100644 --- a/cpu/stm32f0/periph/flashpage.c +++ b/cpu/stm32_common/periph/flashpage.c @@ -7,7 +7,7 @@ */ /** - * @ingroup cpu_stm32f0 + * @ingroup cpu_stm32_common * @{ * * @file @@ -20,11 +20,13 @@ #include "cpu.h" #include "assert.h" -#include "periph/flashpage.h" #define ENABLE_DEBUG (0) #include "debug.h" +#if defined(FLASHPAGE_SIZE) && defined(FLASHPAGE_NUMOF) +#include "periph/flashpage.h" + void flashpage_write(int page, void *data) { assert(page < FLASHPAGE_NUMOF); @@ -86,3 +88,5 @@ void flashpage_write(int page, void *data) while (RCC->CR & RCC_CR_HSIRDY) {} } } + +#endif /* defined(FLASHPAGE_SIZE) && defined(FLASHPAGE_NUMOF) */ diff --git a/cpu/stm32f1/periph/flashpage.c b/cpu/stm32f1/periph/flashpage.c deleted file mode 100644 index 3658999e62bedd5005eab92963d84693345f8b1a..0000000000000000000000000000000000000000 --- a/cpu/stm32f1/periph/flashpage.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2016 Freie Universität Berlin - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @ingroup cpu_stm32f1 - * @{ - * - * @file - * @brief Low-level flash page driver implementation - * - * @author Hauke Petersen <hauke.petersen@fu-berlin.de> - * - * @} - */ - -#include "cpu.h" -#include "assert.h" -#include "periph/flashpage.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -void flashpage_write(int page, void *data) -{ - assert(page < FLASHPAGE_NUMOF); - - uint16_t *page_addr = flashpage_addr(page); - uint16_t *data_addr = (uint16_t *)data; - uint32_t hsi_state = (RCC->CR & RCC_CR_HSION); - - /* the internal RC oscillator (HSI) must be enabled */ - RCC->CR |= (RCC_CR_HSION); - while (!(RCC->CR & RCC_CR_HSIRDY)) {} - - /* unlock the flash module */ - DEBUG("[flashpage] unlocking the flash module\n"); - if (FLASH->CR & FLASH_CR_LOCK) { - FLASH->KEYR = FLASH_KEY1; - FLASH->KEYR = FLASH_KEY2; - } - - /* ERASE sequence */ - /* make sure no flash operation is ongoing */ - DEBUG("[flashpage] erase: waiting for any operation to finish\n"); - while (FLASH->SR & FLASH_SR_BSY) {} - /* set page erase bit and program page address */ - DEBUG("[flashpage] erase: setting the erase bit and page address\n"); - FLASH->CR |= FLASH_CR_PER; - FLASH->AR = (uint32_t)flashpage_addr(page); - DEBUG("address to erase: %p\n", flashpage_addr(page)); - /* trigger the page erase and wait for it to be finished */ - DEBUG("[flashpage] erase: trigger the page erase\n"); - FLASH->CR |= FLASH_CR_STRT; - DEBUG("[flashpage] erase: wait as long as device is busy\n"); - while (FLASH->SR & FLASH_SR_BSY) {} - /* reset PER bit */ - DEBUG("[flashpage] erase: resetting the page erase bit\n"); - FLASH->CR &= ~(FLASH_CR_PER); - - /* WRITE sequence */ - if (data != NULL) { - DEBUG("[flashpage] write: now writing the data\n"); - /* set PG bit and program page to flash */ - FLASH->CR |= FLASH_CR_PG; - for (unsigned i = 0; i < (FLASHPAGE_SIZE / 2); i++) { - *page_addr++ = data_addr[i]; - while (FLASH->SR & FLASH_SR_BSY) {} - } - /* clear program bit again */ - FLASH->CR &= ~(FLASH_CR_PG); - DEBUG("[flashpage] write: done writing data\n"); - } - - /* finally, lock the flash module again */ - DEBUG("flashpage] now locking the flash module again\n"); - FLASH->CR |= FLASH_CR_LOCK; - - /* restore the HSI state */ - if (!hsi_state) { - RCC->CR &= ~(RCC_CR_HSION); - while (RCC->CR & RCC_CR_HSIRDY) {} - } -}