Skip to content

Commit

Permalink
Revert "periph/flashpage: extend API"
Browse files Browse the repository at this point in the history
This reverts commit 72d4701.
  • Loading branch information
Ollrogge committed Apr 4, 2024
1 parent 6a8bbe0 commit 10c987e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 43 deletions.
22 changes: 0 additions & 22 deletions drivers/include/periph/flashpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,28 +236,6 @@ unsigned flashpage_page(const void *addr);
*/
void flashpage_erase(unsigned page);

/**
* @brief Get number of first free flashpage
* @deprecated Use @ref FLASH_WRITABLE_INIT instead, which is usable in modules
* as well as applications. The function will be removed after
* the 2022.04 release.
*
* If riotboot is used in two slot mode, this number will change across
* firmware updates as the firmware slots alternate.
*/
unsigned flashpage_first_free(void);

/**
* @brief Get number of last free flashpage
* @deprecated Use @ref FLASH_WRITABLE_INIT instead, which is usable in modules
* as well as applications. The function will be removed after
* the 2022.04 release.
*
* If riotboot is used in two slot mode, this number will change across
* firmware updates as the firmware slots alternate.
*/
unsigned flashpage_last_free(void);

/**
* @brief Write the given page with the given data
*
Expand Down
45 changes: 24 additions & 21 deletions tests/periph/flashpage/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@

#define LINE_LEN (16)

/* For MSP430 cpu's the last page holds the interrupt vector, although the api
should not limit erasing that page, we don't want to break when testing */
#if defined(CPU_CC430) || defined(CPU_MSP430FXYZ)
#define TEST_LAST_AVAILABLE_PAGE (FLASHPAGE_NUMOF - 2)
#else
#define TEST_LAST_AVAILABLE_PAGE (FLASHPAGE_NUMOF - 1)
#endif

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

Expand Down Expand Up @@ -99,27 +107,24 @@ static int cmd_info(int argc, char **argv)
(void)argc;
(void)argv;

printf("Flash start addr:\t\t0x%08x\n", (int)CPU_FLASH_BASE);
printf("Flash start addr:\t0x%08x\n", (int)CPU_FLASH_BASE);
#ifdef FLASHPAGE_SIZE
printf("Page size:\t\t\t%i\n", (int)FLASHPAGE_SIZE);
printf("Page size:\t\t%i\n", (int)FLASHPAGE_SIZE);
#else
puts("Page size:\t\t\tvariable");
puts("Page size:\t\tvariable");
#endif
printf("Number of pages:\t\t%i\n", (int)FLASHPAGE_NUMOF);
printf("Number of pages:\t%i\n", (int)FLASHPAGE_NUMOF);

#ifdef FLASHPAGE_RWWEE_NUMOF
printf("RWWEE Flash start addr:\t\t0x%08x\n", (int)CPU_FLASH_RWWEE_BASE);
printf("RWWEE Number of pages:\t\t%i\n", (int)FLASHPAGE_RWWEE_NUMOF);
printf("RWWEE Flash start addr:\t0x%08x\n", (int)CPU_FLASH_RWWEE_BASE);
printf("RWWEE Number of pages:\t%i\n", (int)FLASHPAGE_RWWEE_NUMOF);
#endif

#ifdef NVMCTRL_USER
printf("AUX page size:\t\t%i\n", FLASH_USER_PAGE_AUX_SIZE + sizeof(nvm_user_page_t));
printf(" user area:\t\t%i\n", FLASH_USER_PAGE_AUX_SIZE);
printf("AUX page size:\t%i\n", FLASH_USER_PAGE_AUX_SIZE + sizeof(nvm_user_page_t));
printf(" user area:\t%i\n", FLASH_USER_PAGE_AUX_SIZE);
#endif

printf("Number of first free page: \t%u \n", flashpage_first_free());
printf("Number of last free page: \t%u \n", flashpage_last_free());

return 0;
}

Expand Down Expand Up @@ -321,18 +326,17 @@ static int cmd_test_last(int argc, char **argv)
(void) argc;
(void) argv;
char fill = 'a';
unsigned last_free = flashpage_last_free();

for (unsigned i = 0; i < sizeof(page_mem); i++) {
page_mem[i] = (uint8_t)fill++;
if (fill > 'z') {
fill = 'a';
}
}
#ifdef __MSP430__
printf("The last page holds the ISR vector, so test page %u\n", last_free);
#if defined(CPU_CC430) || defined(CPU_MSP430FXYZ)
printf("The last page holds the ISR vector, so test page %d\n", TEST_LAST_AVAILABLE_PAGE);
#endif
if (flashpage_write_and_verify(last_free, page_mem) != FLASHPAGE_OK) {
if (flashpage_write_and_verify(TEST_LAST_AVAILABLE_PAGE, page_mem) != FLASHPAGE_OK) {
puts("error verifying the content of last page");
return 1;
}
Expand Down Expand Up @@ -409,23 +413,22 @@ static int cmd_test_last_raw(int argc, char **argv)
{
(void) argc;
(void) argv;
unsigned last_free = flashpage_last_free();

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

/* try to align */
memcpy(raw_buf, "test12344321tset", 16);
#ifdef __MSP430__
printf("The last page holds the ISR vector, so test page %u\n", last_free);
#if defined(CPU_CC430) || defined(CPU_MSP430FXYZ)
printf("The last page holds the ISR vector, so test page %d\n", TEST_LAST_AVAILABLE_PAGE);
#endif

/* erase the page first */
flashpage_erase(last_free);
flashpage_erase(TEST_LAST_AVAILABLE_PAGE);

flashpage_write(flashpage_addr(last_free), raw_buf, sizeof(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(last_free), raw_buf, strlen(raw_buf)) != 0) {
if (memcmp(flashpage_addr(TEST_LAST_AVAILABLE_PAGE), raw_buf, strlen(raw_buf)) != 0) {
puts("error verifying the content of last page");
return 1;
}
Expand Down

0 comments on commit 10c987e

Please sign in to comment.