Skip to content

Commit

Permalink
periph/flashpage: extend API
Browse files Browse the repository at this point in the history
  • Loading branch information
Ollrogge committed Oct 18, 2021
1 parent 8c4f0d6 commit 0babf55
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
10 changes: 10 additions & 0 deletions drivers/include/periph/flashpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ unsigned flashpage_page(const void *addr);
*/
void flashpage_erase(unsigned page);

/**
* @brief Get number of first free flashpage
*/
unsigned flashpage_first_free(void);

/**
* @brief Get number of last free flashpage
*/
unsigned flashpage_last_free(void);

/**
* @brief Write the given page with the given data
*
Expand Down
22 changes: 22 additions & 0 deletions drivers/periph_common/flashpage.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
#include "cpu.h"
#include "assert.h"

#define ENABLE_DEBUG (0)
#include "debug.h"

/**
* @brief Memory markers, defined in the linker script
* @{
*/
extern uint32_t _end_fw;
extern uint32_t _erom;

/* guard this file, must be done before including periph/flashpage.h
* TODO: remove as soon as periph drivers can be build selectively */
#if defined(FLASHPAGE_SIZE) || defined(PERIPH_FLASHPAGE_CUSTOM_PAGESIZES)
Expand Down Expand Up @@ -129,3 +139,15 @@ unsigned flashpage_page(const void *addr)
return page - 1;
}
#endif /* PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_PAGE */

#ifdef MODULE_PERIPH_FLASHPAGE
unsigned flashpage_first_free(void)
{
return flashpage_page(&_end_fw) + 1;
}

unsigned flashpage_last_free(void)
{
return flashpage_page(&_erom) - 1;
}
#endif /* MODULE_PERIPH_FLASHPAGE */
19 changes: 11 additions & 8 deletions tests/periph_flashpage/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,27 @@ static int cmd_info(int argc, char **argv)
(void)argc;
(void)argv;

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

#ifdef 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);
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);
#endif

#ifdef NVMCTRL_USER
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);
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);
#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

0 comments on commit 0babf55

Please sign in to comment.