From 478d49b4163d9135b95b3abf5dacfcaaa75c9ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 21 Mar 2019 14:23:51 +0100 Subject: [PATCH] [ion] DFU leave instruction triggers a core reset on N0101 and a soft reset on N0100 (to avoid booting on ST bootloader as the device is plugged) --- ion/src/device/n0100/Makefile | 2 ++ ion/src/device/n0100/usb/stack/device.cpp | 20 ++++++++++++++++++++ ion/src/device/n0101/Makefile | 2 ++ ion/src/device/n0101/usb/stack/device.cpp | 16 ++++++++++++++++ ion/src/device/shared/usb/Makefile | 1 + ion/src/device/shared/usb/calculator.cpp | 8 +------- ion/src/device/shared/usb/stack/device.h | 1 + 7 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 ion/src/device/n0100/usb/stack/device.cpp create mode 100644 ion/src/device/n0101/usb/stack/device.cpp diff --git a/ion/src/device/n0100/Makefile b/ion/src/device/n0100/Makefile index 931bd69d0..8b0271c7b 100644 --- a/ion/src/device/n0100/Makefile +++ b/ion/src/device/n0100/Makefile @@ -2,4 +2,6 @@ ion_device_src += $(addprefix ion/src/device/n0100/drivers/, \ board.cpp \ ) +ion_device_src += ion/src/device/n0101/usb/stack/device.cpp + LDSCRIPT ?= ion/src/device/n0100/flash.ld diff --git a/ion/src/device/n0100/usb/stack/device.cpp b/ion/src/device/n0100/usb/stack/device.cpp new file mode 100644 index 000000000..c868116ed --- /dev/null +++ b/ion/src/device/n0100/usb/stack/device.cpp @@ -0,0 +1,20 @@ +#include +#include + +namespace Ion { +namespace Device { +namespace USB { + +void Device::leave() { + /* 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(); +} + +} +} +} + diff --git a/ion/src/device/n0101/Makefile b/ion/src/device/n0101/Makefile index 5f1bf5b13..de1b95697 100644 --- a/ion/src/device/n0101/Makefile +++ b/ion/src/device/n0101/Makefile @@ -3,4 +3,6 @@ ion_device_src += $(addprefix ion/src/device/n0101/drivers/, \ cache.cpp \ ) +ion_device_src += ion/src/device/n0101/usb/stack/device.cpp + LDSCRIPT ?= ion/src/device/n0101/flash.ld diff --git a/ion/src/device/n0101/usb/stack/device.cpp b/ion/src/device/n0101/usb/stack/device.cpp new file mode 100644 index 000000000..08ca6a9f4 --- /dev/null +++ b/ion/src/device/n0101/usb/stack/device.cpp @@ -0,0 +1,16 @@ +#include +#include + +namespace Ion { +namespace Device { +namespace USB { + +void Device::leave() { + Ion::Device::Reset::core(); +} + +} +} +} + + diff --git a/ion/src/device/shared/usb/Makefile b/ion/src/device/shared/usb/Makefile index 7c77dff0d..b61dbdb6b 100644 --- a/ion/src/device/shared/usb/Makefile +++ b/ion/src/device/shared/usb/Makefile @@ -48,6 +48,7 @@ dfu_src += liba/src/memcpy.c dfu_src += libaxx/src/cxxabi/pure_virtual.cpp dfu_src += ion/src/device/shared/usb/boot.cpp dfu_src += ion/src/device/$(MODEL)/drivers/cache.cpp +dfu_src += ion/src/device/$(MODEL)/usb/stack/device.cpp dfu_src += $(addprefix ion/src/device/shared/drivers/, \ base64.cpp \ external_flash.cpp \ diff --git a/ion/src/device/shared/usb/calculator.cpp b/ion/src/device/shared/usb/calculator.cpp index 0ad5a285c..60a63185e 100644 --- a/ion/src/device/shared/usb/calculator.cpp +++ b/ion/src/device/shared/usb/calculator.cpp @@ -1,7 +1,6 @@ #include "calculator.h" #include #include -#include #include namespace Ion { @@ -30,12 +29,7 @@ void Calculator::PollAndReset(bool exitWithKeyboard) { c.detach(); } if (c.resetOnDisconnect()) { - /* 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(); + c.leave(); } } diff --git a/ion/src/device/shared/usb/stack/device.h b/ion/src/device/shared/usb/stack/device.h index 64d97d0fb..e1bcb3daf 100644 --- a/ion/src/device/shared/usb/stack/device.h +++ b/ion/src/device/shared/usb/stack/device.h @@ -23,6 +23,7 @@ public: void poll(); bool isSoftDisconnected() const; void detach(); + void leave(); bool resetOnDisconnect() { return m_resetOnDisconnect; } void setResetOnDisconnect(bool reset) { m_resetOnDisconnect = reset; } protected: