diff --git a/ion/src/device/usb/Makefile b/ion/src/device/usb/Makefile index a2d840eef..6a859fcc9 100644 --- a/ion/src/device/usb/Makefile +++ b/ion/src/device/usb/Makefile @@ -50,6 +50,7 @@ dfu_objs += ion/src/device/device.o dfu_objs += ion/src/device/usb.o dfu_objs += ion/src/device/base64.o dfu_objs += ion/src/device/flash.o +dfu_objs += ion/src/device/external_flash.o dfu_objs += ion/src/device/timing.o ion/src/device/usb/dfu.elf: LDSCRIPT = ion/src/device/usb/dfu.ld diff --git a/ion/src/device/usb/calculator.h b/ion/src/device/usb/calculator.h index d3383e419..81b8c9b2a 100644 --- a/ion/src/device/usb/calculator.h +++ b/ion/src/device/usb/calculator.h @@ -93,7 +93,7 @@ public: m_manufacturerStringDescriptor("NumWorks"), m_productStringDescriptor("NumWorks Calculator"), m_serialNumberStringDescriptor(serialNumber), - m_interfaceStringDescriptor("@Flash/0x08000000/04*016Kg,01*064Kg,07*128Kg"), + m_interfaceStringDescriptor("@Flash/0x08000000/04*016Kg,01*064Kg,07*128Kg/0x90000000/64*064Kg,64*064Kg"), //m_interfaceStringDescriptor("@SRAM/0x20000000/01*256Ke"), /* Switch to this descriptor to use dfu-util to write in the SRAM. * FIXME Should be an alternate Interface. */ diff --git a/ion/src/device/usb/dfu_interface.cpp b/ion/src/device/usb/dfu_interface.cpp index 029cce703..8b30e7ea2 100644 --- a/ion/src/device/usb/dfu_interface.cpp +++ b/ion/src/device/usb/dfu_interface.cpp @@ -1,6 +1,7 @@ #include "dfu_interface.h" #include #include +#include namespace Ion { namespace USB { @@ -173,7 +174,7 @@ void DFUInterface::eraseCommand(uint8_t * transferBuffer, uint16_t transferBuffe if (transferBufferLength == 1) { // Mass erase - m_erasePage = Flash::Device::NumberOfSectors; + m_erasePage = Flash::Device::NumberOfSectors + ExternalFlash::Device::NumberOfSectors; return; } @@ -185,9 +186,11 @@ void DFUInterface::eraseCommand(uint8_t * transferBuffer, uint16_t transferBuffe + (transferBuffer[3] << 16) + (transferBuffer[4] << 24); - m_erasePage = Flash::Device::SectorAtAddress(eraseAddress); - - if (m_erasePage < 0) { + if (eraseAddress >= k_flashStartAddress && eraseAddress <= k_flashEndAddress) { + m_erasePage = Flash::Device::SectorAtAddress(eraseAddress); + } else if (eraseAddress >= k_externalFlashStartAddress && eraseAddress <= k_externalFlashEndAddress) { + m_erasePage = Flash::Device::NumberOfSectors + ExternalFlash::Device::SectorAtAddress(eraseAddress - k_externalFlashStartAddress); + } else { // Unrecognized sector m_state = State::dfuERROR; m_status = Status::errTARGET; @@ -201,10 +204,13 @@ void DFUInterface::eraseMemoryIfNeeded() { return; } - if (m_erasePage == Ion::Flash::Device::NumberOfSectors) { + if (m_erasePage == Flash::Device::NumberOfSectors + ExternalFlash::Device::NumberOfSectors) { Flash::Device::MassErase(); - } else { + ExternalFlash::Device::MassErase(); + } else if (m_erasePage < Flash::Device::NumberOfSectors) { Flash::Device::EraseSector(m_erasePage); + } else { + ExternalFlash::Device::EraseSector(m_erasePage - Flash::Device::NumberOfSectors); } /* Put an out of range value in m_erasePage to indicate that no erase is @@ -222,6 +228,8 @@ void DFUInterface::writeOnMemory() { // Write on SRAM // FIXME We should check that we are not overriding the current instructions. memcpy((void *)m_writeAddress, m_largeBuffer, m_largeBufferLength); + } else if (m_writeAddress >= k_externalFlashStartAddress && m_writeAddress <= k_externalFlashEndAddress) { + ExternalFlash::Device::WriteMemory(m_largeBuffer, reinterpret_cast(m_writeAddress) - k_externalFlashStartAddress, m_largeBufferLength); } else { // Invalid write address m_largeBufferLength = 0; diff --git a/ion/src/device/usb/dfu_interface.h b/ion/src/device/usb/dfu_interface.h index 6284ce951..7fce4bf40 100644 --- a/ion/src/device/usb/dfu_interface.h +++ b/ion/src/device/usb/dfu_interface.h @@ -130,6 +130,8 @@ private: constexpr static uint32_t k_flashEndAddress = 0x08100000; constexpr static uint32_t k_sramStartAddress = 0x20000000; constexpr static uint32_t k_sramEndAddress = 0x20040000; + constexpr static uint32_t k_externalFlashStartAddress = 0x90000000; + constexpr static uint32_t k_externalFlashEndAddress = 0x90800000; // Download and upload bool processDownloadRequest(uint16_t wLength, uint16_t * transferBufferLength);