Skip to content

Commit ffa3ce7

Browse files
committed
Adding usbserial and usbdfu firmwares (and combined compiled .hex files).
1 parent 4ab2723 commit ffa3ce7

17 files changed

+4403
-0
lines changed

hardware/arduino/firmwares/MEGA-dfu_and_usbserial_combined.hex

Lines changed: 234 additions & 0 deletions
Large diffs are not rendered by default.

hardware/arduino/firmwares/UNO-dfu_and_usbserial_combined.hex

Lines changed: 234 additions & 0 deletions
Large diffs are not rendered by default.

hardware/arduino/firmwares/arduino-usbdfu/Arduino-usbdfu.c

Lines changed: 728 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
/*
2+
LUFA Library
3+
Copyright (C) Dean Camera, 2010.
4+
5+
dean [at] fourwalledcubicle [dot] com
6+
www.fourwalledcubicle.com
7+
*/
8+
9+
/*
10+
Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11+
12+
Permission to use, copy, modify, distribute, and sell this
13+
software and its documentation for any purpose is hereby granted
14+
without fee, provided that the above copyright notice appear in
15+
all copies and that both that the copyright notice and this
16+
permission notice and warranty disclaimer appear in supporting
17+
documentation, and that the name of the author not be used in
18+
advertising or publicity pertaining to distribution of the
19+
software without specific, written prior permission.
20+
21+
The author disclaim all warranties with regard to this
22+
software, including all implied warranties of merchantability
23+
and fitness. In no event shall the author be liable for any
24+
special, indirect or consequential damages or any damages
25+
whatsoever resulting from loss of use, data or profits, whether
26+
in an action of contract, negligence or other tortious action,
27+
arising out of or in connection with the use or performance of
28+
this software.
29+
*/
30+
31+
/** \file
32+
*
33+
* Header file for Arduino-usbdfu.c.
34+
*/
35+
36+
#ifndef _ARDUINO_USB_DFU_BOOTLOADER_H_
37+
#define _ARDUINO_USB_DFU_BOOTLOADER_H_
38+
39+
/* Includes: */
40+
#include <avr/io.h>
41+
#include <avr/wdt.h>
42+
#include <avr/boot.h>
43+
#include <avr/pgmspace.h>
44+
#include <avr/eeprom.h>
45+
#include <avr/power.h>
46+
#include <avr/interrupt.h>
47+
#include <stdbool.h>
48+
49+
#include "Descriptors.h"
50+
51+
#include <LUFA/Drivers/Board/LEDs.h>
52+
#include <LUFA/Drivers/USB/USB.h>
53+
54+
/* Macros: */
55+
/** LED mask for the library LED driver, to indicate TX activity. */
56+
#define LEDMASK_TX LEDS_LED1
57+
58+
/** LED mask for the library LED driver, to indicate RX activity. */
59+
#define LEDMASK_RX LEDS_LED2
60+
61+
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
62+
#define LEDMASK_ERROR (LEDS_LED1 | LEDS_LED2)
63+
64+
/** LED mask for the library LED driver, to indicate that the USB interface is busy. */
65+
#define LEDMASK_BUSY (LEDS_LED1 | LEDS_LED2)
66+
67+
/** Configuration define. Define this token to true to case the bootloader to reject all memory commands
68+
* until a memory erase has been performed. When used in conjunction with the lockbits of the AVR, this
69+
* can protect the AVR's firmware from being dumped from a secured AVR. When false, memory operations are
70+
* allowed at any time.
71+
*/
72+
// #define SECURE_MODE false
73+
74+
/** Major bootloader version number. */
75+
#define BOOTLOADER_VERSION_MINOR 2
76+
77+
/** Minor bootloader version number. */
78+
#define BOOTLOADER_VERSION_REV 0
79+
80+
/** Complete bootloader version number expressed as a packed byte, constructed from the
81+
* two individual bootloader version macros.
82+
*/
83+
#define BOOTLOADER_VERSION ((BOOTLOADER_VERSION_MINOR << 4) | BOOTLOADER_VERSION_REV)
84+
85+
/** First byte of the bootloader identification bytes, used to identify a device's bootloader. */
86+
#define BOOTLOADER_ID_BYTE1 0xDC
87+
88+
/** Second byte of the bootloader identification bytes, used to identify a device's bootloader. */
89+
#define BOOTLOADER_ID_BYTE2 0xFB
90+
91+
/** Convenience macro, used to determine if the issued command is the given one-byte long command.
92+
*
93+
* \param[in] dataarr Command byte array to check against
94+
* \param[in] cb1 First command byte to check
95+
*/
96+
#define IS_ONEBYTE_COMMAND(dataarr, cb1) (dataarr[0] == (cb1))
97+
98+
/** Convenience macro, used to determine if the issued command is the given two-byte long command.
99+
*
100+
* \param[in] dataarr Command byte array to check against
101+
* \param[in] cb1 First command byte to check
102+
* \param[in] cb2 Second command byte to check
103+
*/
104+
#define IS_TWOBYTE_COMMAND(dataarr, cb1, cb2) ((dataarr[0] == (cb1)) && (dataarr[1] == (cb2)))
105+
106+
/** Length of the DFU file suffix block, appended to the end of each complete memory write command.
107+
* The DFU file suffix is currently unused (but is designed to give extra file information, such as
108+
* a CRC of the complete firmware for error checking) and so is discarded.
109+
*/
110+
#define DFU_FILE_SUFFIX_SIZE 16
111+
112+
/** Length of the DFU file filler block, appended to the start of each complete memory write command.
113+
* Filler bytes are added to the start of each complete memory write command, and must be discarded.
114+
*/
115+
#define DFU_FILLER_BYTES_SIZE 26
116+
117+
/** DFU class command request to detach from the host. */
118+
#define DFU_DETATCH 0x00
119+
120+
/** DFU class command request to send data from the host to the bootloader. */
121+
#define DFU_DNLOAD 0x01
122+
123+
/** DFU class command request to send data from the bootloader to the host. */
124+
#define DFU_UPLOAD 0x02
125+
126+
/** DFU class command request to get the current DFU status and state from the bootloader. */
127+
#define DFU_GETSTATUS 0x03
128+
129+
/** DFU class command request to reset the current DFU status and state variables to their defaults. */
130+
#define DFU_CLRSTATUS 0x04
131+
132+
/** DFU class command request to get the current DFU state of the bootloader. */
133+
#define DFU_GETSTATE 0x05
134+
135+
/** DFU class command request to abort the current multi-request transfer and return to the dfuIDLE state. */
136+
#define DFU_ABORT 0x06
137+
138+
/** DFU command to begin programming the device's memory. */
139+
#define COMMAND_PROG_START 0x01
140+
141+
/** DFU command to begin reading the device's memory. */
142+
#define COMMAND_DISP_DATA 0x03
143+
144+
/** DFU command to issue a write command. */
145+
#define COMMAND_WRITE 0x04
146+
147+
/** DFU command to issue a read command. */
148+
#define COMMAND_READ 0x05
149+
150+
/** DFU command to issue a memory base address change command, to set the current 64KB flash page
151+
* that subsequent flash operations should use. */
152+
#define COMMAND_CHANGE_BASE_ADDR 0x06
153+
154+
/* Type Defines: */
155+
/** Type define for a non-returning function pointer to the loaded application. */
156+
typedef void (*AppPtr_t)(void) ATTR_NO_RETURN;
157+
158+
/** Type define for a structure containing a complete DFU command issued by the host. */
159+
typedef struct
160+
{
161+
uint8_t Command; /**< Single byte command to perform, one of the COMMAND_* macro values */
162+
uint8_t Data[5]; /**< Command parameters */
163+
uint16_t DataSize; /**< Size of the command parameters */
164+
} DFU_Command_t;
165+
166+
/* Enums: */
167+
/** DFU bootloader states. Refer to the DFU class specification for information on each state. */
168+
enum DFU_State_t
169+
{
170+
appIDLE = 0,
171+
appDETACH = 1,
172+
dfuIDLE = 2,
173+
dfuDNLOAD_SYNC = 3,
174+
dfuDNBUSY = 4,
175+
dfuDNLOAD_IDLE = 5,
176+
dfuMANIFEST_SYNC = 6,
177+
dfuMANIFEST = 7,
178+
dfuMANIFEST_WAIT_RESET = 8,
179+
dfuUPLOAD_IDLE = 9,
180+
dfuERROR = 10
181+
};
182+
183+
/** DFU command status error codes. Refer to the DFU class specification for information on each error code. */
184+
enum DFU_Status_t
185+
{
186+
OK = 0,
187+
errTARGET = 1,
188+
errFILE = 2,
189+
errWRITE = 3,
190+
errERASE = 4,
191+
errCHECK_ERASED = 5,
192+
errPROG = 6,
193+
errVERIFY = 7,
194+
errADDRESS = 8,
195+
errNOTDONE = 9,
196+
errFIRMWARE = 10,
197+
errVENDOR = 11,
198+
errUSBR = 12,
199+
errPOR = 13,
200+
errUNKNOWN = 14,
201+
errSTALLEDPKT = 15
202+
};
203+
204+
/* Function Prototypes: */
205+
void SetupHardware(void);
206+
void ResetHardware(void);
207+
208+
void EVENT_USB_Device_UnhandledControlRequest(void);
209+
210+
#if defined(INCLUDE_FROM_BOOTLOADER_C)
211+
static void DiscardFillerBytes(uint8_t NumberOfBytes);
212+
static void ProcessBootloaderCommand(void);
213+
static void LoadStartEndAddresses(void);
214+
static void ProcessMemProgCommand(void);
215+
static void ProcessMemReadCommand(void);
216+
static void ProcessWriteCommand(void);
217+
static void ProcessReadCommand(void);
218+
#endif
219+
220+
#endif /* _ARDUINO_USB_DFU_BOOTLOADER_H_ */
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
LUFA Library
3+
Copyright (C) Dean Camera, 2010.
4+
5+
dean [at] fourwalledcubicle [dot] com
6+
www.fourwalledcubicle.com
7+
*/
8+
9+
/*
10+
Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11+
12+
Permission to use, copy, modify, distribute, and sell this
13+
software and its documentation for any purpose is hereby granted
14+
without fee, provided that the above copyright notice appear in
15+
all copies and that both that the copyright notice and this
16+
permission notice and warranty disclaimer appear in supporting
17+
documentation, and that the name of the author not be used in
18+
advertising or publicity pertaining to distribution of the
19+
software without specific, written prior permission.
20+
21+
The author disclaim all warranties with regard to this
22+
software, including all implied warranties of merchantability
23+
and fitness. In no event shall the author be liable for any
24+
special, indirect or consequential damages or any damages
25+
whatsoever resulting from loss of use, data or profits, whether
26+
in an action of contract, negligence or other tortious action,
27+
arising out of or in connection with the use or performance of
28+
this software.
29+
*/
30+
31+
/*
32+
Board LEDs driver for the Benito board, from www.dorkbotpdx.org.
33+
*/
34+
35+
#ifndef __LEDS_ARDUINOUNO_H__
36+
#define __LEDS_ARDUINOUNO_H__
37+
38+
/* Includes: */
39+
#include <avr/io.h>
40+
41+
/* Enable C linkage for C++ Compilers: */
42+
#if defined(__cplusplus)
43+
extern "C" {
44+
#endif
45+
46+
/* Preprocessor Checks: */
47+
#if !defined(INCLUDE_FROM_LEDS_H)
48+
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
49+
#endif
50+
51+
/* Public Interface - May be used in end-application: */
52+
/* Macros: */
53+
/** LED mask for the first LED on the board. */
54+
#define LEDS_LED1 (1 << 5)
55+
56+
/** LED mask for the second LED on the board. */
57+
#define LEDS_LED2 (1 << 4)
58+
59+
/** LED mask for all the LEDs on the board. */
60+
#define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2)
61+
62+
/** LED mask for the none of the board LEDs */
63+
#define LEDS_NO_LEDS 0
64+
65+
/* Inline Functions: */
66+
#if !defined(__DOXYGEN__)
67+
static inline void LEDs_Init(void)
68+
{
69+
DDRD |= LEDS_ALL_LEDS;
70+
PORTD |= LEDS_ALL_LEDS;
71+
}
72+
73+
static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
74+
{
75+
PORTD &= ~LEDMask;
76+
}
77+
78+
static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
79+
{
80+
PORTD |= LEDMask;
81+
}
82+
83+
static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
84+
{
85+
PORTD = ((PORTD | LEDS_ALL_LEDS) & ~LEDMask);
86+
}
87+
88+
static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, const uint8_t ActiveMask)
89+
{
90+
PORTD = ((PORTD | ActiveMask) & ~LEDMask);
91+
}
92+
93+
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
94+
{
95+
PORTD ^= LEDMask;
96+
}
97+
98+
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
99+
static inline uint8_t LEDs_GetLEDs(void)
100+
{
101+
return (PORTD & LEDS_ALL_LEDS);
102+
}
103+
#endif
104+
105+
/* Disable C linkage for C++ Compilers: */
106+
#if defined(__cplusplus)
107+
}
108+
#endif
109+
110+
#endif

0 commit comments

Comments
 (0)