Skip to content

Commit

Permalink
tests/periph_flashpage: respect FLASHPAGE_WRITE_BLOCK_SIZE
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Apr 29, 2021
1 parent 51d2dac commit c7c4d75
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tests/periph_flashpage/main.c
Expand Up @@ -40,10 +40,18 @@

/* When writing raw bytes on flash, data must be correctly aligned. */
#define ALIGNMENT_ATTR __attribute__((aligned(FLASHPAGE_WRITE_BLOCK_ALIGNMENT)))

/* We must not write chunks smaller than FLASHPAGE_WRITE_BLOCK_SIZE */
#if FLASHPAGE_WRITE_BLOCK_SIZE > 64
#define RAW_BUF_SIZE FLASHPAGE_WRITE_BLOCK_SIZE
#else
#define RAW_BUF_SIZE 64
#endif

/*
* @brief Allocate an aligned buffer for raw writings
*/
static char raw_buf[64] ALIGNMENT_ATTR;
static char raw_buf[RAW_BUF_SIZE] ALIGNMENT_ATTR;

#ifdef MODULE_PERIPH_FLASHPAGE_PAGEWISE
/**
Expand Down Expand Up @@ -373,6 +381,8 @@ static int cmd_test_last_raw(int argc, char **argv)
(void) argc;
(void) argv;

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

/* try to align */
memcpy(raw_buf, "test12344321tset", 16);
#if defined(CPU_CC430) || defined(CPU_MSP430FXYZ)
Expand All @@ -382,7 +392,7 @@ static int cmd_test_last_raw(int argc, char **argv)
/* erase the page first */
flashpage_erase(TEST_LAST_AVAILABLE_PAGE);

flashpage_write(flashpage_addr(TEST_LAST_AVAILABLE_PAGE), raw_buf, strlen(raw_buf));
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) {
Expand Down

0 comments on commit c7c4d75

Please sign in to comment.