Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/periph/flashpage: make mtd_raw command write bytes instead of ASCII #20177

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions tests/periph/flashpage/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

#include "architecture.h"
#include "od.h"
#include "shell.h"
#include "periph/flashpage.h"
#include "unaligned.h"
#include "fmt.h"

#define LINE_LEN (16)

Expand All @@ -53,7 +55,7 @@
/*
* @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
/**
Expand Down Expand Up @@ -92,7 +94,7 @@
#ifdef MODULE_PERIPH_FLASHPAGE_PAGEWISE
static void memdump(void *addr, size_t len)
{
od_hex_dump (addr, len, LINE_LEN);

Check warning on line 97 in tests/periph/flashpage/main.c

View workflow job for this annotation

GitHub Actions / static-tests

horizontal tab used
}

static void dump_local(void)
Expand Down Expand Up @@ -221,17 +223,29 @@
uintptr_t addr;

if (argc < 3) {
printf("usage: %s <addr> <data>\n", argv[0]);
printf("usage: %s <addr> <hexadecimal data>\n", argv[0]);
return 1;
}

addr = getaddr(argv[1]);
/* 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) {
Teufelchen1 marked this conversation as resolved.
Show resolved Hide resolved
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));
printf("wrote local data to flash address %#" PRIxPTR " of len %" PRIuSIZE "\n",
addr, strlen(raw_buf));
flashpage_write((void*)(uintptr_t)addr, raw_buf, len);
printf("wrote local data to flash address %#" PRIxPTR " of len %d\n",
addr, len);
return 0;
}

Expand Down Expand Up @@ -414,7 +428,7 @@
(void) argc;
(void) argv;

memset(raw_buf, 0, sizeof(raw_buf));
memset(raw_buf, 0xff, sizeof(raw_buf));

/* try to align */
memcpy(raw_buf, "test12344321tset", 16);
Expand All @@ -428,7 +442,7 @@
flashpage_write(flashpage_addr(TEST_LAST_AVAILABLE_PAGE), raw_buf, sizeof(raw_buf));

/* 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) {
Teufelchen1 marked this conversation as resolved.
Show resolved Hide resolved
puts("error verifying the content of last page");
return 1;
}
Expand Down Expand Up @@ -509,7 +523,7 @@
return 1;
}

fill += (page % ('z' - 'a')); // Make each page slightly different by changing starting char for easier comparison by eye

Check warning on line 526 in tests/periph/flashpage/main.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters

for (unsigned i = 0; i < sizeof(page_mem); i++) {
page_mem[i] = (uint8_t)fill++;
Expand Down Expand Up @@ -548,7 +562,7 @@
}
}

if (flashpage_rwwee_write_and_verify((int)FLASHPAGE_RWWEE_NUMOF - 1, page_mem) != FLASHPAGE_OK) {

Check warning on line 565 in tests/periph/flashpage/main.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
puts("error verifying the content of last RWWEE page");
return 1;
}
Expand All @@ -575,10 +589,10 @@
/* erase the page first */
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 */
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");
return 1;
}
Expand Down Expand Up @@ -634,7 +648,7 @@
/* check if the AUX page has been cleared */
for (uint32_t i = 0; i < FLASH_USER_PAGE_AUX_SIZE; ++i) {
if (*(uint8_t*)sam0_flashpage_aux_get(i) != 0xFF) {
printf("dst_offset=%"PRIu32": user page not cleared at offset 0x%"PRIx32"\n", dst_offset, i);

Check warning on line 651 in tests/periph/flashpage/main.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
return -1;
}
}
Expand All @@ -648,13 +662,13 @@
/* check if half-word was written correctly */
uint16_t data_in = unaligned_get_u16(sam0_flashpage_aux_get(dst + sizeof(test_data)));
if (data_in != single_data) {
printf("dst_offset=%"PRIu32": %x != %x, offset = 0x%"PRIx32"\n", dst_offset, single_data, data_in, dst + sizeof(test_data));

Check warning on line 665 in tests/periph/flashpage/main.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
return -1;
}

/* check if test data was written correctly */
if (memcmp(sam0_flashpage_aux_get(dst), test_data, sizeof(test_data))) {
printf("dst_offset=%"PRIu32": write test_data failed, offset = 0x%"PRIx32"\n", dst_offset, dst);

Check warning on line 671 in tests/periph/flashpage/main.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
return -1;
}
}
Expand All @@ -673,7 +687,7 @@
{ "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 },
#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 },
#ifdef MODULE_PERIPH_FLASHPAGE_PAGEWISE
{ "edit", "Write bytes to the local page buffer", cmd_edit },
Expand All @@ -683,13 +697,13 @@
#ifdef MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE
{ "test_reserved_pagewise", "Write and verify short write on reserved page", cmd_test_reserved},
#endif
{ "test_last_raw", "Write and verify raw short write on last page available", cmd_test_last_raw },

Check warning on line 700 in tests/periph/flashpage/main.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
#ifdef FLASHPAGE_RWWEE_NUMOF
{ "read_rwwee", "Copy the given page from RWWEE to the local page buffer and dump to STDOUT", cmd_read_rwwee },

Check warning on line 702 in tests/periph/flashpage/main.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
{ "write_rwwee", "Write the local page buffer to the given RWWEE page", cmd_write_rwwee },
{ "test_rwwee", "Write and verify test pattern to RWWEE", cmd_test_rwwee },
{ "test_last_rwwee", "Write and verify test pattern on last RWWEE page available", cmd_test_last_rwwee },

Check warning on line 705 in tests/periph/flashpage/main.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
{ "test_last_rwwee_raw", "Write and verify raw short write on last RWWEE page available", cmd_test_last_rwwee_raw },

Check warning on line 706 in tests/periph/flashpage/main.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
#endif
#ifdef NVMCTRL_USER
{ "dump_config_page", "Dump the content of the MCU configuration page", cmd_dump_config },
Expand Down
Loading