diff options
Diffstat (limited to 'Bootloaders')
-rw-r--r-- | Bootloaders/CDC/BootloaderCDC.c | 20 | ||||
-rw-r--r-- | Bootloaders/CDC/BootloaderCDC.h | 40 | ||||
-rw-r--r-- | Bootloaders/DFU/BootloaderDFU.c | 34 | ||||
-rw-r--r-- | Bootloaders/DFU/BootloaderDFU.h | 14 | ||||
-rw-r--r-- | Bootloaders/HID/BootloaderHID.c | 6 | ||||
-rw-r--r-- | Bootloaders/HID/BootloaderHID.txt | 7 | ||||
-rw-r--r-- | Bootloaders/HID/Descriptors.c | 38 | ||||
-rw-r--r-- | Bootloaders/HID/makefile | 3 |
8 files changed, 57 insertions, 105 deletions
diff --git a/Bootloaders/CDC/BootloaderCDC.c b/Bootloaders/CDC/BootloaderCDC.c index cb6619edb..99e0ccb4f 100644 --- a/Bootloaders/CDC/BootloaderCDC.c +++ b/Bootloaders/CDC/BootloaderCDC.c @@ -39,22 +39,22 @@ /** Contains the current baud rate and other settings of the first virtual serial port. This must be retained as some * operating systems will not open the port unless the settings can be set successfully. */ -CDC_Line_Coding_t LineEncoding = { .BaudRateBPS = 0, - .CharFormat = OneStopBit, - .ParityType = Parity_None, - .DataBits = 8 }; +static CDC_LineEncoding_t LineEncoding = { .BaudRateBPS = 0, + .CharFormat = CDC_LINEENCODING_OneStopBit, + .ParityType = CDC_PARITY_None, + .DataBits = 8 }; /** Current address counter. This stores the current address of the FLASH or EEPROM as set by the host, * and is used when reading or writing to the AVRs memory (either FLASH or EEPROM depending on the issued * command.) */ -uint32_t CurrAddress; +static uint32_t CurrAddress; /** Flag to indicate if the bootloader should be running, or should exit and allow the application code to run * via a watchdog reset. When cleared the bootloader will exit, starting the watchdog and entering an infinite * loop until the AVR restarts and the application runs. */ -bool RunBootloader = true; +static bool RunBootloader = true; /** Main program entry point. This routine configures the hardware required by the bootloader, then continuously @@ -137,24 +137,24 @@ void EVENT_USB_Device_ControlRequest(void) /* Process CDC specific control requests */ switch (USB_ControlRequest.bRequest) { - case REQ_GetLineEncoding: + case CDC_REQ_GetLineEncoding: if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) { Endpoint_ClearSETUP(); /* Write the line coding data to the control endpoint */ - Endpoint_Write_Control_Stream_LE(&LineEncoding, sizeof(CDC_Line_Coding_t)); + Endpoint_Write_Control_Stream_LE(&LineEncoding, sizeof(CDC_LineEncoding_t)); Endpoint_ClearOUT(); } break; - case REQ_SetLineEncoding: + case CDC_REQ_SetLineEncoding: if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) { Endpoint_ClearSETUP(); /* Read the line coding data in from the host into the global struct */ - Endpoint_Read_Control_Stream_LE(&LineEncoding, sizeof(CDC_Line_Coding_t)); + Endpoint_Read_Control_Stream_LE(&LineEncoding, sizeof(CDC_LineEncoding_t)); Endpoint_ClearIN(); } diff --git a/Bootloaders/CDC/BootloaderCDC.h b/Bootloaders/CDC/BootloaderCDC.h index b4459137c..b6bea11e4 100644 --- a/Bootloaders/CDC/BootloaderCDC.h +++ b/Bootloaders/CDC/BootloaderCDC.h @@ -65,50 +65,10 @@ /** Eight character bootloader firmware identifier reported to the host when requested */ #define SOFTWARE_IDENTIFIER "LUFACDC" - /** CDC Class specific request to get the current virtual serial port configuration settings. */ - #define REQ_GetLineEncoding 0x21 - - /** CDC Class specific request to set the current virtual serial port configuration settings. */ - #define REQ_SetLineEncoding 0x20 - /* Type Defines: */ - /** Type define for the virtual serial port line encoding settings, for storing the current USART configuration - * as set by the host via a class specific request. - */ - typedef struct - { - uint32_t BaudRateBPS; /**< Baud rate of the virtual serial port, in bits per second */ - uint8_t CharFormat; /**< Character format of the virtual serial port, a value from the - * CDCDevice_CDC_LineCodingFormats_t enum - */ - uint8_t ParityType; /**< Parity setting of the virtual serial port, a value from the - * CDCDevice_LineCodingParity_t enum - */ - uint8_t DataBits; /**< Bits of data per character of the virtual serial port */ - } CDC_Line_Coding_t; - /** Type define for a non-returning pointer to the start of the loaded application in flash memory. */ typedef void (*AppPtr_t)(void) ATTR_NO_RETURN; - /* Enums: */ - /** Enum for the possible line encoding formats of a virtual serial port. */ - enum CDCDevice_CDC_LineCodingFormats_t - { - OneStopBit = 0, /**< Each frame contains one stop bit */ - OneAndAHalfStopBits = 1, /**< Each frame contains one and a half stop bits */ - TwoStopBits = 2, /**< Each frame contains two stop bits */ - }; - - /** Enum for the possible line encoding parity settings of a virtual serial port. */ - enum CDCDevice_LineCodingParity_t - { - Parity_None = 0, /**< No parity bit mode on each frame */ - Parity_Odd = 1, /**< Odd parity bit mode on each frame */ - Parity_Even = 2, /**< Even parity bit mode on each frame */ - Parity_Mark = 3, /**< Mark parity bit mode on each frame */ - Parity_Space = 4, /**< Space parity bit mode on each frame */ - }; - /* Function Prototypes: */ void CDC_Task(void); void SetupHardware(void); diff --git a/Bootloaders/DFU/BootloaderDFU.c b/Bootloaders/DFU/BootloaderDFU.c index 41b3e37ba..717c934e5 100644 --- a/Bootloaders/DFU/BootloaderDFU.c +++ b/Bootloaders/DFU/BootloaderDFU.c @@ -40,57 +40,57 @@ * other than erase. This is initially set to the value set by SECURE_MODE, and cleared by the bootloader * once a memory erase has completed in a bootloader session. */ -bool IsSecure = SECURE_MODE; +static bool IsSecure = SECURE_MODE; /** Flag to indicate if the bootloader should be running, or should exit and allow the application code to run * via a soft reset. When cleared, the bootloader will abort, the USB interface will shut down and the application * jumped to via an indirect jump to location 0x0000 (or other location specified by the host). */ -bool RunBootloader = true; +static bool RunBootloader = true; /** Flag to indicate if the bootloader is waiting to exit. When the host requests the bootloader to exit and * jump to the application address it specifies, it sends two sequential commands which must be properly * acknowledged. Upon reception of the first the RunBootloader flag is cleared and the WaitForExit flag is set, * causing the bootloader to wait for the final exit command before shutting down. */ -bool WaitForExit = false; +static bool WaitForExit = false; /** Current DFU state machine state, one of the values in the DFU_State_t enum. */ -uint8_t DFU_State = dfuIDLE; +static uint8_t DFU_State = dfuIDLE; /** Status code of the last executed DFU command. This is set to one of the values in the DFU_Status_t enum after * each operation, and returned to the host when a Get Status DFU request is issued. */ -uint8_t DFU_Status = OK; +static uint8_t DFU_Status = OK; /** Data containing the DFU command sent from the host. */ -DFU_Command_t SentCommand; +static DFU_Command_t SentCommand; /** Response to the last issued Read Data DFU command. Unlike other DFU commands, the read command * requires a single byte response from the bootloader containing the read data when the next DFU_UPLOAD command * is issued by the host. */ -uint8_t ResponseByte; +static uint8_t ResponseByte; /** Pointer to the start of the user application. By default this is 0x0000 (the reset vector), however the host * may specify an alternate address when issuing the application soft-start command. */ -AppPtr_t AppStartPtr = (AppPtr_t)0x0000; +static AppPtr_t AppStartPtr = (AppPtr_t)0x0000; /** 64-bit flash page number. This is concatenated with the current 16-bit address on USB AVRs containing more than * 64KB of flash memory. */ -uint8_t Flash64KBPage = 0; +static uint8_t Flash64KBPage = 0; /** Memory start address, indicating the current address in the memory being addressed (either FLASH or EEPROM * depending on the issued command from the host). */ -uint16_t StartAddr = 0x0000; +static uint16_t StartAddr = 0x0000; /** Memory end address, indicating the end address to read to/write from in the memory being addressed (either FLASH * of EEPROM depending on the issued command from the host). */ -uint16_t EndAddr = 0x0000; +static uint16_t EndAddr = 0x0000; /** Main program entry point. This routine configures the hardware required by the bootloader, then continuously @@ -180,7 +180,7 @@ void EVENT_USB_Device_ControlRequest(void) switch (USB_ControlRequest.bRequest) { - case REQ_DFU_DNLOAD: + case DFU_REQ_DNLOAD: Endpoint_ClearSETUP(); /* Check if bootloader is waiting to terminate */ @@ -333,7 +333,7 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearStatusStage(); break; - case REQ_DFU_UPLOAD: + case DFU_REQ_UPLOAD: Endpoint_ClearSETUP(); while (!(Endpoint_IsINReady())) @@ -432,7 +432,7 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearStatusStage(); break; - case REQ_DFU_GETSTATUS: + case DFU_REQ_GETSTATUS: Endpoint_ClearSETUP(); /* Write 8-bit status value */ @@ -452,7 +452,7 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearStatusStage(); break; - case REQ_DFU_CLRSTATUS: + case DFU_REQ_CLRSTATUS: Endpoint_ClearSETUP(); /* Reset the status value variable to the default OK status */ @@ -460,7 +460,7 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearStatusStage(); break; - case REQ_DFU_GETSTATE: + case DFU_REQ_GETSTATE: Endpoint_ClearSETUP(); /* Write the current device state to the endpoint */ @@ -470,7 +470,7 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearStatusStage(); break; - case REQ_DFU_ABORT: + case DFU_REQ_ABORT: Endpoint_ClearSETUP(); /* Reset the current state variable to the default idle state */ diff --git a/Bootloaders/DFU/BootloaderDFU.h b/Bootloaders/DFU/BootloaderDFU.h index 545548d84..1c1ebba6c 100644 --- a/Bootloaders/DFU/BootloaderDFU.h +++ b/Bootloaders/DFU/BootloaderDFU.h @@ -103,25 +103,25 @@ #define DFU_FILLER_BYTES_SIZE 26 /** DFU class command request to detach from the host. */ - #define REQ_DFU_DETATCH 0x00 + #define DFU_REQ_DETATCH 0x00 /** DFU class command request to send data from the host to the bootloader. */ - #define REQ_DFU_DNLOAD 0x01 + #define DFU_REQ_DNLOAD 0x01 /** DFU class command request to send data from the bootloader to the host. */ - #define REQ_DFU_UPLOAD 0x02 + #define DFU_REQ_UPLOAD 0x02 /** DFU class command request to get the current DFU status and state from the bootloader. */ - #define REQ_DFU_GETSTATUS 0x03 + #define DFU_REQ_GETSTATUS 0x03 /** DFU class command request to reset the current DFU status and state variables to their defaults. */ - #define REQ_DFU_CLRSTATUS 0x04 + #define DFU_REQ_CLRSTATUS 0x04 /** DFU class command request to get the current DFU state of the bootloader. */ - #define REQ_DFU_GETSTATE 0x05 + #define DFU_REQ_GETSTATE 0x05 /** DFU class command request to abort the current multi-request transfer and return to the dfuIDLE state. */ - #define REQ_DFU_ABORT 0x06 + #define DFU_REQ_ABORT 0x06 /** DFU command to begin programming the device's memory. */ #define COMMAND_PROG_START 0x01 diff --git a/Bootloaders/HID/BootloaderHID.c b/Bootloaders/HID/BootloaderHID.c index 9c6b3e051..174041e45 100644 --- a/Bootloaders/HID/BootloaderHID.c +++ b/Bootloaders/HID/BootloaderHID.c @@ -39,7 +39,7 @@ * via a soft reset. When cleared, the bootloader will abort, the USB interface will shut down and the application
* started via a forced watchdog reset.
*/
-bool RunBootloader = true;
+static bool RunBootloader = true;
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously
* runs the bootloader processing routine until instructed to soft-exit.
@@ -127,7 +127,7 @@ void EVENT_USB_Device_ControlRequest(void) boot_spm_busy_wait();
/* Write each of the FLASH page's bytes in sequence */
- for (uint16_t PageByte = 0; PageByte < SPM_PAGESIZE; PageByte += 2)
+ for (uint8_t PageWord = 0; PageWord < (SPM_PAGESIZE / 2); PageWord++)
{
/* Check if endpoint is empty - if so clear it and wait until ready for next packet */
if (!(Endpoint_BytesInEndpoint()))
@@ -137,7 +137,7 @@ void EVENT_USB_Device_ControlRequest(void) }
/* Write the next data word to the FLASH page */
- boot_page_fill(PageAddress + PageByte, Endpoint_Read_Word_LE());
+ boot_page_fill(PageAddress + ((uint16_t)PageWord << 1), Endpoint_Read_Word_LE());
}
/* Write the filled FLASH page to memory */
diff --git a/Bootloaders/HID/BootloaderHID.txt b/Bootloaders/HID/BootloaderHID.txt index 9b47ff3c6..51dceb831 100644 --- a/Bootloaders/HID/BootloaderHID.txt +++ b/Bootloaders/HID/BootloaderHID.txt @@ -51,9 +51,10 @@ * from PJRC, used with permission. This bootloader is delibertely non-compatible with the properietary HalfKay
* bootloader GUI; only the command line interface software accompanying this bootloader will work with it.
*
- * Out of the box this bootloader builds for the USB1287, and will fit into 4KB of bootloader space. If
- * you wish to enlarge this space and/or change the AVR model, you will need to edit the BOOT_START and MCU
- * values in the accompanying makefile.
+ * Out of the box this bootloader builds for the USB1287, and will fit into 2KB of bootloader space for the
+ * Series 2 USB AVRs (ATMEGAxxU2, AT90USBxx2) or 4KB of bootloader space for all other models. If you wish to
+ * enlarge this space and/or change the AVR model, you will need to edit the BOOT_START and MCU values in the
+ * accompanying makefile.
*
* \section SSec_Options Project Options
*
diff --git a/Bootloaders/HID/Descriptors.c b/Bootloaders/HID/Descriptors.c index 0a63b7925..f79d34686 100644 --- a/Bootloaders/HID/Descriptors.c +++ b/Bootloaders/HID/Descriptors.c @@ -43,12 +43,12 @@ * the device will send, and what it may be sent back from the host. Refer to the HID specification for
* more details on HID report descriptors.
*/
-USB_Descriptor_HIDReport_Datatype_t HIDReport[] =
+const USB_Descriptor_HIDReport_Datatype_t HIDReport[] =
{
- HID_RI_USAGE_PAGE(16, 0xFF00), /* Vendor Page 1 */
- HID_RI_USAGE(8, 0x01), /* Vendor Usage 1 */
+ HID_RI_USAGE_PAGE(16, 0xFFDC), /* Vendor Page 0xDC */
+ HID_RI_USAGE(8, 0xFB), /* Vendor Usage 0xFB */
HID_RI_COLLECTION(8, 0x01), /* Vendor Usage 1 */
- HID_RI_USAGE(8, 0x03), /* Vendor Usage 3 */
+ HID_RI_USAGE(8, 0x02), /* Vendor Usage 2 */
HID_RI_LOGICAL_MINIMUM(8, 0x00),
HID_RI_LOGICAL_MAXIMUM(8, 0xFF),
HID_RI_REPORT_SIZE(8, 0x08),
@@ -62,7 +62,7 @@ USB_Descriptor_HIDReport_Datatype_t HIDReport[] = * number of device configurations. The descriptor is read out by the USB host when the enumeration
* process begins.
*/
-USB_Descriptor_Device_t DeviceDescriptor =
+const USB_Descriptor_Device_t DeviceDescriptor =
{
.Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
@@ -89,7 +89,7 @@ USB_Descriptor_Device_t DeviceDescriptor = * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
* a configuration so that the host may correctly communicate with the USB device.
*/
-USB_Descriptor_Configuration_t ConfigurationDescriptor =
+const USB_Descriptor_Configuration_t ConfigurationDescriptor =
{
.Config =
{
@@ -154,33 +154,23 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex,
const void** const DescriptorAddress)
{
- const uint8_t DescriptorType = (wValue >> 8);
+ const uint8_t DescriptorType = (wValue >> 8);
const void* Address = NULL;
uint16_t Size = NO_DESCRIPTOR;
- /* If/Else If chain compiles slightly smaller than a switch case */
if (DescriptorType == DTYPE_Device)
- {
- Address = &DeviceDescriptor;
- Size = sizeof(USB_Descriptor_Device_t);
- }
+ Address = &DeviceDescriptor;
else if (DescriptorType == DTYPE_Configuration)
- {
- Address = &ConfigurationDescriptor;
- Size = sizeof(USB_Descriptor_Configuration_t);
- }
+ Address = &ConfigurationDescriptor;
else if (DescriptorType == HID_DTYPE_HID)
- {
- Address = &ConfigurationDescriptor.HID_VendorHID;
- Size = sizeof(USB_HID_Descriptor_HID_t);
- }
+ Address = &ConfigurationDescriptor.HID_VendorHID;
else
- {
- Address = &HIDReport;
- Size = sizeof(HIDReport);
- }
+ Address = &HIDReport;
+ if (Address != NULL)
+ Size = (Address == &HIDReport) ? sizeof(HIDReport) : ((USB_Descriptor_Header_t*)Address)->Size;
+
*DescriptorAddress = Address;
return Size;
}
diff --git a/Bootloaders/HID/makefile b/Bootloaders/HID/makefile index 81561c371..338bafa01 100644 --- a/Bootloaders/HID/makefile +++ b/Bootloaders/HID/makefile @@ -91,7 +91,7 @@ F_CLOCK = $(F_CPU) # Note that the bootloader size and start address given in AVRStudio is in words and not
# bytes, and so will need to be doubled to obtain the byte address needed by AVR-GCC.
FLASH_SIZE_KB = 128
-BOOT_SECTION_SIZE_KB = 2
+BOOT_SECTION_SIZE_KB = 4
BOOT_START = 0x$(shell echo "obase=16; ($(FLASH_SIZE_KB) - $(BOOT_SECTION_SIZE_KB)) * 1024" | bc)
@@ -124,6 +124,7 @@ LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENAB LUFA_OPTS += -D NO_INTERNAL_SERIAL
LUFA_OPTS += -D NO_DEVICE_SELF_POWER
LUFA_OPTS += -D NO_DEVICE_REMOTE_WAKEUP
+LUFA_OPTS += -D NO_SOF_EVENTS
# Create the LUFA source path variables by including the LUFA root makefile
|