1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/drivers/periph_common/flashpage.c
Francisco Molina 9fa0099d62
cpu/stm32wb: add flashpage support
- Since flash access is shared with CPU2 we resize ROM_LEN
  according to CPU2 secure flash memmory area.
- Add assert to prevent unauthorized reads from CPU2 secure
  flash area
2020-03-25 09:29:56 +01:00

95 lines
2.0 KiB
C

/*
* Copyright (C) 2016 Freie Universität Berlin
*
* 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 drivers_periph_flashpage
* @{
*
* @file
* @brief Common flash page functions
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
#include <string.h>
#include "cpu.h"
#include "assert.h"
/* 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_NUMOF) && defined(FLASHPAGE_SIZE)
#include "periph/flashpage.h"
void flashpage_read(int page, void *data)
{
assert(page < (int)FLASHPAGE_NUMOF);
#if defined(CPU_FAM_STM32WB)
assert(page < (int)(FLASH->SFR & FLASH_SFR_SFSA));
#endif
memcpy(data, flashpage_addr(page), FLASHPAGE_SIZE);
}
int flashpage_verify(int page, const void *data)
{
assert(page < (int)FLASHPAGE_NUMOF);
#if defined(CPU_FAM_STM32WB)
assert(page < (int)(FLASH->SFR & FLASH_SFR_SFSA));
#endif
if (memcmp(flashpage_addr(page), data, FLASHPAGE_SIZE) == 0) {
return FLASHPAGE_OK;
}
else {
return FLASHPAGE_NOMATCH;
}
}
int flashpage_write_and_verify(int page, const void *data)
{
flashpage_write(page, data);
return flashpage_verify(page, data);
}
#if defined(FLASHPAGE_RWWEE_NUMOF)
void flashpage_rwwee_read(int page, void *data)
{
assert(page < (int)FLASHPAGE_RWWEE_NUMOF);
memcpy(data, flashpage_rwwee_addr(page), FLASHPAGE_SIZE);
}
int flashpage_rwwee_verify(int page, const void *data)
{
assert(page < (int)FLASHPAGE_RWWEE_NUMOF);
if (memcmp(flashpage_rwwee_addr(page), data, FLASHPAGE_SIZE) == 0) {
return FLASHPAGE_OK;
}
else {
return FLASHPAGE_NOMATCH;
}
}
int flashpage_rwwee_write_and_verify(int page, const void *data)
{
flashpage_rwwee_write(page, data);
return flashpage_rwwee_verify(page, data);
}
#endif
#endif