From fc1b5fb2188f3bff548536dbabdffe4283546326 Mon Sep 17 00:00:00 2001 From: manuvelayudhan <36821019+manuvelayudhan@users.noreply.github.com> Date: Tue, 27 Feb 2018 14:31:56 +0530 Subject: [PATCH] If the specified address for write operation is a valid EEPROM address, the requested write is carried out using the existing flash write functions. In order for this to work, the flash parameter fields of the _stlink structure (base, size and page size) are over-written with EEPROM parameters. --- src/tools/flash.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/tools/flash.c b/src/tools/flash.c index 508c4aa84..354e75dd2 100644 --- a/src/tools/flash.c +++ b/src/tools/flash.c @@ -162,6 +162,24 @@ int main(int ac, char** av) goto on_error; } } + else if ((o.addr >= sl->eeprom_base) && + (o.addr < sl->eeprom_base + sl->eeprom_size)) { + + /* Hack to use existing flash write functions for writing to eeprom */ + sl->flash_base = sl->eeprom_base; + sl->flash_size = sl->eeprom_size; + sl->flash_pgsz = sl->eeprom_pgsz; + + if(o.format == FLASH_FORMAT_IHEX) + err = stlink_mwrite_flash(sl, mem, (uint32_t)size, o.addr); + else + err = stlink_fwrite_flash(sl, o.filename, o.addr); + if (err == -1) + { + printf("eeprom : stlink_fwrite_flash() == -1\n"); + goto on_error; + } + } else { err = -1; printf("Unknown memory region\n");