Skip to content

Commit cdde810

Browse files
committed
tests/periph_flashpage: Add _in_address_space feature tests
1 parent 6ab1fb9 commit cdde810

File tree

4 files changed

+85
-2
lines changed

4 files changed

+85
-2
lines changed

tests/periph_flashpage/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
config APPLICATION
99
bool
1010
default y
11+
imply MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE
1112
imply MODULE_PERIPH_FLASHPAGE_PAGEWISE
1213
imply MODULE_PERIPH_FLASHPAGE_RWEE
1314
depends on TEST_KCONFIG

tests/periph_flashpage/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ BOARD ?= iotlab-m3
22
include ../Makefile.tests_common
33

44
FEATURES_REQUIRED += periph_flashpage
5+
FEATURES_OPTIONAL += periph_flashpage_in_address_space
56
FEATURES_OPTIONAL += periph_flashpage_pagewise
67
FEATURES_OPTIONAL += periph_flashpage_rwee
78

tests/periph_flashpage/main.c

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @}
1919
*/
2020

21+
#include <assert.h>
2122
#include <inttypes.h>
2223
#include <stdio.h>
2324
#include <string.h>
@@ -55,7 +56,19 @@ static char raw_buf[RAW_BUF_SIZE] ALIGNMENT_ATTR;
5556
* requires 64 bit alignment.
5657
*/
5758
static uint8_t page_mem[FLASHPAGE_SIZE] ALIGNMENT_ATTR;
58-
#endif
59+
60+
#ifdef MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE
61+
/**
62+
* @brief Reserve 1 page of flash memory
63+
*/
64+
FLASH_WRITABLE_INIT(_backing_memory, 0x1);
65+
66+
/*
67+
* @brief Created to test the sorting of symbols in .flash_writable section
68+
*/
69+
FLASH_WRITABLE_INIT(_abacking_memory, 0x1);
70+
#endif /* MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE */
71+
#endif /* MODULE_PERIPH_FLASHPAGE_PAGEWISE */
5972

6073
static int getpage(const char *str)
6174
{
@@ -363,7 +376,63 @@ static int cmd_test_last(int argc, char **argv)
363376
puts("wrote local page buffer to last flash page");
364377
return 0;
365378
}
366-
#endif
379+
380+
#ifdef MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE
381+
/**
382+
* @brief Does a write and verify test on reserved page
383+
*/
384+
static int cmd_test_reserved(int argc, char **argv)
385+
{
386+
(void) argc;
387+
(void) argv;
388+
389+
/**
390+
* Arrays created by the FLASH_WRITABLE_INIT macro should be sorted in
391+
* ascending order by name.
392+
*/
393+
assert(&_abacking_memory < &_backing_memory);
394+
395+
char fill = 'a';
396+
const char sig[] = {"RIOT"};
397+
unsigned page = flashpage_page((void *)_backing_memory);
398+
399+
printf("Reserved page num: %u \n", page);
400+
401+
flashpage_read(page, page_mem);
402+
403+
/* test is running for the first time so initialize flash */
404+
if (memcmp(sig, &page_mem[1], sizeof(sig)) != 0) {
405+
page_mem[0] = 0;
406+
memcpy(&page_mem[1], sig, sizeof(sig));
407+
}
408+
else {
409+
page_mem[0]++;
410+
}
411+
412+
printf("Since the last firmware update this test has been run "
413+
"%u times \n", page_mem[0]);
414+
415+
/* fill memory after counter and signature */
416+
for (unsigned i = 0x1 + sizeof(sig); i < sizeof(page_mem); i++) {
417+
page_mem[i] = (uint8_t)fill++;
418+
if (fill > 'z') {
419+
fill = 'a';
420+
}
421+
}
422+
423+
if (flashpage_write_and_verify(page, page_mem) != FLASHPAGE_OK) {
424+
puts("error verifying the content of reserved page");
425+
return 1;
426+
}
427+
428+
puts("wrote local page buffer to reserved flash page");
429+
puts("\nWhen running on a bootloader, as an extra check, try restarting "
430+
"the board and check whether this application still comes up.");
431+
432+
return 0;
433+
}
434+
#endif /* MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE */
435+
#endif /* MODULE_PERIPH_FLASHPAGE_PAGEWISE */
367436

368437
/**
369438
* @brief Does a short raw write on last page available
@@ -643,6 +712,9 @@ static const shell_command_t shell_commands[] = {
643712
{ "edit", "Write bytes to the local page buffer", cmd_edit },
644713
{ "test", "Write and verify test pattern", cmd_test },
645714
{ "test_last_pagewise", "Write and verify test pattern on last page available", cmd_test_last },
715+
#endif
716+
#ifdef MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE
717+
{ "test_reserved_pagewise", "Write and verify short write on reserved page", cmd_test_reserved},
646718
#endif
647719
{ "test_last_raw", "Write and verify raw short write on last page available", cmd_test_last_raw },
648720
#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)