26 #include <libopencm3/stm32/flash.h> 27 #include <libopencm3/stm32/desig.h> 28 #include <libopencm3/stm32/dbgmcu.h> 39 if (address>(UINT32_MAX-size)) {
42 if (address<FLASH_BASE) {
50 if ((address+size)>(FLASH_BASE+DESIG_FLASH_SIZE*1024)) {
60 if (
buffer==NULL || size==0) {
68 for (
size_t i=0; i<size; i++) {
69 buffer[i] = *((uint8_t*)address+i);
78 if (
buffer==NULL || size==0 || size%2) {
86 if (address<FLASH_BASE) {
90 }
else if ((uint32_t)&
__flash_end<FLASH_BASE && (address+size)>(FLASH_BASE+DESIG_FLASH_SIZE*1024)) {
95 uint16_t page_size = 0;
96 if ((0x410==(DBGMCU_IDCODE&DBGMCU_IDCODE_DEV_ID_MASK)) || (0x412==(DBGMCU_IDCODE&DBGMCU_IDCODE_DEV_ID_MASK))) {
98 }
else if ((0x414==(DBGMCU_IDCODE&DBGMCU_IDCODE_DEV_ID_MASK)) || (0x430==(DBGMCU_IDCODE&DBGMCU_IDCODE_DEV_ID_MASK)) || (0x418==(DBGMCU_IDCODE&DBGMCU_IDCODE_DEV_ID_MASK))) {
101 if (DESIG_FLASH_SIZE<256) {
110 uint32_t page_start = address-(address%page_size);
112 for (uint32_t flash=address; flash<(address+size) && flash<(page_start+page_size); flash += 2) {
113 if (*(uint16_t*)(flash)!=0xffff) {
118 uint8_t page_data[page_size];
121 for (uint32_t flash=page_start; flash<address && flash<(page_start+page_size) && page_i<page_size; flash++) {
122 page_data[page_i++] = *(uint8_t*)(flash);
125 while (size>0 && page_i<page_size) {
126 page_data[page_i++] = *
buffer;
132 while (page_i<page_size) {
133 page_data[page_i] = *(uint8_t*)(page_start+page_i);
136 flash_erase_page(page_start);
137 if (flash_get_status_flags()!=FLASH_SR_EOP) {
141 for (uint16_t i=0; i<page_size/2; i++) {
142 flash_program_half_word(page_start+i*2, *((uint16_t*)(page_data+i*2)));
143 if (flash_get_status_flags()!=FLASH_SR_EOP) {
147 if (*((uint16_t*)(page_data+i*2))!=*((uint16_t*)(page_start+i*2))) {
153 while (size>0 && address<(page_start+page_size)) {
154 flash_program_half_word(address, *((uint16_t*)(
buffer)));
155 if (flash_get_status_flags()!=FLASH_SR_EOP) {
159 if (*((uint16_t*)address)!=*((uint16_t*)
buffer)) {
static bool flash_internal_range(uint32_t address, size_t size)
verify if the data is in the internal flash area
global definitions and methods (API)
library to read/write internal flash (API)
char __flash_end
symbol for end of flash
bool flash_internal_read(uint32_t address, uint8_t *buffer, size_t size)
read data from internal flash
static uint8_t * buffer
input/output buffer for read/write commands/functions
bool flash_internal_write(uint32_t address, uint8_t *buffer, size_t size)
write data to internal flash