diff --git a/build/toolchain.arm-gcc.mak b/build/toolchain.arm-gcc.mak index 845994b2d..52a4c805b 100644 --- a/build/toolchain.arm-gcc.mak +++ b/build/toolchain.arm-gcc.mak @@ -5,10 +5,10 @@ GDB = arm-none-eabi-gdb OBJCOPY = arm-none-eabi-objcopy SIZE = arm-none-eabi-size -ifeq ($(DEBUG),1) +#ifeq ($(DEBUG),1) SFLAGS += -ggdb3 -else +#else SFLAGS += -fdata-sections -ffunction-sections LDFLAGS += --gc-sections -endif +#endif SFLAGS += -mthumb -march=armv7e-m -mfloat-abi=hard -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 diff --git a/ion/src/device/events_keyboard.cpp b/ion/src/device/events_keyboard.cpp index 8cfeb9ce8..1e256509d 100644 --- a/ion/src/device/events_keyboard.cpp +++ b/ion/src/device/events_keyboard.cpp @@ -34,6 +34,7 @@ Event getEvent(int * timeout) { uint64_t keysSeenUp = 0; uint64_t keysSeenTransitionningFromUpToDown = 0; while (true) { +#if 1 // Check if the USB is plugged and if we are being enumerated by a host. if (OTG.GINTSTS()->getENUMDNE()) { /* The device is being enumerated, the speed enumeration is finished. @@ -41,6 +42,15 @@ Event getEvent(int * timeout) { OTG.GINTSTS()->setENUMDNE(1); return Events::USBEnumeration; } +#else + if (OTG.GINTSTS()->getUSBRST()) { + usleep(11000); + if (OTG.GINTSTS()->getENUMDNE()) { + OTG.GINTSTS()->setENUMDNE(1); + return Events::USBEnumeration; + } + } +#endif Keyboard::State state = Keyboard::scan(); keysSeenUp |= ~state; diff --git a/ion/src/device/usb/Makefile b/ion/src/device/usb/Makefile index f0e800688..c04812786 100644 --- a/ion/src/device/usb/Makefile +++ b/ion/src/device/usb/Makefile @@ -19,6 +19,7 @@ usb_objs += $(addprefix ion/src/device/usb/stack/, \ string_descriptor.o\ ) +USB_DFU_XIP_FLASH := 0 ifeq ($(USB_DFU_XIP_FLASH),1) objs += ion/src/device/usb_dfu_xip_flash.o diff --git a/ion/src/device/usb/endpoint0.cpp b/ion/src/device/usb/endpoint0.cpp index 711c42167..c0ec5f9a4 100644 --- a/ion/src/device/usb/endpoint0.cpp +++ b/ion/src/device/usb/endpoint0.cpp @@ -85,6 +85,12 @@ void Endpoint0::readAndDispatchSetupPacket() { m_request = SetupPacket(m_largeBuffer); uint16_t maxBufferLength = MIN(m_request.wLength(), k_largeBufferLength); + int strLength = 3; + if (m_bufferIndex > k_largeBufferDEBUGLength - strLength) { + m_bufferIndex = 0; + } + memcpy(&m_largeBufferDEBUG[m_bufferIndex], "SP/", strLength); + m_bufferIndex += strLength; #if 0 // Requests are only sent to the device or the interface for now. @@ -95,9 +101,6 @@ void Endpoint0::readAndDispatchSetupPacket() { if (type == 0) { m_requestRecipients[0]->processSetupRequest(&m_request, m_largeBuffer, &m_transferBufferLength, maxBufferLength); } else { - for (volatile int i=0;i<10; i++) { - i = i+1; - } m_requestRecipients[1]->processSetupRequest(&m_request, m_largeBuffer, &m_transferBufferLength, maxBufferLength); } #endif @@ -208,6 +211,15 @@ void Endpoint0::sendSomeData() { m_state = State::DataIn; m_bufferOffset += k_maxPacketSize; m_transferBufferLength -= k_maxPacketSize; + int strLength = 4; + if (m_bufferIndex > k_largeBufferDEBUGLength - strLength - 4) { + m_bufferIndex = 0; + } + memcpy(&m_largeBufferDEBUG[m_bufferIndex], "I64/", strLength); + m_bufferIndex += strLength; + m_largeBufferDEBUG[899] = 'A'; + memcpy(&m_largeBufferDEBUG[900], m_largeBuffer + m_bufferOffset, k_maxPacketSize); + m_largeBufferDEBUG[964] = 'B'; return; } // Last data packet sent diff --git a/ion/src/device/usb/endpoint0.h b/ion/src/device/usb/endpoint0.h index 75c11456d..ef635b8a7 100644 --- a/ion/src/device/usb/endpoint0.h +++ b/ion/src/device/usb/endpoint0.h @@ -23,7 +23,8 @@ public: }; constexpr static int k_maxPacketSize = 64; - constexpr Endpoint0(RequestRecipient * device, RequestRecipient * interface) : + //constexpr Endpoint0(RequestRecipient * device, RequestRecipient * interface) : + Endpoint0(RequestRecipient * device, RequestRecipient * interface) : m_forceNAK(false), m_bufferOffset(0), m_transferBufferLength(0), @@ -32,8 +33,27 @@ public: m_request(), m_requestRecipients{device, interface}, m_state(State::Idle), - m_largeBuffer{0} + m_largeBuffer{0}, + m_largeBufferDEBUG{0}, + m_bufferIndex(8) { + m_largeBufferDEBUG[0] = 'D'; + m_largeBufferDEBUG[1] = 'E'; + m_largeBufferDEBUG[2] = 'B'; + m_largeBufferDEBUG[3] = 'U'; + m_largeBufferDEBUG[4] = 'G'; + m_largeBufferDEBUG[5] = 'L'; + m_largeBufferDEBUG[6] = 'E'; + m_largeBufferDEBUG[7] = 'A'; + m_largeBufferDEBUG[1015] = 'E'; + m_largeBufferDEBUG[1016] = 'N'; + m_largeBufferDEBUG[1017] = 'D'; + m_largeBufferDEBUG[1018] = 'B'; + m_largeBufferDEBUG[1019] = 'U'; + m_largeBufferDEBUG[1020] = 'F'; + m_largeBufferDEBUG[1021] = 'F'; + m_largeBufferDEBUG[1022] = 'E'; + m_largeBufferDEBUG[1023] = 'R'; } void setup(); void setupOut(); @@ -56,6 +76,7 @@ public: private: constexpr static int k_largeBufferLength = 2048; + constexpr static int k_largeBufferDEBUGLength = 1024; uint16_t receiveSomeData(); uint16_t readPacket(void * buffer, uint16_t length); @@ -70,6 +91,8 @@ private: RequestRecipient * m_requestRecipients[2]; State m_state; uint8_t m_largeBuffer[2048]; + char m_largeBufferDEBUG[1024]; + int m_bufferIndex; }; }