stm32f1/lib/flash_internal.h

60 lines
2.5 KiB
C

/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/** library to read/write internal flash (API)
* @file
* @author King Kévin <kingkevin@cuvoodoo.info>
* @date 2016-2020
* @note peripherals used: none
*/
#pragma once
/** read data from internal flash
* @param[in] address start address of the data to read
* @param[out] buffer where to store the read data
* @param[in] size how much data to read, in bytes
* @return if read succeeded
*/
bool flash_internal_read(uint32_t address, uint8_t *buffer, size_t size);
/** write data to internal flash
* @param[in] address start address where to write data to
* @param[in] buffer data to be written
* @param[in] size how much data to write, in bytes
* @param[in] preserve keep the rest of the page if data needs to be erased
* @return number of bytes written (including preserved data), or negative in case of error
* @note the page will be erased if needed to write the data to the flash
*/
int32_t flash_internal_write(uint32_t address, const uint8_t *buffer, size_t size, bool preserve);
/** get flash page size
* @return flash page size (in bytes)
*/
uint16_t flash_internal_page_size(void);
/** setup the emulated EEPROM area
* @param[in] pages number of flash pages to allocate for the emulated EEPROM
* @warn area must be at least 4 bytes larger than the structure to write
*/
void flash_internal_eeprom_setup(uint16_t pages);
/** read emulated EEPROM area
* @param[out] eeprom where to store the EEPROM data
* @param[in] size size of the EEPROM area (in bytes)
*/
bool flash_internal_eeprom_read(uint8_t *eeprom, uint16_t size);
/** write emulated EEPROM area
* @param[in] eeprom EEPROM data to be stored
* @param[in] size size of the EEPROM area (in bytes)
* @return number of bytes written (including preserved data), or negative in case of error
*/
int32_t flash_internal_eeprom_write(const uint8_t *eeprom, uint16_t size);