LUFA Library - DFU Class Bootloader
|
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/boot.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <avr/power.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdbool.h>
#include "Descriptors.h"
#include "BootloaderAPI.h"
#include "Config/AppConfig.h"
#include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Platform/Platform.h>
Data Structures | |
struct | DFU_Command_t |
Macros | |
#define | BOOTLOADER_VERSION_MINOR 2 |
#define | BOOTLOADER_VERSION_REV 0 |
#define | MAGIC_BOOT_KEY 0xDC42 |
#define | BOOTLOADER_VERSION ((BOOTLOADER_VERSION_MINOR << 4) | BOOTLOADER_VERSION_REV) |
#define | BOOTLOADER_ID_BYTE1 0xDC |
#define | BOOTLOADER_ID_BYTE2 0xFB |
#define | IS_ONEBYTE_COMMAND(dataarr, cb1) (dataarr[0] == (cb1)) |
#define | IS_TWOBYTE_COMMAND(dataarr, cb1, cb2) ((dataarr[0] == (cb1)) && (dataarr[1] == (cb2))) |
#define | DFU_FILE_SUFFIX_SIZE 16 |
#define | DFU_FILLER_BYTES_SIZE 26 |
#define | DFU_REQ_DETATCH 0x00 |
#define | DFU_REQ_DNLOAD 0x01 |
#define | DFU_REQ_UPLOAD 0x02 |
#define | DFU_REQ_GETSTATUS 0x03 |
#define | DFU_REQ_CLRSTATUS 0x04 |
#define | DFU_REQ_GETSTATE 0x05 |
#define | DFU_REQ_ABORT 0x06 |
#define | COMMAND_PROG_START 0x01 |
#define | COMMAND_DISP_DATA 0x03 |
#define | COMMAND_WRITE 0x04 |
#define | COMMAND_READ 0x05 |
#define | COMMAND_CHANGE_BASE_ADDR 0x06 |
Typedefs | |
typedef void(* | AppPtr_t )(void) ATTR_NO_RETURN |
Enumerations | |
enum | DFU_State_t { appIDLE = 0, appDETACH = 1, dfuIDLE = 2, dfuDNLOAD_SYNC = 3, dfuDNBUSY = 4, dfuDNLOAD_IDLE = 5, dfuMANIFEST_SYNC = 6, dfuMANIFEST = 7, dfuMANIFEST_WAIT_RESET = 8, dfuUPLOAD_IDLE = 9, dfuERROR = 10 } |
enum | DFU_Status_t { OK = 0, errTARGET = 1, errFILE = 2, errWRITE = 3, errERASE = 4, errCHECK_ERASED = 5, errPROG = 6, errVERIFY = 7, errADDRESS = 8, errNOTDONE = 9, errFIRMWARE = 10, errVENDOR = 11, errUSBR = 12, errPOR = 13, errUNKNOWN = 14, errSTALLEDPKT = 15 } |
Functions | |
static void | SetupHardware (void) |
static void | ResetHardware (void) |
void | EVENT_USB_Device_ControlRequest (void) |
void | Application_Jump_Check (void) ATTR_INIT_SECTION(3) |
Header file for BootloaderDFU.c.
#define BOOTLOADER_ID_BYTE1 0xDC |
First byte of the bootloader identification bytes, used to identify a device's bootloader.
#define BOOTLOADER_ID_BYTE2 0xFB |
Second byte of the bootloader identification bytes, used to identify a device's bootloader.
#define BOOTLOADER_VERSION ((BOOTLOADER_VERSION_MINOR << 4) | BOOTLOADER_VERSION_REV) |
Complete bootloader version number expressed as a packed byte, constructed from the two individual bootloader version macros.
#define BOOTLOADER_VERSION_MINOR 2 |
Major bootloader version number.
#define BOOTLOADER_VERSION_REV 0 |
Minor bootloader version number.
#define COMMAND_CHANGE_BASE_ADDR 0x06 |
DFU command to issue a memory base address change command, to set the current 64KB flash page that subsequent flash operations should use.
#define COMMAND_DISP_DATA 0x03 |
DFU command to begin reading the device's memory.
#define COMMAND_PROG_START 0x01 |
DFU command to begin programming the device's memory.
#define COMMAND_READ 0x05 |
DFU command to issue a read command.
#define COMMAND_WRITE 0x04 |
DFU command to issue a write command.
#define DFU_FILE_SUFFIX_SIZE 16 |
Length of the DFU file suffix block, appended to the end of each complete memory write command. The DFU file suffix is currently unused (but is designed to give extra file information, such as a CRC of the complete firmware for error checking) and so is discarded.
#define DFU_FILLER_BYTES_SIZE 26 |
Length of the DFU file filler block, appended to the start of each complete memory write command. Filler bytes are added to the start of each complete memory write command, and must be discarded.
#define DFU_REQ_ABORT 0x06 |
DFU class command request to abort the current multi-request transfer and return to the dfuIDLE state.
#define DFU_REQ_CLRSTATUS 0x04 |
DFU class command request to reset the current DFU status and state variables to their defaults.
#define DFU_REQ_DETATCH 0x00 |
DFU class command request to detach from the host.
#define DFU_REQ_DNLOAD 0x01 |
DFU class command request to send data from the host to the bootloader.
#define DFU_REQ_GETSTATE 0x05 |
DFU class command request to get the current DFU state of the bootloader.
#define DFU_REQ_GETSTATUS 0x03 |
DFU class command request to get the current DFU status and state from the bootloader.
#define DFU_REQ_UPLOAD 0x02 |
DFU class command request to send data from the bootloader to the host.
#define IS_ONEBYTE_COMMAND | ( | dataarr, | |
cb1 | |||
) | (dataarr[0] == (cb1)) |
Convenience macro, used to determine if the issued command is the given one-byte long command.
[in] | dataarr | Command byte array to check against |
[in] | cb1 | First command byte to check |
#define IS_TWOBYTE_COMMAND | ( | dataarr, | |
cb1, | |||
cb2 | |||
) | ((dataarr[0] == (cb1)) && (dataarr[1] == (cb2))) |
Convenience macro, used to determine if the issued command is the given two-byte long command.
[in] | dataarr | Command byte array to check against |
[in] | cb1 | First command byte to check |
[in] | cb2 | Second command byte to check |
#define MAGIC_BOOT_KEY 0xDC42 |
Magic bootloader key to unlock forced application start mode.
typedef void(* AppPtr_t)(void) ATTR_NO_RETURN |
Type define for a non-returning function pointer to the loaded application.
enum DFU_State_t |
enum DFU_Status_t |
void Application_Jump_Check | ( | void | ) |
Special startup routine to check if the bootloader was started via a watchdog reset, and if the magic application start key has been loaded into MagicBootKey. If the bootloader started via the watchdog and the key is valid, this will force the user application to start via a software jump.
void EVENT_USB_Device_ControlRequest | ( | void | ) |
Event handler for the USB_ControlRequest event. This is used to catch and process control requests sent to the device from the USB host before passing along unhandled control requests to the library for processing internally.
|
static |
|
static |