diff --git a/tests/periph_flashpage/Makefile b/tests/periph_flashpage/Makefile index 746a26411b15026f340deb193d416e66af00c1a4..6307181d9855266492d4a4c61814c9c57307366b 100644 --- a/tests/periph_flashpage/Makefile +++ b/tests/periph_flashpage/Makefile @@ -2,7 +2,8 @@ APPLICATION = periph_flashpage BOARD ?= iotlab-m3 include ../Makefile.tests_common -FEATURES_REQUIRED = periph_flashpage +FEATURES_REQUIRED += periph_flashpage +FEATURES_OPTIONAL += periph_flashpage_raw USEMODULE += shell diff --git a/tests/periph_flashpage/main.c b/tests/periph_flashpage/main.c index df99d946ef6e58208bf357c4bc859b109adb54ad..b7a901f3eecdd8642324dc9b521d9b0ad9cf25de 100644 --- a/tests/periph_flashpage/main.c +++ b/tests/periph_flashpage/main.c @@ -32,6 +32,20 @@ */ static uint8_t page_mem[FLASHPAGE_SIZE]; +#ifdef MODULE_PERIPH_FLASHPAGE_RAW +/* + * @brief Allocate an aligned buffer for raw writings + */ +static char raw_buf[64] __attribute__ ((aligned (FLASHPAGE_RAW_ALIGNMENT))); + +static uint32_t getaddr(const char *str) +{ + uint32_t addr = strtol(str, NULL, 16); + + return addr; +} +#endif + static int getpage(const char *str) { int page = atoi(str); @@ -164,6 +178,29 @@ static int cmd_write(int argc, char **argv) return 0; } +#ifdef MODULE_PERIPH_FLASHPAGE_RAW +static int cmd_write_raw(int argc, char **argv) +{ + uint32_t addr; + + if (argc < 3) { + printf("usage: %s <addr> <data>\n", argv[0]); + return 1; + } + + addr = getaddr(argv[1]); + + /* try to align */ + memcpy(raw_buf, argv[2], strlen(argv[2])); + + flashpage_write_raw((void*)addr, raw_buf, strlen(raw_buf)); + + printf("wrote local data to flash address %#lx of len %u\n", + addr, strlen(raw_buf)); + return 0; +} +#endif + static int cmd_erase(int argc, char **argv) { int page; @@ -248,6 +285,9 @@ static const shell_command_t shell_commands[] = { { "dump_local", "Dump the local page buffer to STDOUT", cmd_dump_local }, { "read", "Read and output the given page", cmd_read }, { "write", "Write (ASCII) data to the given page", cmd_write }, +#ifdef MODULE_PERIPH_FLASHPAGE_RAW + { "write_raw", "Write (ASCII, max 64B) data to the given address", cmd_write_raw }, +#endif { "erase", "Erase the given page", cmd_erase }, { "edit", "Write bytes to the local page", cmd_edit }, { "test", "Write and verify test pattern", cmd_test },