Commit a7eca429 authored by Dean Camera's avatar Dean Camera

Add experimental support for the AVR32 UC3A4 microcontrollers.

Add support for the inbuilt unique serial numbers in the UC3A3 and UC3A4 models.
parent 81fd8d40
...@@ -87,9 +87,9 @@ ...@@ -87,9 +87,9 @@
//@} //@}
#if (!defined(NO_INTERNAL_SERIAL) && \ #if (!defined(NO_INTERNAL_SERIAL) && \
(defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1287__) || \ (defined(USB_SERIES_7_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_4_AVR) || \
defined(__AVR_ATmega32U6__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) || \ (defined(USB_SERIES_2_AVR) && (!defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__))) || \
defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega8U2__))) defined(__DOXYGEN__)))
/** String descriptor index for the device's unique serial number string descriptor within the device. /** String descriptor index for the device's unique serial number string descriptor within the device.
* This unique serial number is used by the host to associate resources to the device (such as drivers or COM port * This unique serial number is used by the host to associate resources to the device (such as drivers or COM port
* number allocations) to a device regardless of the port it is plugged in to on the host. Some microcontrollers contain * number allocations) to a device regardless of the port it is plugged in to on the host. Some microcontrollers contain
...@@ -190,7 +190,7 @@ ...@@ -190,7 +190,7 @@
return (UDADDR & (1 << ADDEN)); return (UDADDR & (1 << ADDEN));
} }
static inline uint8_t USB_Device_GetSerialString(wchar_t* UnicodeString, const uint8_t MaxLen) static inline uint8_t USB_Device_GetSerialString(uint16_t* UnicodeString, const uint8_t MaxLen)
{ {
uint8_t SerialCharNum = 0; uint8_t SerialCharNum = 0;
...@@ -213,8 +213,8 @@ ...@@ -213,8 +213,8 @@
SerialByte &= 0x0F; SerialByte &= 0x0F;
UnicodeString[SerialCharNum] = (SerialByte >= 10) ? UnicodeString[SerialCharNum] = cpu_to_le16((SerialByte >= 10) ?
(('A' - 10) + SerialByte) : ('0' + SerialByte); (('A' - 10) + SerialByte) : ('0' + SerialByte));
} }
} }
......
...@@ -204,12 +204,12 @@ static void USB_Device_GetInternalSerialDescriptor(void) ...@@ -204,12 +204,12 @@ static void USB_Device_GetInternalSerialDescriptor(void)
struct struct
{ {
USB_Descriptor_Header_t Header; USB_Descriptor_Header_t Header;
wchar_t UnicodeString[20]; uint16_t UnicodeString[20];
} SignatureDescriptor; } SignatureDescriptor;
SignatureDescriptor.Header.Type = DTYPE_String; SignatureDescriptor.Header.Type = DTYPE_String;
SignatureDescriptor.Header.Size = USB_Device_GetSerialString(SignatureDescriptor.UnicodeString, SignatureDescriptor.Header.Size = USB_STRING_LEN(USB_Device_GetSerialString(SignatureDescriptor.UnicodeString,
sizeof(SignatureDescriptor.UnicodeString)); sizeof(SignatureDescriptor.UnicodeString) / sizeof(SignatureDescriptor.UnicodeString[0])));
Endpoint_ClearSETUP(); Endpoint_ClearSETUP();
......
...@@ -645,15 +645,15 @@ ...@@ -645,15 +645,15 @@
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t
* or a value given by the specific class. * or a value given by the specific class.
*/ */
int16_t bString[]; /**< String data, as unicode characters (alternatively, string language IDs). uint16_t bString[]; /**< String data, as unicode characters (alternatively, string language IDs).
* If normal ASCII characters are to be used, they must be added as an array * If normal ASCII characters are to be used, they must be added as an array
* of characters rather than a normal C string so that they are widened to * of characters rather than a normal C string so that they are widened to
* Unicode size. * Unicode size.
* *
* Under GCC, strings prefixed with the "L" character (before the opening string * Under GCC, strings prefixed with the "L" character (before the opening string
* quotation mark) are considered to be Unicode strings, and may be used instead * quotation mark) are considered to be Unicode strings, and may be used instead
* of an explicit array of ASCII characters. * of an explicit array of ASCII characters.
*/ */
} ATTR_PACKED USB_StdDescriptor_String_t; } ATTR_PACKED USB_StdDescriptor_String_t;
/* Private Interface - For use in library only: */ /* Private Interface - For use in library only: */
......
...@@ -77,16 +77,22 @@ ...@@ -77,16 +77,22 @@
#define USB_DEVICE_OPT_FULLSPEED (0 << 0) #define USB_DEVICE_OPT_FULLSPEED (0 << 0)
//@} //@}
/** String descriptor index for the device's unique serial number string descriptor within the device. #if (!defined(NO_INTERNAL_SERIAL) && \
* This unique serial number is used by the host to associate resources to the device (such as drivers or COM port (defined(USB_SERIES_UC3A3_AVR) || defined(USB_SERIES_UC3A4_AVR) || \
* number allocations) to a device regardless of the port it is plugged in to on the host. Some microcontrollers contain defined(__DOXYGEN__)))
* a unique serial number internally, and setting the device descriptors serial number string index to this value /** String descriptor index for the device's unique serial number string descriptor within the device.
* will cause it to use the internal serial number. * This unique serial number is used by the host to associate resources to the device (such as drivers or COM port
* * number allocations) to a device regardless of the port it is plugged in to on the host. Some microcontrollers contain
* On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR and so will force the host to create a pseudo-serial * a unique serial number internally, and setting the device descriptors serial number string index to this value
* number for the device. * will cause it to use the internal serial number.
*/ *
#define USE_INTERNAL_SERIAL NO_DESCRIPTOR * On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR and so will force the host to create a pseudo-serial
* number for the device.
*/
#define USE_INTERNAL_SERIAL 0xDC
#else
#define USE_INTERNAL_SERIAL NO_DESCRIPTOR
#endif
/* Function Prototypes: */ /* Function Prototypes: */
/** Sends a Remote Wakeup request to the host. This signals to the host that the device should /** Sends a Remote Wakeup request to the host. This signals to the host that the device should
...@@ -171,6 +177,37 @@ ...@@ -171,6 +177,37 @@
{ {
return AVR32_USBB.UDCON.adden; return AVR32_USBB.UDCON.adden;
} }
static inline uint8_t USB_Device_GetSerialString(uint16_t* UnicodeString, const uint8_t MaxLen)
{
uint8_t SerialCharNum = 0;
ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
{
uint32_t* SigReadAddress = 0x80800204;
for (SerialCharNum = 0; SerialCharNum < MIN(MaxLen, 30); SerialCharNum++)
{
if (SerialCharNum == MaxLen)
break;
uint8_t SerialByte = *SigReadAddress;
if (SerialCharNum & 0x01)
{
SerialByte >>= 4;
SigReadAddress++;
}
SerialByte &= 0x0F;
UnicodeString[SerialCharNum] = cpu_to_le16((SerialByte >= 10) ?
(('A' - 10) + SerialByte) : ('0' + SerialByte));
}
}
return SerialCharNum;
}
#endif #endif
#endif #endif
......
...@@ -294,7 +294,7 @@ ...@@ -294,7 +294,7 @@
/* Private Interface - For use in library only: */ /* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__) #if !defined(__DOXYGEN__)
/* Macros: */ /* Macros: */
#if defined(USB_SERIES_UC3A3_AVR) #if (defined(USB_SERIES_UC3A3_AVR) || defined(USB_SERIES_UC3A4_AVR))
#define USB_CLOCK_REQUIRED_FREQ 12000000UL #define USB_CLOCK_REQUIRED_FREQ 12000000UL
#else #else
#define USB_CLOCK_REQUIRED_FREQ 48000000UL #define USB_CLOCK_REQUIRED_FREQ 48000000UL
......
...@@ -153,6 +153,12 @@ ...@@ -153,6 +153,12 @@
#define USB_SERIES_UC3A3_AVR #define USB_SERIES_UC3A3_AVR
#define USB_CAN_BE_DEVICE #define USB_CAN_BE_DEVICE
#define USB_CAN_BE_HOST #define USB_CAN_BE_HOST
#elif (defined(__AVR32_UC3A4256__) || defined(__AVR32_UC3A4256S__) || \
defined(__AVR32_UC3A4128__) || defined(__AVR32_UC3A4128S__) || \
defined(__AVR32_UC3A464__) || defined(__AVR32_UC3A464S__))
#define USB_SERIES_UC3A4_AVR
#define USB_CAN_BE_DEVICE
#define USB_CAN_BE_HOST
#elif (defined(__AVR32_UC3B0512__) || defined(__AVR32_UC3B0256__) || \ #elif (defined(__AVR32_UC3B0512__) || defined(__AVR32_UC3B0256__) || \
defined(__AVR32_UC3B0128__) || defined(__AVR32_UC3B064__)) defined(__AVR32_UC3B0128__) || defined(__AVR32_UC3B064__))
#define USB_SERIES_UC3B0_AVR #define USB_SERIES_UC3B0_AVR
......
...@@ -15,18 +15,24 @@ ...@@ -15,18 +15,24 @@
* - AT32UC3A164 (USB Host and Device) * - AT32UC3A164 (USB Host and Device)
* - AT32UC3A364 (USB Host and Device) * - AT32UC3A364 (USB Host and Device)
* - AT32UC3A364S (USB Host and Device) * - AT32UC3A364S (USB Host and Device)
* - AT32UC3A464 (USB Host and Device)
* - AT32UC3A464S (USB Host and Device)
* - AT32UC3B064 (USB Host and Device) * - AT32UC3B064 (USB Host and Device)
* - AT32UC3B164 (USB Host and Device) * - AT32UC3B164 (USB Host and Device)
* - AT32UC3A0128 (USB Host and Device) * - AT32UC3A0128 (USB Host and Device)
* - AT32UC3A1128 (USB Host and Device) * - AT32UC3A1128 (USB Host and Device)
* - AT32UC3A3128 (USB Host and Device) * - AT32UC3A3128 (USB Host and Device)
* - AT32UC3A3128S (USB Host and Device) * - AT32UC3A3128S (USB Host and Device)
* - AT32UC3A4128 (USB Host and Device)
* - AT32UC3A4128S (USB Host and Device)
* - AT32UC3B0128 (USB Host and Device) * - AT32UC3B0128 (USB Host and Device)
* - AT32UC3B1128 (USB Host and Device) * - AT32UC3B1128 (USB Host and Device)
* - AT32UC3A0256 (USB Host and Device) * - AT32UC3A0256 (USB Host and Device)
* - AT32UC3A1256 (USB Host and Device) * - AT32UC3A1256 (USB Host and Device)
* - AT32UC3A3256 (USB Host and Device) * - AT32UC3A3256 (USB Host and Device)
* - AT32UC3A3256S (USB Host and Device) * - AT32UC3A3256S (USB Host and Device)
* - AT32UC3A4256 (USB Host and Device)
* - AT32UC3A4256S (USB Host and Device)
* - AT32UC3B0256 (USB Host and Device) * - AT32UC3B0256 (USB Host and Device)
* - AT32UC3B1256 (USB Host and Device) * - AT32UC3B1256 (USB Host and Device)
* - AT32UC3A0512 (USB Host and Device) * - AT32UC3A0512 (USB Host and Device)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment