diff --git a/ion/src/device/bootloader/drivers/external_flash.cpp b/ion/src/device/bootloader/drivers/external_flash.cpp index 34de8b591..1c7686cd4 100644 --- a/ion/src/device/bootloader/drivers/external_flash.cpp +++ b/ion/src/device/bootloader/drivers/external_flash.cpp @@ -471,6 +471,7 @@ void __attribute__((noinline)) WriteMemory(uint8_t * destination, const uint8_t if (Config::NumberOfSectors == 0) { return; } + destination -= ExternalFlash::Config::StartAddress; unset_memory_mapped_mode(); /* Each 256-byte page of the external flash memory (contained in a previously erased area) * may be programmed in burst mode with a single Page Program instruction. diff --git a/ion/src/device/bootloader/drivers/external_flash_tramp.cpp b/ion/src/device/bootloader/drivers/external_flash_tramp.cpp index 031722356..29a2bf03e 100644 --- a/ion/src/device/bootloader/drivers/external_flash_tramp.cpp +++ b/ion/src/device/bootloader/drivers/external_flash_tramp.cpp @@ -371,7 +371,7 @@ void MassErase() { void WriteMemory(uint8_t * destination, const uint8_t * source, size_t length) { asm("cpsid if"); - reinterpret_cast(Ion::Device::Trampoline::address(Ion::Device::Trampoline::ExternalFlashWriteMemory))(destination + ExternalFlash::Config::StartAddress, source, length); + reinterpret_cast(Ion::Device::Trampoline::address(Ion::Device::Trampoline::ExternalFlashWriteMemory))(destination, source, length); asm("cpsie if"); } diff --git a/ion/src/device/n0110/drivers/external_flash.cpp b/ion/src/device/n0110/drivers/external_flash.cpp index 1c9c4a1e9..612efc017 100644 --- a/ion/src/device/n0110/drivers/external_flash.cpp +++ b/ion/src/device/n0110/drivers/external_flash.cpp @@ -471,6 +471,7 @@ void __attribute__((noinline)) WriteMemory(uint8_t * destination, const uint8_t if (Config::NumberOfSectors == 0) { return; } + destination -= ExternalFlash::Config::StartAddress; unset_memory_mapped_mode(); /* Each 256-byte page of the external flash memory (contained in a previously erased area) * may be programmed in burst mode with a single Page Program instruction. diff --git a/ion/src/device/shared/drivers/flash.cpp b/ion/src/device/shared/drivers/flash.cpp index 6f569cd89..692bd4df8 100644 --- a/ion/src/device/shared/drivers/flash.cpp +++ b/ion/src/device/shared/drivers/flash.cpp @@ -46,7 +46,7 @@ void WriteMemory(uint8_t * destination, uint8_t * source, size_t length) { if (SectorAtAddress((uint32_t)destination) < InternalFlash::Config::NumberOfSectors) { InternalFlash::WriteMemory(destination, source, length); } else { - ExternalFlash::WriteMemory(destination - ExternalFlash::Config::StartAddress, source, length); + ExternalFlash::WriteMemory(destination, source, length); } }