[usb] If needed, reset the device inside Calculator::Poll

Change-Id: I2d9e2eef4e04b1042a2524a4267569324ad8bcce
This commit is contained in:
Léa Saviot
2018-04-11 13:59:52 +02:00
parent b566676a76
commit 555ced4941
6 changed files with 15 additions and 17 deletions

View File

@@ -103,7 +103,6 @@ void coreReset() {
}
void jumpReset() {
shutdown();
uint32_t * stackPointerAddress = reinterpret_cast<uint32_t *>(0x08000000);
uint32_t * resetHandlerAddress = reinterpret_cast<uint32_t *>(0x08000004);
set_msp(*stackPointerAddress);

View File

@@ -45,6 +45,7 @@ dfu_objs += ion/src/device/usb/boot.o
dfu_objs += ion/src/device/keyboard.o
dfu_objs += ion/src/device/device.o
dfu_objs += ion/src/device/usb.o
dfu_objs += ion/src/device/set_msp.o
ion/src/device/usb/dfu.elf: LDFLAGS = --gc-sections -T ion/src/device/usb/dfu.ld
ion/src/device/usb/dfu.elf: $(usb_objs) $(dfu_objs)

View File

@@ -2,12 +2,13 @@
#include "../regs/regs.h"
#include "../keyboard.h"
#include <ion/usb.h>
#include "../device.h"
namespace Ion {
namespace USB {
namespace Device {
bool Calculator::PollAndReset(bool exitWithKeyboard) {
void Calculator::PollAndReset(bool exitWithKeyboard) {
char serialNumber[Ion::SerialNumberLength+1];
Ion::getSerialNumber(serialNumber);
Calculator c(serialNumber);
@@ -28,7 +29,14 @@ bool Calculator::PollAndReset(bool exitWithKeyboard) {
if (!c.isSoftDisconnected()) {
c.detach();
}
return c.resetOnDisconnect();
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::jumpReset();
}
}
Descriptor * Calculator::descriptor(uint8_t type, uint8_t index) {

View File

@@ -24,7 +24,7 @@ namespace Device {
class Calculator : public Device {
public:
static bool PollAndReset(bool exitWithKeyboard); // Return true if reset is needed
static void PollAndReset(bool exitWithKeyboard); // Return true if reset is needed
Calculator(const char * serialNumber) :
Device(&m_dfuInterface),
m_deviceDescriptor(

View File

@@ -1,7 +1,6 @@
#include <ion/usb.h>
#include <string.h>
#include <assert.h>
#include "../device.h"
extern char _stack_end;
extern char _dfu_bootloader_flash_start;
@@ -10,7 +9,7 @@ extern char _dfu_bootloader_flash_end;
namespace Ion {
namespace USB {
typedef bool (*PollFunctionPointer)(bool exitWithKeyboard);
typedef void (*PollFunctionPointer)(bool exitWithKeyboard);
void DFU() {
@@ -62,14 +61,7 @@ void DFU() {
* add-symbol-file ion/src/device/usb/dfu.elf 0x20038000
*/
if (dfu_bootloader_entry(true)) {
/* 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::jumpReset();
}
dfu_bootloader_entry(true);
/* 5- That's all. The DFU bootloader on the stack is now dead code that will
* be overwritten when the stack grows. */

View File

@@ -5,9 +5,7 @@ namespace Ion {
namespace USB {
void DFU() {
if (Ion::USB::Device::Calculator::PollAndReset(true)) {
Ion::Device::jumpReset();
}
Ion::USB::Device::Calculator::PollAndReset(true);
}
}