Merge pull request #15908 from benpicco/drivers/periph_common-flashpage
drivers/periph: flashpage: add common helper functions
This commit is contained in:
commit
0493292ef3
@ -130,6 +130,7 @@ extern "C" {
|
|||||||
#if defined(CPU_FAM_STM32F2) || defined(CPU_FAM_STM32F4) || \
|
#if defined(CPU_FAM_STM32F2) || defined(CPU_FAM_STM32F4) || \
|
||||||
defined(CPU_FAM_STM32F7)
|
defined(CPU_FAM_STM32F7)
|
||||||
#define PERIPH_FLASHPAGE_CUSTOM_PAGESIZES
|
#define PERIPH_FLASHPAGE_CUSTOM_PAGESIZES
|
||||||
|
#define PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_ADDR
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief stm32 dual bank configuration
|
* @brief stm32 dual bank configuration
|
||||||
|
|||||||
@ -328,16 +328,6 @@ size_t flashpage_size(unsigned page)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *flashpage_addr(unsigned page)
|
|
||||||
{
|
|
||||||
uintptr_t addr = CPU_FLASH_BASE;
|
|
||||||
while (page) {
|
|
||||||
addr += flashpage_size(--page);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (void*)addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned flashpage_page(void *addr)
|
unsigned flashpage_page(void *addr)
|
||||||
{
|
{
|
||||||
/* Calculates the flashpage number based on the address for the
|
/* Calculates the flashpage number based on the address for the
|
||||||
|
|||||||
@ -105,6 +105,30 @@ extern "C" {
|
|||||||
#define PERIPH_FLASHPAGE_CUSTOM_PAGESIZES
|
#define PERIPH_FLASHPAGE_CUSTOM_PAGESIZES
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_ADDR
|
||||||
|
*
|
||||||
|
* @brief If non-uniform flash page sizes are required, defined to signal
|
||||||
|
* that the peripheral does not implement a custom @ref flashpage_addr
|
||||||
|
* function and instead relies on the generic helper function that
|
||||||
|
* relies on @ref flashpage_size.
|
||||||
|
*/
|
||||||
|
#ifdef DOXYGEN
|
||||||
|
#define PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_ADDR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_PAGE
|
||||||
|
*
|
||||||
|
* @brief If non-uniform flash page sizes are required, defined to signal
|
||||||
|
* that the peripheral does not implement a custom @ref flashpage_page
|
||||||
|
* function and instead relies on the generic helper function that
|
||||||
|
* relies on @ref flashpage_size.
|
||||||
|
*/
|
||||||
|
#ifdef DOXYGEN
|
||||||
|
#define PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_PAGE
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return values used in this interface
|
* @brief Return values used in this interface
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -24,9 +24,9 @@
|
|||||||
|
|
||||||
/* guard this file, must be done before including periph/flashpage.h
|
/* guard this file, must be done before including periph/flashpage.h
|
||||||
* TODO: remove as soon as periph drivers can be build selectively */
|
* TODO: remove as soon as periph drivers can be build selectively */
|
||||||
#if defined(FLASHPAGE_NUMOF) && defined(FLASHPAGE_SIZE)
|
#if defined(FLASHPAGE_SIZE) || defined(PERIPH_FLASHPAGE_CUSTOM_PAGESIZES)
|
||||||
|
|
||||||
#include "periph/flashpage.h"
|
#include "periph/flashpage.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef MODULE_PERIPH_FLASHPAGE_PAGEWISE
|
#ifdef MODULE_PERIPH_FLASHPAGE_PAGEWISE
|
||||||
void flashpage_read(unsigned page, void *data)
|
void flashpage_read(unsigned page, void *data)
|
||||||
@ -76,7 +76,6 @@ void flashpage_write_page(unsigned page, const void *data)
|
|||||||
#endif /* MODULE_PERIPH_FLASHPAGE_PAGEWISE */
|
#endif /* MODULE_PERIPH_FLASHPAGE_PAGEWISE */
|
||||||
|
|
||||||
#if defined(FLASHPAGE_RWWEE_NUMOF)
|
#if defined(FLASHPAGE_RWWEE_NUMOF)
|
||||||
|
|
||||||
void flashpage_rwwee_read(unsigned page, void *data)
|
void flashpage_rwwee_read(unsigned page, void *data)
|
||||||
{
|
{
|
||||||
assert(page < (int)FLASHPAGE_RWWEE_NUMOF);
|
assert(page < (int)FLASHPAGE_RWWEE_NUMOF);
|
||||||
@ -101,7 +100,30 @@ int flashpage_rwwee_write_and_verify(unsigned page, const void *data)
|
|||||||
flashpage_rwwee_write_page(page, data);
|
flashpage_rwwee_write_page(page, data);
|
||||||
return flashpage_rwwee_verify(page, data);
|
return flashpage_rwwee_verify(page, data);
|
||||||
}
|
}
|
||||||
|
#endif /* FLASHPAGE_RWWEE_NUMOF */
|
||||||
|
|
||||||
#endif
|
#ifdef PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_ADDR
|
||||||
|
void *flashpage_addr(unsigned page)
|
||||||
|
{
|
||||||
|
uintptr_t addr = CPU_FLASH_BASE;
|
||||||
|
|
||||||
#endif
|
while (page) {
|
||||||
|
addr += flashpage_size(--page);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (void*)addr;
|
||||||
|
}
|
||||||
|
#endif /* PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_ADDR */
|
||||||
|
|
||||||
|
#ifdef PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_PAGE
|
||||||
|
unsigned flashpage_page(void *addr)
|
||||||
|
{
|
||||||
|
unsigned page = 0;
|
||||||
|
|
||||||
|
for (uintptr_t pos = CPU_FLASH_BASE; addr >= pos; ++page) {
|
||||||
|
pos += flashpage_size(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
return page - 1;
|
||||||
|
}
|
||||||
|
#endif /* PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_PAGE */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user