Skip to content

Commit 1b046de

Browse files
committed
tests/periph_flashpage: test reserving of flash memory
1 parent a2f9d2e commit 1b046de

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

tests/periph_flashpage/main.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ static char raw_buf[RAW_BUF_SIZE] ALIGNMENT_ATTR;
5555
* requires 64 bit alignment.
5656
*/
5757
static uint8_t page_mem[FLASHPAGE_SIZE] ALIGNMENT_ATTR;
58+
59+
/**
60+
* @brief Reserve 1 page of flash memory
61+
*/
62+
static const uint8_t _backing_memory[FLASHPAGE_SIZE]
63+
__attribute__((aligned(FLASHPAGE_SIZE)))
64+
__attribute__((section(".flash_writable")));
5865
#endif
5966

6067
static int getpage(const char *str)
@@ -363,6 +370,53 @@ static int cmd_test_last(int argc, char **argv)
363370
puts("wrote local page buffer to last flash page");
364371
return 0;
365372
}
373+
374+
/**
375+
* @brief Does a write and verify test on reserved page
376+
*/
377+
static int cmd_test_reserved(int argc, char **argv)
378+
{
379+
(void) argc;
380+
(void) argv;
381+
382+
char fill = 'a';
383+
const char sig[] = {"RIOT"};
384+
unsigned page = flashpage_page((void *)_backing_memory);
385+
386+
printf("Reserved page num: %u \n", page);
387+
388+
flashpage_read(page, page_mem);
389+
390+
// test is running for the first time so initialize flash
391+
if (memcmp(sig, &page_mem[1], sizeof(sig) - 1) != 0) {
392+
page_mem[0] = 0;
393+
memcpy(&page_mem[1], sig, sizeof(sig));
394+
}
395+
else {
396+
page_mem[0]++;
397+
}
398+
399+
printf("Since the last firmware update this test has been run "
400+
"%u times \n", page_mem[0]);
401+
402+
for (unsigned i = sizeof(sig); i < sizeof(page_mem); i++) {
403+
page_mem[i] = (uint8_t)fill++;
404+
if (fill > 'z') {
405+
fill = 'a';
406+
}
407+
}
408+
409+
if (flashpage_write_and_verify(page, page_mem) != FLASHPAGE_OK) {
410+
puts("error verifying the content of reserved page");
411+
return 1;
412+
}
413+
414+
puts("wrote local page buffer to reserved flash page");
415+
puts("\nWhen running on a bootloader, as an extra check, try restarting "
416+
"the board and check whether this application still comes up.");
417+
418+
return 0;
419+
}
366420
#endif
367421

368422
/**
@@ -643,6 +697,7 @@ static const shell_command_t shell_commands[] = {
643697
{ "edit", "Write bytes to the local page buffer", cmd_edit },
644698
{ "test", "Write and verify test pattern", cmd_test },
645699
{ "test_last_pagewise", "Write and verify test pattern on last page available", cmd_test_last },
700+
{ "test_reserved_pagewise", "Write and verify short write on reserved page", cmd_test_reserved},
646701
#endif
647702
{ "test_last_raw", "Write and verify raw short write on last page available", cmd_test_last_raw },
648703
#ifdef FLASHPAGE_RWWEE_NUMOF

tests/periph_flashpage/tests/01-run.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ def testfunc(child):
2929
child.expect_exact('wrote local page buffer to last flash page')
3030
child.expect('>')
3131

32+
# check if board has flash page reservation capability and if so test that as well
33+
# capability is deduced from help contents
34+
child.sendline("help")
35+
index = child.expect(['test_reserved_pagewise', '>'])
36+
if index == 0:
37+
child.sendline("test_reserved_pagewise")
38+
child.expect_exact('wrote local page buffer to reserved flash page')
39+
child.expect('>')
40+
3241
# check if board has RWWEE capability and if so test that as well
3342
# capability is deduced from help contents
3443
child.sendline("help")

0 commit comments

Comments
 (0)