Skip to content

Commit

Permalink
tests/periph_flashpage: test reserving of flash memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Ollrogge committed Dec 27, 2021
1 parent 83d7978 commit efa2b4b
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/periph_flashpage/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ static char raw_buf[RAW_BUF_SIZE] ALIGNMENT_ATTR;
* requires 64 bit alignment.
*/
static uint8_t page_mem[FLASHPAGE_SIZE] ALIGNMENT_ATTR;

/**
* @brief Reserve 1 page of flash memory
*/
static const uint8_t _backing_memory[FLASHPAGE_SIZE]
__attribute__((aligned(FLASHPAGE_SIZE)))
__attribute__((section(".flash_writable")));
#endif

static int getpage(const char *str)
Expand Down Expand Up @@ -363,6 +370,35 @@ static int cmd_test_last(int argc, char **argv)
puts("wrote local page buffer to last flash page");
return 0;
}

/**
* @brief Does a write and verify test on reserved page
*/
static int cmd_test_res(int argc, char **argv)
{
(void) argc;
(void) argv;

char fill = 'a';
unsigned page = flashpage_page((void *)_backing_memory);

printf("Reserved page num: %u \n", page);

for (unsigned i = 0; i < sizeof(page_mem); i++) {
page_mem[i] = (uint8_t)fill++;
if (fill > 'z') {
fill = 'a';
}
}

if (flashpage_write_and_verify(page, page_mem) != FLASHPAGE_OK) {
puts("error verifying the content of reserved page");
return 1;
}

puts("wrote local page buffer to reserved flash page");
return 0;
}
#endif

/**
Expand Down Expand Up @@ -643,6 +679,7 @@ static const shell_command_t shell_commands[] = {
{ "edit", "Write bytes to the local page buffer", cmd_edit },
{ "test", "Write and verify test pattern", cmd_test },
{ "test_last_pagewise", "Write and verify test pattern on last page available", cmd_test_last },
{ "test_res_pagewise", "Write and verify short write on reserved page", cmd_test_res},
#endif
{ "test_last_raw", "Write and verify raw short write on last page available", cmd_test_last_raw },
#ifdef FLASHPAGE_RWWEE_NUMOF
Expand Down

0 comments on commit efa2b4b

Please sign in to comment.