From ebe4fc0bc152b00231cfd55376e997b2bd47ffbe Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Sat, 23 Jan 2021 23:34:24 +0100 Subject: [PATCH] tests/mtd_raw: include mtd_write_page() in test --- tests/mtd_raw/Makefile | 1 + tests/mtd_raw/main.c | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/tests/mtd_raw/Makefile b/tests/mtd_raw/Makefile index bea9c1e940..260e1ab0fd 100644 --- a/tests/mtd_raw/Makefile +++ b/tests/mtd_raw/Makefile @@ -5,5 +5,6 @@ USEMODULE += shell_commands USEMODULE += od USEMODULE += mtd +USEMODULE += mtd_write_page include $(RIOTBASE)/Makefile.include diff --git a/tests/mtd_raw/main.c b/tests/mtd_raw/main.c index e9d8f25d9f..3b9778c6b6 100644 --- a/tests/mtd_raw/main.c +++ b/tests/mtd_raw/main.c @@ -173,13 +173,13 @@ static int cmd_write(int argc, char **argv) return res; } -static int cmd_write_page(int argc, char **argv) +static int cmd_write_page_raw(int argc, char **argv) { mtd_dev_t *dev = _get_dev(argc, argv); uint32_t page, offset, len; if (argc < 5 || dev == NULL) { - printf("usage: %s \n", argv[0]); + printf("usage: %s \n", argv[0]); return -1; } @@ -196,6 +196,29 @@ static int cmd_write_page(int argc, char **argv) return res; } +static int cmd_write_page(int argc, char **argv) +{ + mtd_dev_t *dev = _get_dev(argc, argv); + uint32_t page, offset, len; + + if (argc < 5 || dev == NULL) { + printf("usage: %s \n", argv[0]); + return -1; + } + + page = atoi(argv[2]); + offset = atoi(argv[3]); + len = strlen(argv[4]); + + int res = mtd_write_page(dev, argv[4], page, offset, len); + + if (res) { + printf("error: %i\n", res); + } + + return res; +} + static int cmd_erase(int argc, char **argv) { mtd_dev_t *dev = _get_dev(argc, argv); @@ -409,7 +432,7 @@ static int cmd_test(int argc, char **argv) /* overwrite first test string, rely on MTD for read-modify-write */ const char test_str_2[] = "Hello World!"; offset = 5; - assert(mtd_write_page_hl(dev, test_str_2, page_0, offset, sizeof(test_str_2)) == 0); + assert(mtd_write_page(dev, test_str_2, page_0, offset, sizeof(test_str_2)) == 0); assert(mtd_read_page(dev, buffer, page_0, offset, sizeof(test_str_2)) == 0); assert(memcmp(test_str_2, buffer, sizeof(test_str_2)) == 0); @@ -426,7 +449,12 @@ static const shell_command_t shell_commands[] = { { "read", "Read a region of memory on the MTD device", cmd_read }, { "read_page", "Read a region of memory on the MTD device (pagewise addressing)", cmd_read_page }, { "write", "Write a region of memory on the MTD device", cmd_write }, - { "write_page", "Write a region of memory on the MTD device (pagewise addressing)", cmd_write_page }, + { "write_page_raw", + "Write a region of memory on the MTD device (pagewise addressing)", + cmd_write_page_raw }, + { "write_page", + "Write a region of memory on the MTD device (pagewise addressing, read-modify-write)", + cmd_write_page }, { "erase", "Erase a region of memory on the MTD device", cmd_erase }, { "erase_sector", "Erase a sector of memory on the MTD device", cmd_erase_sector }, { "test", "Erase & write test data to the last two sectors", cmd_test },