26 #include <libopencm3/stm32/desig.h> 27 #include <libopencm3/stm32/flash.h> 33 #define PAGE_SIZE 1024 41 if (buffer==NULL || size==0) {
47 for (
size_t i=0; i<size; i++) {
48 buffer[i] = *((uint8_t*)address+i);
60 if (buffer==NULL || size==0) {
71 storage_read(address, &page[0], page_pre);
73 for (uint16_t i=0; i<
PAGE_SIZE-page_pre; i++) {
74 page[page_pre+i] = buffer[i];
79 for (uint16_t i=0; i<size; i++) {
80 page[page_pre+i] = buffer[i];
83 storage_read(address+page_pre+size, &page[page_pre+size],
PAGE_SIZE-page_pre-size);
88 flash_erase_page(address);
89 if (flash_get_status_flags()!=FLASH_SR_EOP) {
94 flash_program_half_word(address+i*2, *((uint16_t*)page+i));
95 if (flash_get_status_flags()!=FLASH_SR_EOP) {
99 if (*((uint16_t*)address+i)!=*((uint16_t*)page+i)) {
#define STORAGE_START
the start of the flash area where to store data (be sure it's after the firmware data) ...
global definitions and methods (API)
library to read/write internal flash (API)
bool flash_internal_read(uint32_t address, uint8_t *buffer, size_t size)
read data from internal flash
#define PAGE_SIZE
the flash page size (medium-density devices have 1KiB page size)
#define STORAGE_END
the end of the flash area where to store data
bool flash_internal_write(uint32_t address, uint8_t *buffer, size_t size)
write data to internal flash