Skip to content

Commit 43f5a18

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

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/periph_flashpage/main.c

Lines changed: 40 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,38 @@ 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_res(int argc, char **argv)
378+
{
379+
(void) argc;
380+
(void) argv;
381+
382+
char fill = 'a';
383+
unsigned page = flashpage_page((void *)_backing_memory);
384+
385+
printf("Reserved page num: %u \n", page);
386+
387+
for (unsigned i = 0; i < sizeof(page_mem); i++) {
388+
page_mem[i] = (uint8_t)fill++;
389+
if (fill > 'z') {
390+
fill = 'a';
391+
}
392+
}
393+
394+
if (flashpage_write_and_verify(page, page_mem) != FLASHPAGE_OK) {
395+
puts("error verifying the content of reserved page");
396+
return 1;
397+
}
398+
399+
puts("wrote local page buffer to reserved flash page");
400+
puts("wrote local page buffer to reserved flash page");
401+
puts("\nWhen running on a bootloader, as an extra check, try restarting "
402+
"the board and check whether this application still comes up.");
403+
return 0;
404+
}
366405
#endif
367406

368407
/**
@@ -643,6 +682,7 @@ static const shell_command_t shell_commands[] = {
643682
{ "edit", "Write bytes to the local page buffer", cmd_edit },
644683
{ "test", "Write and verify test pattern", cmd_test },
645684
{ "test_last_pagewise", "Write and verify test pattern on last page available", cmd_test_last },
685+
{ "test_res_pagewise", "Write and verify short write on reserved page", cmd_test_res},
646686
#endif
647687
{ "test_last_raw", "Write and verify raw short write on last page available", cmd_test_last_raw },
648688
#ifdef FLASHPAGE_RWWEE_NUMOF

0 commit comments

Comments
 (0)