Add experimental support for the AVR32 UC3A4 microcontrollers.
Add support for the inbuilt unique serial numbers in the UC3A3 and UC3A4 models.
This commit is contained in:
		
							parent
							
								
									81fd8d4004
								
							
						
					
					
						commit
						a7eca42996
					
				
					 7 changed files with 78 additions and 29 deletions
				
			
		| 
						 | 
				
			
			@ -87,9 +87,9 @@
 | 
			
		|||
			//@}
 | 
			
		||||
			
 | 
			
		||||
			#if (!defined(NO_INTERNAL_SERIAL) && \
 | 
			
		||||
			     (defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1287__) || \
 | 
			
		||||
			      defined(__AVR_ATmega32U6__) || defined(__AVR_AT90USB646__)  || defined(__AVR_AT90USB1286__) ||  \
 | 
			
		||||
			      defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__)  || defined(__AVR_ATmega8U2__)))
 | 
			
		||||
			     (defined(USB_SERIES_7_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_4_AVR) || \
 | 
			
		||||
			      (defined(USB_SERIES_2_AVR) && (!defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__))) || \
 | 
			
		||||
				  defined(__DOXYGEN__)))
 | 
			
		||||
				/** 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
 | 
			
		||||
				 *  number allocations) to a device regardless of the port it is plugged in to on the host. Some microcontrollers contain
 | 
			
		||||
| 
						 | 
				
			
			@ -190,7 +190,7 @@
 | 
			
		|||
				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;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -213,8 +213,8 @@
 | 
			
		|||
 | 
			
		||||
						SerialByte &= 0x0F;
 | 
			
		||||
 | 
			
		||||
						UnicodeString[SerialCharNum] = (SerialByte >= 10) ?
 | 
			
		||||
						                               (('A' - 10) + SerialByte) : ('0' + SerialByte);
 | 
			
		||||
						UnicodeString[SerialCharNum] = cpu_to_le16((SerialByte >= 10) ?
 | 
			
		||||
						                                           (('A' - 10) + SerialByte) : ('0' + SerialByte));
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
				
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -204,12 +204,12 @@ static void USB_Device_GetInternalSerialDescriptor(void)
 | 
			
		|||
	struct
 | 
			
		||||
	{
 | 
			
		||||
		USB_Descriptor_Header_t Header;
 | 
			
		||||
		wchar_t                 UnicodeString[20];
 | 
			
		||||
		uint16_t                UnicodeString[20];
 | 
			
		||||
	} SignatureDescriptor;
 | 
			
		||||
 | 
			
		||||
	SignatureDescriptor.Header.Type = DTYPE_String;
 | 
			
		||||
	SignatureDescriptor.Header.Size = USB_Device_GetSerialString(SignatureDescriptor.UnicodeString,
 | 
			
		||||
	                                                             sizeof(SignatureDescriptor.UnicodeString));
 | 
			
		||||
	SignatureDescriptor.Header.Size = USB_STRING_LEN(USB_Device_GetSerialString(SignatureDescriptor.UnicodeString,
 | 
			
		||||
	                                                 sizeof(SignatureDescriptor.UnicodeString) / sizeof(SignatureDescriptor.UnicodeString[0])));
 | 
			
		||||
 | 
			
		||||
	Endpoint_ClearSETUP();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -645,15 +645,15 @@
 | 
			
		|||
				uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t
 | 
			
		||||
				                          *   or a value given by the specific class.
 | 
			
		||||
				                          */
 | 
			
		||||
				int16_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
 | 
			
		||||
				                    *   of characters rather than a normal C string so that they are widened to
 | 
			
		||||
				                    *   Unicode size.
 | 
			
		||||
				                    *
 | 
			
		||||
				                    *   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
 | 
			
		||||
				                    *   of an explicit array of ASCII characters.
 | 
			
		||||
				                    */
 | 
			
		||||
				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
 | 
			
		||||
				                     *   of characters rather than a normal C string so that they are widened to
 | 
			
		||||
				                     *   Unicode size.
 | 
			
		||||
				                     *
 | 
			
		||||
				                     *   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
 | 
			
		||||
				                     *   of an explicit array of ASCII characters.
 | 
			
		||||
				                     */
 | 
			
		||||
			} ATTR_PACKED USB_StdDescriptor_String_t;
 | 
			
		||||
 | 
			
		||||
	/* Private Interface - For use in library only: */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -77,16 +77,22 @@
 | 
			
		|||
			#define USB_DEVICE_OPT_FULLSPEED               (0 << 0)
 | 
			
		||||
			//@}
 | 
			
		||||
			
 | 
			
		||||
			/** 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
 | 
			
		||||
			 *  number allocations) to a device regardless of the port it is plugged in to on the host. Some microcontrollers contain
 | 
			
		||||
			 *  a unique serial number internally, and setting the device descriptors serial number string index to this value
 | 
			
		||||
			 *  will cause it to use the internal serial number.
 | 
			
		||||
			 *
 | 
			
		||||
			 *  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                    NO_DESCRIPTOR
 | 
			
		||||
			#if (!defined(NO_INTERNAL_SERIAL) && \
 | 
			
		||||
			     (defined(USB_SERIES_UC3A3_AVR) || defined(USB_SERIES_UC3A4_AVR) || \
 | 
			
		||||
				  defined(__DOXYGEN__)))
 | 
			
		||||
				/** 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
 | 
			
		||||
				 *  number allocations) to a device regardless of the port it is plugged in to on the host. Some microcontrollers contain
 | 
			
		||||
				 *  a unique serial number internally, and setting the device descriptors serial number string index to this value
 | 
			
		||||
				 *  will cause it to use the internal serial number.
 | 
			
		||||
				 *
 | 
			
		||||
				 *  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: */
 | 
			
		||||
			/** Sends a Remote Wakeup request to the host. This signals to the host that the device should
 | 
			
		||||
| 
						 | 
				
			
			@ -171,6 +177,37 @@
 | 
			
		|||
			{
 | 
			
		||||
				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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -294,7 +294,7 @@
 | 
			
		|||
	/* Private Interface - For use in library only: */
 | 
			
		||||
	#if !defined(__DOXYGEN__)
 | 
			
		||||
		/* Macros: */			
 | 
			
		||||
			#if defined(USB_SERIES_UC3A3_AVR)
 | 
			
		||||
			#if (defined(USB_SERIES_UC3A3_AVR) || defined(USB_SERIES_UC3A4_AVR))
 | 
			
		||||
				#define USB_CLOCK_REQUIRED_FREQ  12000000UL
 | 
			
		||||
			#else
 | 
			
		||||
				#define USB_CLOCK_REQUIRED_FREQ  48000000UL
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -153,6 +153,12 @@
 | 
			
		|||
				#define USB_SERIES_UC3A3_AVR
 | 
			
		||||
				#define USB_CAN_BE_DEVICE
 | 
			
		||||
				#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__) || \
 | 
			
		||||
			       defined(__AVR32_UC3B0128__) || defined(__AVR32_UC3B064__))
 | 
			
		||||
				#define USB_SERIES_UC3B0_AVR
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,18 +15,24 @@
 | 
			
		|||
 *   - AT32UC3A164 (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3A364 (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3A364S (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3A464 (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3A464S (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3B064 (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3B164 (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3A0128 (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3A1128 (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3A3128 (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3A3128S (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3A4128 (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3A4128S (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3B0128 (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3B1128 (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3A0256 (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3A1256 (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3A3256 (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3A3256S (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3A4256 (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3A4256S (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3B0256 (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3B1256 (USB Host and Device)
 | 
			
		||||
 *   - AT32UC3A0512 (USB Host and Device)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue