2018-04-01 17:40:14 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 Inria
|
|
|
|
*
|
|
|
|
* 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_stm32_common
|
|
|
|
* @ingroup drivers_periph_eeprom
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Low-level eeprom driver implementation
|
|
|
|
*
|
|
|
|
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
2019-03-27 09:49:00 +01:00
|
|
|
* @author Oleg Artamonov <oleg@unwds.com>
|
2018-04-01 17:40:14 +02:00
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "cpu.h"
|
2018-10-01 15:24:57 +02:00
|
|
|
#include "periph/eeprom.h"
|
2018-04-01 17:40:14 +02:00
|
|
|
|
|
|
|
#define ENABLE_DEBUG (0)
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
extern void _lock(void);
|
|
|
|
extern void _unlock(void);
|
2019-03-27 09:49:00 +01:00
|
|
|
extern void _wait_for_pending_operations(void);
|
2018-04-01 17:40:14 +02:00
|
|
|
|
|
|
|
#ifndef EEPROM_START_ADDR
|
|
|
|
#error "periph/eeprom: EEPROM_START_ADDR is not defined"
|
|
|
|
#endif
|
|
|
|
|
2018-10-01 15:24:57 +02:00
|
|
|
size_t eeprom_read(uint32_t pos, uint8_t *data, size_t len)
|
2018-04-01 17:40:14 +02:00
|
|
|
{
|
2018-10-01 15:24:57 +02:00
|
|
|
assert(pos + len <= EEPROM_SIZE);
|
|
|
|
|
|
|
|
uint8_t *p = data;
|
|
|
|
|
|
|
|
DEBUG("Reading data from EEPROM at pos %" PRIu32 ": ", pos);
|
|
|
|
for (size_t i = 0; i < len; i++) {
|
2019-03-27 09:49:00 +01:00
|
|
|
_wait_for_pending_operations();
|
2018-10-01 15:24:57 +02:00
|
|
|
*p++ = *(uint8_t *)(EEPROM_START_ADDR + pos++);
|
|
|
|
DEBUG("0x%02X ", *p);
|
|
|
|
}
|
|
|
|
DEBUG("\n");
|
2018-04-01 17:40:14 +02:00
|
|
|
|
2018-10-01 15:24:57 +02:00
|
|
|
return len;
|
2018-04-01 17:40:14 +02:00
|
|
|
}
|
|
|
|
|
2018-10-01 15:24:57 +02:00
|
|
|
size_t eeprom_write(uint32_t pos, const uint8_t *data, size_t len)
|
2018-04-01 17:40:14 +02:00
|
|
|
{
|
2018-10-01 15:24:57 +02:00
|
|
|
assert(pos + len <= EEPROM_SIZE);
|
|
|
|
|
|
|
|
uint8_t *p = (uint8_t *)data;
|
2018-04-01 17:40:14 +02:00
|
|
|
|
|
|
|
_unlock();
|
2018-10-01 15:24:57 +02:00
|
|
|
|
|
|
|
for (size_t i = 0; i < len; i++) {
|
2019-03-27 09:49:00 +01:00
|
|
|
_wait_for_pending_operations();
|
2018-10-01 15:24:57 +02:00
|
|
|
*(uint8_t *)(EEPROM_START_ADDR + pos++) = *p++;
|
|
|
|
}
|
|
|
|
|
2018-04-01 17:40:14 +02:00
|
|
|
_lock();
|
2018-10-01 15:24:57 +02:00
|
|
|
|
|
|
|
return len;
|
2018-04-01 17:40:14 +02:00
|
|
|
}
|