1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

efm32: Adapt to flashpage/flashpage_pagewise API

This commit is contained in:
Koen Zandberg 2020-11-09 16:43:55 +01:00
parent 3c10425b4c
commit 9a79124fba
No known key found for this signature in database
GPG Key ID: 0895A893E6D2985B
4 changed files with 21 additions and 26 deletions

View File

@ -10,7 +10,7 @@ config CPU_COMMON_EFM32
select HAS_CPU_EFM32
select HAS_PERIPH_CPUID
select HAS_PERIPH_FLASHPAGE
select HAS_PERIPH_FLASHPAGE_RAW
select HAS_PERIPH_FLASHPAGE_PAGEWISE
select HAS_PERIPH_GPIO
select HAS_PERIPH_GPIO_IRQ
select HAS_PERIPH_WDT

View File

@ -11,7 +11,7 @@ endif
FEATURES_PROVIDED += arch_efm32
FEATURES_PROVIDED += periph_cpuid
FEATURES_PROVIDED += periph_flashpage
FEATURES_PROVIDED += periph_flashpage_raw
FEATURES_PROVIDED += periph_flashpage_pagewise
FEATURES_PROVIDED += periph_gpio periph_gpio_irq
FEATURES_PROVIDED += periph_wdt

View File

@ -46,9 +46,9 @@ extern "C" {
/* The minimum block size which can be written is 4B. However, the erase
* block is always FLASHPAGE_SIZE.
*/
#define FLASHPAGE_RAW_BLOCKSIZE (4U)
#define FLASHPAGE_WRITE_BLOCK_SIZE (4U)
/* Writing should be always 4 bytes aligned */
#define FLASHPAGE_RAW_ALIGNMENT (4U)
#define FLASHPAGE_WRITE_BLOCK_ALIGNMENT (4U)
/** @} */
/**

View File

@ -26,15 +26,27 @@
#include "em_msc.h"
void flashpage_write_raw(void *target_addr, const void *data, size_t len)
void flashpage_erase(unsigned page)
{
/* assert multiples of FLASHPAGE_RAW_BLOCKSIZE are written and no less of
assert(page < (int)FLASHPAGE_NUMOF);
uint32_t *page_addr = (uint32_t *)flashpage_addr(page);
/* erase given page */
MSC_Init();
MSC_ErasePage(page_addr);
MSC_Deinit();
}
void flashpage_write(void *target_addr, const void *data, size_t len)
{
/* assert multiples of FLASHPAGE_WRITE_BLOCK_SIZE are written and no less of
that length. */
assert(!(len % FLASHPAGE_RAW_BLOCKSIZE));
assert(!(len % FLASHPAGE_WRITE_BLOCK_SIZE));
/* ensure writes are aligned */
assert(!(((unsigned)target_addr % FLASHPAGE_RAW_ALIGNMENT) ||
((unsigned)data % FLASHPAGE_RAW_ALIGNMENT)));
assert(!(((unsigned)target_addr % FLASHPAGE_WRITE_BLOCK_ALIGNMENT) ||
((unsigned)data % FLASHPAGE_WRITE_BLOCK_ALIGNMENT)));
/* ensure the length doesn't exceed the actual flash size */
assert(((unsigned)target_addr + len) <
@ -47,20 +59,3 @@ void flashpage_write_raw(void *target_addr, const void *data, size_t len)
MSC_WriteWord(page_addr, data_addr, len);
MSC_Deinit();
}
void flashpage_write(int page, const void *data)
{
assert(page < (int)FLASHPAGE_NUMOF);
uint32_t *page_addr = (uint32_t *)flashpage_addr(page);
/* erase given page */
MSC_Init();
MSC_ErasePage(page_addr);
MSC_Deinit();
/* write data to page */
if (data != NULL) {
flashpage_write_raw(page_addr, data, FLASHPAGE_SIZE);
}
}