2017-11-13 16:08:08 +01:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2017-11-29 19:50:50 +01:00
|
|
|
* @ingroup cpu_efm32
|
2017-11-13 16:08:08 +01:00
|
|
|
* @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"
|
|
|
|
|
2020-11-09 16:43:55 +01:00
|
|
|
void flashpage_erase(unsigned page)
|
2019-08-04 12:32:54 +02:00
|
|
|
{
|
2020-11-09 16:43:55 +01:00
|
|
|
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
|
2019-08-04 12:32:54 +02:00
|
|
|
that length. */
|
2020-11-09 16:43:55 +01:00
|
|
|
assert(!(len % FLASHPAGE_WRITE_BLOCK_SIZE));
|
2019-08-04 12:32:54 +02:00
|
|
|
|
|
|
|
/* ensure writes are aligned */
|
2020-11-09 16:43:55 +01:00
|
|
|
assert(!(((unsigned)target_addr % FLASHPAGE_WRITE_BLOCK_ALIGNMENT) ||
|
|
|
|
((unsigned)data % FLASHPAGE_WRITE_BLOCK_ALIGNMENT)));
|
2019-08-04 12:32:54 +02:00
|
|
|
|
|
|
|
/* 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();
|
|
|
|
}
|