1 #ifndef ION_DEVICE_USB_DFU_INTERFACE_H 2 #define ION_DEVICE_USB_DFU_INTERFACE_H 23 m_state(State::dfuIDLE),
25 m_potentialNewAddressPointer(0),
26 m_erasePage(k_flashMemorySectorsCount+1),
28 m_largeBufferLength(0),
30 m_bInterfaceAlternateSetting(bInterfaceAlternateSetting)
38 assert(interfaceAlternativeIndex == m_bInterfaceAlternateSetting);
41 return m_bInterfaceAlternateSetting;
47 enum class DFURequest {
58 enum class DFUDownloadCommand {
60 SetAddressPointer = 0x21,
71 errCHECK_ERASED = 0x05,
93 dfuMANIFESTWAITRESET = 8,
98 class StatusData :
public Streamable {
100 StatusData(Status status, State state,
uint32_t pollTimeout = 1) :
104 m_bwPollTimeout{
uint8_t((pollTimeout>>16) & 0xFF),
uint8_t((pollTimeout>>8) & 0xFF),
uint8_t(pollTimeout & 0xFF)},
110 void push(Channel *
c)
const override;
118 class StateData :
public Streamable {
120 StateData(State state) : m_bState((
uint8_t)state) {}
122 void push(Channel *
c)
const override;
127 constexpr
static uint8_t k_flashMemorySectorsCount = 12;
131 constexpr
static uint32_t k_flashStartAddress = 0x08000000;
132 constexpr
static uint32_t k_flashEndAddress = 0x08100000;
133 constexpr
static uint32_t k_sramStartAddress = 0x20000000;
134 constexpr
static uint32_t k_sramEndAddress = 0x20040000;
137 bool processDownloadRequest(
uint16_t wLength,
uint16_t * transferBufferLength);
138 bool processUploadRequest(SetupPacket * request,
uint8_t * transferBuffer,
uint16_t * transferBufferLength,
uint16_t transferBufferMaxLength);
140 void setAddressPointerCommand(SetupPacket * request,
uint8_t * transferBuffer,
uint16_t transferBufferLength);
141 void changeAddressPointerIfNeeded();
143 void eraseCommand(
uint8_t * transferBuffer,
uint16_t transferBufferLength);
144 void eraseMemoryIfNeeded();
145 void writeOnMemory();
146 void unlockFlashMemory();
147 void lockFlashMemoryAndPurgeCaches();
149 bool getStatus(SetupPacket * request,
uint8_t * transferBuffer,
uint16_t * transferBufferLength,
uint16_t transferBufferMaxLength);
150 bool clearStatus(SetupPacket * request,
uint8_t * transferBuffer,
uint16_t * transferBufferLength,
uint16_t transferBufferMaxLength);
154 bool dfuAbort(
uint16_t * transferBufferLength);
156 void leaveDFUAndReset();
162 uint32_t m_potentialNewAddressPointer;
167 uint8_t m_bInterfaceAlternateSetting;
void wholeDataSentCallback(SetupPacket *request, uint8_t *transferBuffer, uint16_t *transferBufferLength) override
void wholeDataReceivedCallback(SetupPacket *request, uint8_t *transferBuffer, uint16_t *transferBufferLength) override
DFUInterface(Device *device, Endpoint0 *ep0, uint8_t bInterfaceAlternateSetting)
static constexpr int MaxTransferSize
bool processSetupInRequest(SetupPacket *request, uint8_t *transferBuffer, uint16_t *transferBufferLength, uint16_t transferBufferMaxLength) override
void setActiveInterfaceAlternative(uint8_t interfaceAlternativeIndex) override
uint8_t getActiveInterfaceAlternative() override