mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
67 lines
1.6 KiB
C
67 lines
1.6 KiB
C
/*
|
|
* Copyright (C) 2017 Bas Stottelaar <basstottelaar@gmail.com>
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
* directory for more details.
|
|
*/
|
|
|
|
/**
|
|
* @ingroup cpu_efm32
|
|
* @ingroup drivers_periph_flashpage
|
|
* @{
|
|
*
|
|
* @file
|
|
* @brief Low-level flash page driver implementation
|
|
*
|
|
* @author Bas Stottelaar <basstottelaar@gmail.com>
|
|
*
|
|
* @}
|
|
*/
|
|
|
|
#include "cpu.h"
|
|
#include "assert.h"
|
|
|
|
#include "periph/flashpage.h"
|
|
|
|
#include "em_msc.h"
|
|
|
|
void flashpage_write_raw(void *target_addr, const void *data, size_t len)
|
|
{
|
|
/* assert multiples of FLASHPAGE_RAW_BLOCKSIZE are written and no less of
|
|
that length. */
|
|
assert(!(len % FLASHPAGE_RAW_BLOCKSIZE));
|
|
|
|
/* ensure writes are aligned */
|
|
assert(!(((unsigned)target_addr % FLASHPAGE_RAW_ALIGNMENT) ||
|
|
((unsigned)data % FLASHPAGE_RAW_ALIGNMENT)));
|
|
|
|
/* ensure the length doesn't exceed the actual flash size */
|
|
assert(((unsigned)target_addr + len) <
|
|
(CPU_FLASH_BASE + (FLASHPAGE_SIZE * FLASHPAGE_NUMOF)) + 1);
|
|
|
|
uint32_t *page_addr = target_addr;
|
|
const uint32_t *data_addr = data;
|
|
|
|
MSC_Init();
|
|
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);
|
|
}
|
|
}
|