From bf80957b56eb43d6bee90f683d832a9001e6f778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 18 Jun 2019 15:26:58 -0400 Subject: [PATCH] [ion] Reset: add a method Reset::coreWhilePlugged implemented differently for N0100 & N0110 --- ion/src/device/n0100/Makefile | 3 +-- ion/src/device/n0100/drivers/reset.cpp | 18 ++++++++++++++++++ ion/src/device/n0100/usb/stack/device.cpp | 20 -------------------- ion/src/device/n0110/Makefile | 3 +-- ion/src/device/n0110/drivers/reset.cpp | 13 +++++++++++++ ion/src/device/n0110/usb/stack/device.cpp | 21 --------------------- ion/src/device/shared/drivers/reset.h | 1 + ion/src/device/shared/usb/Makefile | 2 +- ion/src/device/shared/usb/stack/device.cpp | 10 ++++++++++ 9 files changed, 45 insertions(+), 46 deletions(-) create mode 100644 ion/src/device/n0100/drivers/reset.cpp delete mode 100644 ion/src/device/n0100/usb/stack/device.cpp create mode 100644 ion/src/device/n0110/drivers/reset.cpp delete mode 100644 ion/src/device/n0110/usb/stack/device.cpp diff --git a/ion/src/device/n0100/Makefile b/ion/src/device/n0100/Makefile index f6ea824cc..2f76f52b3 100644 --- a/ion/src/device/n0100/Makefile +++ b/ion/src/device/n0100/Makefile @@ -1,8 +1,7 @@ ion_device_src += $(addprefix ion/src/device/n0100/drivers/, \ board.cpp \ power.cpp \ + reset.cpp \ ) -ion_device_src += ion/src/device/n0100/usb/stack/device.cpp - LDSCRIPT ?= ion/src/device/n0100/flash.ld diff --git a/ion/src/device/n0100/drivers/reset.cpp b/ion/src/device/n0100/drivers/reset.cpp new file mode 100644 index 000000000..c64afb379 --- /dev/null +++ b/ion/src/device/n0100/drivers/reset.cpp @@ -0,0 +1,18 @@ +#include +#include "config/flash.h" + +namespace Ion { +namespace Device { +namespace Reset { + +void coreWhilePlugged() { + /* We don't perform a core reset because at this point in time the USB cable + * might be plugged in. Doing a full core reset would result in the device + * entering the ST DFU bootloader. By performing a jump-reset, we mimic the + * core reset without entering ST bootloader.*/ + jump(Flash::Config::StartAddress); +} + +} +} +} diff --git a/ion/src/device/n0100/usb/stack/device.cpp b/ion/src/device/n0100/usb/stack/device.cpp deleted file mode 100644 index 158de4507..000000000 --- a/ion/src/device/n0100/usb/stack/device.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include - -namespace Ion { -namespace Device { -namespace USB { - -void Device::leave(uint32_t leaveAddress) { - /* We don't perform a core reset because at this point in time the USB cable - * is most likely plugged in. Doing a full core reset would be the clean - * thing to do but would therefore result in the device entering the ROMed - * DFU bootloader, which we want to avoid. By performing a jump-reset, we - * will enter the newly flashed firmware. */ - Ion::Device::Reset::jump(leaveAddress); -} - -} -} -} - diff --git a/ion/src/device/n0110/Makefile b/ion/src/device/n0110/Makefile index deb82dc23..338fcef76 100644 --- a/ion/src/device/n0110/Makefile +++ b/ion/src/device/n0110/Makefile @@ -2,8 +2,7 @@ ion_device_src += $(addprefix ion/src/device/n0110/drivers/, \ board.cpp \ cache.cpp \ power.cpp \ + reset.cpp \ ) -ion_device_src += ion/src/device/n0110/usb/stack/device.cpp - LDSCRIPT ?= ion/src/device/n0110/flash.ld diff --git a/ion/src/device/n0110/drivers/reset.cpp b/ion/src/device/n0110/drivers/reset.cpp new file mode 100644 index 000000000..f8c30d7e6 --- /dev/null +++ b/ion/src/device/n0110/drivers/reset.cpp @@ -0,0 +1,13 @@ +#include + +namespace Ion { +namespace Device { +namespace Reset { + +void coreWhilePlugged() { + core(); +} + +} +} +} diff --git a/ion/src/device/n0110/usb/stack/device.cpp b/ion/src/device/n0110/usb/stack/device.cpp deleted file mode 100644 index 3efdb085d..000000000 --- a/ion/src/device/n0110/usb/stack/device.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include - -namespace Ion { -namespace Device { -namespace USB { - -void Device::leave(uint32_t leaveAddress) { - if (leaveAddress == Ion::Device::Flash::Config::StartAddress) { - Ion::Device::Reset::core(); - } else { - Ion::Device::Reset::jump(leaveAddress); - } -} - -} -} -} - - diff --git a/ion/src/device/shared/drivers/reset.h b/ion/src/device/shared/drivers/reset.h index 764788d0a..bb3f81887 100644 --- a/ion/src/device/shared/drivers/reset.h +++ b/ion/src/device/shared/drivers/reset.h @@ -8,6 +8,7 @@ namespace Device { namespace Reset { void core(); +void coreWhilePlugged(); /* jump takes as parameter the address of the isr vector to jump to: the data at * jumpIsrVectorAddress must the stack_pointer address, and the data at diff --git a/ion/src/device/shared/usb/Makefile b/ion/src/device/shared/usb/Makefile index 1d5d46d9c..7c19882e3 100644 --- a/ion/src/device/shared/usb/Makefile +++ b/ion/src/device/shared/usb/Makefile @@ -51,7 +51,7 @@ dfu_src += libaxx/src/cxxabi/pure_virtual.cpp dfu_src += ion/src/device/shared/usb/boot.cpp dfu_src += ion/src/device/$(MODEL)/drivers/board.cpp dfu_src += ion/src/device/$(MODEL)/drivers/cache.cpp -dfu_src += ion/src/device/$(MODEL)/usb/stack/device.cpp +dfu_src += ion/src/device/$(MODEL)/drivers/reset.cpp dfu_src += $(addprefix ion/src/device/shared/drivers/, \ backlight.cpp \ battery.cpp \ diff --git a/ion/src/device/shared/usb/stack/device.cpp b/ion/src/device/shared/usb/stack/device.cpp index eed4c47d8..c0b72dc9e 100644 --- a/ion/src/device/shared/usb/stack/device.cpp +++ b/ion/src/device/shared/usb/stack/device.cpp @@ -1,4 +1,6 @@ #include "device.h" +#include +#include #include namespace Ion { @@ -89,6 +91,14 @@ void Device::detach() { OTG.DCTL()->setSDIS(true); } +void Device::leave(uint32_t leaveAddress) { + if (leaveAddress == Ion::Device::Flash::Config::StartAddress) { + Ion::Device::Reset::coreWhilePlugged(); + } else { + Ion::Device::Reset::jump(leaveAddress); + } +} + bool Device::processSetupInRequest(SetupPacket * request, uint8_t * transferBuffer, uint16_t * transferBufferLength, uint16_t transferBufferMaxLength) { // Device only handles standard requests. if (request->requestType() != SetupPacket::RequestType::Standard) {