mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests/periph/flashpage: make mtd_raw write bytes instead of ASCII
This commit is contained in:
parent
a5996e22b8
commit
629c0c2f1a
@ -23,12 +23,14 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "architecture.h"
|
#include "architecture.h"
|
||||||
#include "od.h"
|
#include "od.h"
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
#include "periph/flashpage.h"
|
#include "periph/flashpage.h"
|
||||||
#include "unaligned.h"
|
#include "unaligned.h"
|
||||||
|
#include "fmt.h"
|
||||||
|
|
||||||
#define LINE_LEN (16)
|
#define LINE_LEN (16)
|
||||||
|
|
||||||
@ -53,7 +55,7 @@
|
|||||||
/*
|
/*
|
||||||
* @brief Allocate an aligned buffer for raw writings
|
* @brief Allocate an aligned buffer for raw writings
|
||||||
*/
|
*/
|
||||||
static char raw_buf[RAW_BUF_SIZE] ALIGNMENT_ATTR;
|
static uint8_t raw_buf[RAW_BUF_SIZE] ALIGNMENT_ATTR;
|
||||||
|
|
||||||
#ifdef MODULE_PERIPH_FLASHPAGE_PAGEWISE
|
#ifdef MODULE_PERIPH_FLASHPAGE_PAGEWISE
|
||||||
/**
|
/**
|
||||||
@ -221,17 +223,29 @@ static int cmd_write_raw(int argc, char **argv)
|
|||||||
uintptr_t addr;
|
uintptr_t addr;
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
printf("usage: %s <addr> <data>\n", argv[0]);
|
printf("usage: %s <addr> <hexadecimal data>\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
addr = getaddr(argv[1]);
|
addr = getaddr(argv[1]);
|
||||||
/* try to align */
|
/* try to align */
|
||||||
memcpy(raw_buf, argv[2], strlen(argv[2]));
|
int len;
|
||||||
|
if ((len = strlen(argv[2])) % 2 || (unsigned)len > sizeof(raw_buf) * 2) {
|
||||||
|
printf("error: data must have an even length and must be <= %"PRIuSIZE"\n",
|
||||||
|
sizeof(raw_buf) * 2);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
if (!isxdigit((int)(argv[2][i]))) {
|
||||||
|
printf("error: data must be hexadecimal\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
len = fmt_hex_bytes(raw_buf, argv[2]);
|
||||||
|
|
||||||
flashpage_write((void*)(uintptr_t)addr, raw_buf, strlen(raw_buf));
|
flashpage_write((void*)(uintptr_t)addr, raw_buf, len);
|
||||||
printf("wrote local data to flash address %#" PRIxPTR " of len %" PRIuSIZE "\n",
|
printf("wrote local data to flash address %#" PRIxPTR " of len %d\n",
|
||||||
addr, strlen(raw_buf));
|
addr, len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,7 +428,7 @@ static int cmd_test_last_raw(int argc, char **argv)
|
|||||||
(void) argc;
|
(void) argc;
|
||||||
(void) argv;
|
(void) argv;
|
||||||
|
|
||||||
memset(raw_buf, 0, sizeof(raw_buf));
|
memset(raw_buf, 0xff, sizeof(raw_buf));
|
||||||
|
|
||||||
/* try to align */
|
/* try to align */
|
||||||
memcpy(raw_buf, "test12344321tset", 16);
|
memcpy(raw_buf, "test12344321tset", 16);
|
||||||
@ -428,7 +442,7 @@ static int cmd_test_last_raw(int argc, char **argv)
|
|||||||
flashpage_write(flashpage_addr(TEST_LAST_AVAILABLE_PAGE), raw_buf, sizeof(raw_buf));
|
flashpage_write(flashpage_addr(TEST_LAST_AVAILABLE_PAGE), raw_buf, sizeof(raw_buf));
|
||||||
|
|
||||||
/* verify that previous write_raw effectively wrote the desired data */
|
/* verify that previous write_raw effectively wrote the desired data */
|
||||||
if (memcmp(flashpage_addr(TEST_LAST_AVAILABLE_PAGE), raw_buf, strlen(raw_buf)) != 0) {
|
if (memcmp(flashpage_addr(TEST_LAST_AVAILABLE_PAGE), raw_buf, 16) != 0) {
|
||||||
puts("error verifying the content of last page");
|
puts("error verifying the content of last page");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -575,10 +589,10 @@ static int cmd_test_last_rwwee_raw(int argc, char **argv)
|
|||||||
/* erase the page first */
|
/* erase the page first */
|
||||||
flashpage_rwwee_write_page(((int)FLASHPAGE_RWWEE_NUMOF - 1), NULL);
|
flashpage_rwwee_write_page(((int)FLASHPAGE_RWWEE_NUMOF - 1), NULL);
|
||||||
|
|
||||||
flashpage_rwwee_write(flashpage_rwwee_addr((int)FLASHPAGE_RWWEE_NUMOF - 1), raw_buf, strlen(raw_buf));
|
flashpage_rwwee_write(flashpage_rwwee_addr((int)FLASHPAGE_RWWEE_NUMOF - 1), raw_buf, 16);
|
||||||
|
|
||||||
/* verify that previous write_raw effectively wrote the desired data */
|
/* verify that previous write_raw effectively wrote the desired data */
|
||||||
if (memcmp(flashpage_rwwee_addr((int)FLASHPAGE_RWWEE_NUMOF - 1), raw_buf, strlen(raw_buf)) != 0) {
|
if (memcmp(flashpage_rwwee_addr((int)FLASHPAGE_RWWEE_NUMOF - 1), raw_buf, 16) != 0) {
|
||||||
puts("error verifying the content of last RWWEE page");
|
puts("error verifying the content of last RWWEE page");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -673,7 +687,7 @@ static const shell_command_t shell_commands[] = {
|
|||||||
{ "read", "Copy the given page to the local page buffer and dump to STDOUT", cmd_read },
|
{ "read", "Copy the given page to the local page buffer and dump to STDOUT", cmd_read },
|
||||||
{ "write", "Write the local page buffer to the given page", cmd_write },
|
{ "write", "Write the local page buffer to the given page", cmd_write },
|
||||||
#endif
|
#endif
|
||||||
{ "write_raw", "Write (ASCII, max 64B) data to the given address", cmd_write_raw },
|
{ "write_raw", "Write raw bytes (max 64B) to the given address", cmd_write_raw },
|
||||||
{ "erase", "Erase the given page buffer", cmd_erase },
|
{ "erase", "Erase the given page buffer", cmd_erase },
|
||||||
#ifdef MODULE_PERIPH_FLASHPAGE_PAGEWISE
|
#ifdef MODULE_PERIPH_FLASHPAGE_PAGEWISE
|
||||||
{ "edit", "Write bytes to the local page buffer", cmd_edit },
|
{ "edit", "Write bytes to the local page buffer", cmd_edit },
|
||||||
|
Loading…
Reference in New Issue
Block a user