Skip to content
Snippets Groups Projects
Commit 4a088830 authored by Micah Elizabeth Scott's avatar Micah Elizabeth Scott
Browse files

Updates for DFU 1.1, more debugging

parent a2300808
No related branches found
No related tags found
No related merge requests found
......@@ -66,7 +66,7 @@ bool test_banner_echo()
}
}
//serial_end();
serial_end();
return matched == bannerLength;
}
......@@ -79,6 +79,7 @@ int main()
led_on();
// }
dfu_init();
usb_init();
while (1) {
......
......@@ -63,16 +63,20 @@ static dfu_status_t dfu_status = OK;
static unsigned dfu_poll_timeout = 1;
void dfu_init()
{
serial_begin(BAUD2DIV(115200));
serial_print("Hello from DFU!\n");
}
void dfu_download(unsigned blockNum, unsigned length, const uint8_t *data)
{
serial_phex32(blockNum);
serial_putchar(' ');
serial_phex32(length);
serial_putchar('\n');
serial_putchar('.');
}
void dfu_getstatus(uint8_t *status)
{
serial_putchar('B');
status[0] = dfu_status;
status[1] = dfu_poll_timeout >> 16;
status[2] = dfu_poll_timeout >> 8;
......
/*
* Fadecandy DFU Bootloader
*
* Copyright (c) 2013 Micah Elizabeth Scott
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
typedef enum {
appIDLE = 0,
appDETACH,
dfuIDLE,
dfuDNLOAD_SYNC,
dfuDNBUSY,
dfuDNLOAD_IDLE,
dfuMANIFEST_SYNC,
dfuMANIFEST,
dfuMANIFEST_WAIT_RESET,
dfuUPLOAD_IDLE,
dfuERROR
} dfu_state_t;
typedef enum {
OK = 0,
errTARGET,
errFILE,
errWRITE,
errERASE,
errCHECK_ERASED,
errPROG,
errVERIFY,
errADDRESS,
errNOTDONE,
errFIRMWARE,
errVENDOR,
errUSBR,
errPOR,
errUNKNOWN,
errSTALLEDPKT,
} dfu_status_t;
void dfu_init();
void dfu_download(unsigned blockNum, unsigned length, const uint8_t *data);
void dfu_getstatus(uint8_t *status);
void dfu_clrstatus();
uint8_t dfu_getstate();
void dfu_abort();
......@@ -63,8 +63,8 @@ static uint8_t device_descriptor[] = {
18, // bLength
1, // bDescriptorType
0x00, 0x02, // bcdUSB
DEVICE_CLASS, // bDeviceClass
DEVICE_SUBCLASS, // bDeviceSubClass
0x00, // bDeviceClass
0x00, // bDeviceSubClass
0x00, // bDeviceProtocol
EP0_SIZE, // bMaxPacketSize0
LSB(VENDOR_ID), MSB(VENDOR_ID), // idVendor
......@@ -105,19 +105,20 @@ static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
DFU_INTERFACE, // bInterfaceNumber
0, // bAlternateSetting
0, // bNumEndpoints
DEVICE_CLASS, // bInterfaceClass
DEVICE_SUBCLASS, // bInterfaceSubClass
DFU_INTERFACE_PROTOCOL, // bInterfaceProtocol
0xFE, // bInterfaceClass
0x01, // bInterfaceSubClass
0x02, // bInterfaceProtocol
2, // iInterface
// DFU Functional Descriptor (DFU spec TAble 4.2)
7, // bLength
9, // bLength
0x21, // bDescriptorType
0x01, // bmAttributes: Download only, must be reset
LSB(DFU_DETACH_TIMEOUT), // wDetachTimeOut
MSB(DFU_DETACH_TIMEOUT),
LSB(DFU_TRANSFER_SIZE), // wTransferSize
MSB(DFU_TRANSFER_SIZE),
0x01,0x01, // bcdDFUVersion
};
......
......@@ -38,8 +38,6 @@
#define VENDOR_ID 0x1d50 // OpenMoko
#define PRODUCT_ID 0x607a // Assigned to Fadecandy project
#define DEVICE_VER 0x0100 // Bootloader version
#define DEVICE_CLASS 0xfe // Application specific
#define DEVICE_SUBCLASS 0x01 // Device Firmware Update
#define MANUFACTURER_NAME {'s','c','a','n','l','i','m','e'}
#define MANUFACTURER_NAME_LEN 8
#define PRODUCT_NAME {'F','a','d','e','c','a','n','d','y',' ','B','o','o','t','l','o','a','d','e','r'}
......@@ -47,10 +45,9 @@
#define EP0_SIZE 64
#define NUM_INTERFACE 1
#define DFU_INTERFACE 0
#define DFU_INTERFACE_PROTOCOL 0x02 // DFU Mode
#define DFU_DETACH_TIMEOUT 10000 // 10 second timer
#define DFU_TRANSFER_SIZE 1024 // Equal to flash erase block size
#define CONFIG_DESC_SIZE (9+9+7)
#define DFU_TRANSFER_SIZE EP0_SIZE
#define CONFIG_DESC_SIZE (9+9+9)
typedef struct {
uint16_t wValue;
......
......@@ -35,6 +35,7 @@
#include "mk20dx128.h"
#include "usb_dev.h"
#include "usb_desc.h"
#include "dfu.h"
// buffer descriptor table
......
......@@ -40,13 +40,6 @@ extern "C" {
void usb_init(void);
void usb_isr(void);
// Callbacks for implementing DFU mode
void dfu_download(unsigned blockNum, unsigned length, const uint8_t *data);
void dfu_getstatus(uint8_t *status);
void dfu_clrstatus();
uint8_t dfu_getstate();
void dfu_abort();
extern volatile uint8_t usb_configuration;
#ifdef __cplusplus
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment