diff --git a/boards/msb-430/Makefile.features b/boards/msb-430/Makefile.features index 90ca83aa3e51aef31d3e8d65898e410442ab17e3..26fb1ac1bface41353ddf69d09ccf05fd791918c 100644 --- a/boards/msb-430/Makefile.features +++ b/boards/msb-430/Makefile.features @@ -1,7 +1,8 @@ # Put defined MCU peripherals here (in alphabetical order) +FEATURES_PROVIDED += periph_flashpage FEATURES_PROVIDED += periph_gpio -FEATURES_PROVIDED += periph_timer FEATURES_PROVIDED += periph_spi +FEATURES_PROVIDED += periph_timer FEATURES_PROVIDED += periph_uart # Various other features (if any) diff --git a/boards/msb-430h/Makefile.features b/boards/msb-430h/Makefile.features index b40f1768ead2a1da8867c183e4a9dd5968ef7990..a39b503f31153764abd29c23842df0f95f8c6618 100644 --- a/boards/msb-430h/Makefile.features +++ b/boards/msb-430h/Makefile.features @@ -1,5 +1,6 @@ # Put defined MCU peripherals here (in alphabetical order) FEATURES_PROVIDED += periph_gpio +FEATURES_PROVIDED += periph_flashpage FEATURES_PROVIDED += periph_spi FEATURES_PROVIDED += periph_timer FEATURES_PROVIDED += periph_uart diff --git a/boards/telosb/Makefile.features b/boards/telosb/Makefile.features index 57c25ac5c4d37eee1eb9ea71932d51fa4a0146c7..26fb1ac1bface41353ddf69d09ccf05fd791918c 100644 --- a/boards/telosb/Makefile.features +++ b/boards/telosb/Makefile.features @@ -1,4 +1,5 @@ # Put defined MCU peripherals here (in alphabetical order) +FEATURES_PROVIDED += periph_flashpage FEATURES_PROVIDED += periph_gpio FEATURES_PROVIDED += periph_spi FEATURES_PROVIDED += periph_timer diff --git a/boards/wsn430-v1_3b/Makefile.features b/boards/wsn430-v1_3b/Makefile.features index c3dad712131c133cfbcde0040068e8813e9f3420..d9b7460ec55da6690f2502617b307e5e0fa2a2e1 100644 --- a/boards/wsn430-v1_3b/Makefile.features +++ b/boards/wsn430-v1_3b/Makefile.features @@ -1,4 +1,5 @@ # Put defined MCU peripherals here (in alphabetical order) +FEATURES_PROVIDED += periph_flashpage FEATURES_PROVIDED += periph_gpio FEATURES_PROVIDED += periph_timer FEATURES_PROVIDED += periph_spi diff --git a/boards/wsn430-v1_4/Makefile.features b/boards/wsn430-v1_4/Makefile.features index c3dad712131c133cfbcde0040068e8813e9f3420..d9b7460ec55da6690f2502617b307e5e0fa2a2e1 100644 --- a/boards/wsn430-v1_4/Makefile.features +++ b/boards/wsn430-v1_4/Makefile.features @@ -1,4 +1,5 @@ # Put defined MCU peripherals here (in alphabetical order) +FEATURES_PROVIDED += periph_flashpage FEATURES_PROVIDED += periph_gpio FEATURES_PROVIDED += periph_timer FEATURES_PROVIDED += periph_spi diff --git a/boards/z1/Makefile.features b/boards/z1/Makefile.features index 57c25ac5c4d37eee1eb9ea71932d51fa4a0146c7..26fb1ac1bface41353ddf69d09ccf05fd791918c 100644 --- a/boards/z1/Makefile.features +++ b/boards/z1/Makefile.features @@ -1,4 +1,5 @@ # Put defined MCU peripherals here (in alphabetical order) +FEATURES_PROVIDED += periph_flashpage FEATURES_PROVIDED += periph_gpio FEATURES_PROVIDED += periph_spi FEATURES_PROVIDED += periph_timer diff --git a/cpu/msp430_common/Makefile.include b/cpu/msp430_common/Makefile.include index ca676e5065a9970e57ec2616e37d72c07d8fb826..ab6e0cf8c0d308b270fb348b28e8d16bb5a72b1e 100644 --- a/cpu/msp430_common/Makefile.include +++ b/cpu/msp430_common/Makefile.include @@ -1,7 +1,11 @@ INCLUDES += -I$(RIOTCPU)/msp430_common/include/ +# export the CPU model +MODEL = $(shell echo $(CPU_MODEL) | tr 'a-z' 'A-Z') +export CFLAGS += -DCPU_MODEL_$(MODEL) + export UNDEF += $(BINDIR)/msp430_common/startup.o -export USEMODULE += msp430_common msp430_common_periph +export USEMODULE += msp430_common msp430_common_periph periph_common DEFAULT_MODULE += oneway_malloc diff --git a/cpu/msp430_common/include/cpu_conf.h b/cpu/msp430_common/include/cpu_conf.h index 3bf046d1d2548b2a1bc0660b5bdd8c40467ebbcc..e76aa7b6bb8957e0a7184a21daf20045f5609f3a 100644 --- a/cpu/msp430_common/include/cpu_conf.h +++ b/cpu/msp430_common/include/cpu_conf.h @@ -14,7 +14,28 @@ extern "C" { #endif /** - * @name Kernel configuration + * @name Configure the internal flash memory + * @{ + */ +#define FLASHPAGE_SIZE (512) + +#if defined (CPU_MODEL_MSP430F1611) +#define CPU_FLASH_BASE (0x4000) +#define FLASHPAGE_NUMOF (96) /* 48K */ +#elif defined (CPU_MODEL_MSP430F1612) +#define CPU_FLASH_BASE (0x2600) +#define FLASHPAGE_NUMOF (110) /* 56K */ +#elif defined (CPU_MODEL_MSP430F2617) +#define CPU_FLASH_BASE (0x3100) +#define FLASHPAGE_NUMOF (128) /* we can currently only access 52K */ +#elif defined (CPU_MODEL_CC430F6137) +#define CPU_FLASH_BASE (0x8000) +#define FLASHPAGE_NUMOF (64) /* 32K */ +#endif +/** @} */ + +/** + * @name Kernel configuration * @{ */ #ifndef THREAD_EXTRA_STACKSIZE_PRINTF diff --git a/cpu/msp430_common/periph/flashpage.c b/cpu/msp430_common/periph/flashpage.c new file mode 100644 index 0000000000000000000000000000000000000000..27cc73e9cbf2f3b045cc2727da0fd6b7a1ac9b82 --- /dev/null +++ b/cpu/msp430_common/periph/flashpage.c @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2014 INRIA + * 2017 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_msp430fxyz + * @{ + * + * @file + * @brief Implementation of the peripheral flashpage interface + * + * @author Oliver Hahm <oliver.hahm@inria.fr> + * @author Hauke Petersen <hauke.petersen@fu-berlin.de> + * + * @} + */ + +#include "cpu.h" +#include "irq.h" +#include "periph/flashpage.h" + +void flashpage_write(int page, void *data) +{ + assert(page < FLASHPAGE_NUMOF); + + uint8_t *src = (uint8_t *)data; + uint8_t *dst = (uint8_t *)flashpage_addr(page); + unsigned istate; + + /* disable interrupts and unlock flash */ + istate = irq_disable(); + FCTL3 = FWKEY; + while (FCTL3 & BUSY) {} + + /* erase page */ + FCTL1 = (FWKEY | ERASE); + *dst = 0; /* erases the page */ + while (FCTL3 & BUSY) {} + + if (data) { + FCTL1 = (FWKEY | WRT); + for (unsigned i = 0; i < FLASHPAGE_SIZE; i++) { + *(dst++) = *(src++); + while (!(FCTL3 & WAIT)) {} + } + } + + /* lock flash and re-enable interrupts */ + FCTL1 = (FWKEY); + FCTL3 = (FWKEY | LOCK); + irq_restore(istate); +}