Fixed invalid USB controller PLL prescaler values for the ATMEGAxxU2 controllers

Fixed lack of support for the ATMEGA32U2 in the DFU and CDC class bootloaders

Changed incomplete Webserver project over to using the uIP timer library.
pull/1469/head
Dean Camera 15 years ago
parent f0d6d4ef13
commit 77dda302ac

@ -40,29 +40,21 @@
#include <LUFA/Drivers/USB/USB.h> #include <LUFA/Drivers/USB/USB.h>
/* Macros: */ /* Macros: */
#if defined(__AVR_AT90USB1286__) #if defined(__AVR_AT90USB1287__)
#define AVR_SIGNATURE_1 0x1E #define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x97 #define AVR_SIGNATURE_2 0x97
#define AVR_SIGNATURE_3 0x82 #define AVR_SIGNATURE_3 0x82
#elif defined(__AVR_AT90USB1287__)
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x97
#define AVR_SIGNATURE_3 0x82
#elif defined(__AVR_AT90USB646__)
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x96
#define AVR_SIGNATURE_3 0x82
#elif defined(__AVR_AT90USB647__) #elif defined(__AVR_AT90USB647__)
#define AVR_SIGNATURE_1 0x1E #define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x96 #define AVR_SIGNATURE_2 0x96
#define AVR_SIGNATURE_3 0x82 #define AVR_SIGNATURE_3 0x82
#elif defined(__AVR_AT90USB162__) #elif defined(__AVR_AT90USB1286__)
#define AVR_SIGNATURE_1 0x1E #define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x94 #define AVR_SIGNATURE_2 0x97
#define AVR_SIGNATURE_3 0x82 #define AVR_SIGNATURE_3 0x82
#elif defined(__AVR_AT90USB82__) #elif defined(__AVR_AT90USB646__)
#define AVR_SIGNATURE_1 0x1E #define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x94 #define AVR_SIGNATURE_2 0x96
#define AVR_SIGNATURE_3 0x82 #define AVR_SIGNATURE_3 0x82
#elif defined(__AVR_ATmega32U6__) #elif defined(__AVR_ATmega32U6__)
#define AVR_SIGNATURE_1 0x1E #define AVR_SIGNATURE_1 0x1E
@ -76,6 +68,26 @@
#define AVR_SIGNATURE_1 0x1E #define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x94 #define AVR_SIGNATURE_2 0x94
#define AVR_SIGNATURE_3 0x88 #define AVR_SIGNATURE_3 0x88
#elif defined(__AVR_ATmega32U2__)
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x94
#define AVR_SIGNATURE_3 0x82
#elif defined(__AVR_ATmega16U2__)
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x94
#define AVR_SIGNATURE_3 0x89
#elif defined(__AVR_AT90USB162__)
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x94
#define AVR_SIGNATURE_3 0x82
#elif defined(__AVR_ATmega8U2__)
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x93
#define AVR_SIGNATURE_3 0x82
#elif defined(__AVR_AT90USB82__)
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x93
#define AVR_SIGNATURE_3 0x89
#else #else
#error The selected AVR part is not currently supported by this bootloader. #error The selected AVR part is not currently supported by this bootloader.
#endif #endif

@ -63,12 +63,17 @@
*/ */
#define ATTR_CAN_DOWNLOAD (1 << 0) #define ATTR_CAN_DOWNLOAD (1 << 0)
#if defined(__AVR_AT90USB1286__) #if defined(__AVR_AT90USB1287__)
#define PRODUCT_ID_CODE 0x2FFB #define PRODUCT_ID_CODE 0x2FFB
#define AVR_SIGNATURE_1 0x1E #define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x97 #define AVR_SIGNATURE_2 0x97
#define AVR_SIGNATURE_3 0x82 #define AVR_SIGNATURE_3 0x82
#elif defined(__AVR_AT90USB1287__) #elif defined(__AVR_AT90USB647__)
#define PRODUCT_ID_CODE 0x2FF9
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x96
#define AVR_SIGNATURE_3 0x82
#elif defined(__AVR_AT90USB1286__)
#define PRODUCT_ID_CODE 0x2FFB #define PRODUCT_ID_CODE 0x2FFB
#define AVR_SIGNATURE_1 0x1E #define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x97 #define AVR_SIGNATURE_2 0x97
@ -83,11 +88,6 @@
#define AVR_SIGNATURE_1 0x1E #define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x95 #define AVR_SIGNATURE_2 0x95
#define AVR_SIGNATURE_3 0x88 #define AVR_SIGNATURE_3 0x88
#elif defined(__AVR_AT90USB647__)
#define PRODUCT_ID_CODE 0x2FF9
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x96
#define AVR_SIGNATURE_3 0x82
#elif defined(__AVR_ATmega32U4__) #elif defined(__AVR_ATmega32U4__)
#define PRODUCT_ID_CODE 0x2FF4 #define PRODUCT_ID_CODE 0x2FF4
#define AVR_SIGNATURE_1 0x1E #define AVR_SIGNATURE_1 0x1E
@ -98,6 +98,16 @@
#define AVR_SIGNATURE_1 0x1E #define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x94 #define AVR_SIGNATURE_2 0x94
#define AVR_SIGNATURE_3 0x88 #define AVR_SIGNATURE_3 0x88
#elif defined(__AVR_ATmega32U2__)
#define PRODUCT_ID_CODE 0x2FF0
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x94
#define AVR_SIGNATURE_3 0x82
#elif defined(__AVR_ATmega16U2__)
#define PRODUCT_ID_CODE 0x2FEF
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x94
#define AVR_SIGNATURE_3 0x89
#elif defined(__AVR_AT90USB162__) #elif defined(__AVR_AT90USB162__)
#define PRODUCT_ID_CODE 0x2FFA #define PRODUCT_ID_CODE 0x2FFA
#define AVR_SIGNATURE_1 0x1E #define AVR_SIGNATURE_1 0x1E
@ -108,11 +118,6 @@
#define AVR_SIGNATURE_1 0x1E #define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x93 #define AVR_SIGNATURE_2 0x93
#define AVR_SIGNATURE_3 0x82 #define AVR_SIGNATURE_3 0x82
#elif defined(__AVR_ATmega16U2__)
#define PRODUCT_ID_CODE 0x2FEF
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x94
#define AVR_SIGNATURE_3 0x89
#elif defined(__AVR_AT90USB82__) #elif defined(__AVR_AT90USB82__)
#define PRODUCT_ID_CODE 0x2FEE #define PRODUCT_ID_CODE 0x2FEE
#define AVR_SIGNATURE_1 0x1E #define AVR_SIGNATURE_1 0x1E

@ -76,7 +76,8 @@
#if (F_CLOCK == 8000000) #if (F_CLOCK == 8000000)
#if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \ #if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \
defined(__AVR_ATMEGA8U2__) || defined(__AVR_ATMEGA16U2__)) defined(__AVR_ATmega8U2__) || defined(__AVR_ATmega16U2__) || \
defined(__AVR_ATmega32U2))
#define USB_PLL_PSC 0 #define USB_PLL_PSC 0
#elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))
#define USB_PLL_PSC 0 #define USB_PLL_PSC 0
@ -87,7 +88,8 @@
#endif #endif
#elif (F_CLOCK == 16000000) #elif (F_CLOCK == 16000000)
#if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \ #if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \
defined(__AVR_ATMEGA8U2__) || defined(__AVR_ATMEGA16U2__)) defined(__AVR_ATmega8U2__) || defined(__AVR_ATmega16U2__) || \
defined(__AVR_ATmega32U2))
#define USB_PLL_PSC (1 << PLLP0) #define USB_PLL_PSC (1 << PLLP0)
#elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))
#define USB_PLL_PSC (1 << PINDIV) #define USB_PLL_PSC (1 << PINDIV)

@ -35,6 +35,8 @@
* - Fixed XPLAIN board Dataflash driver broken due to incorrect preprocessor commands * - Fixed XPLAIN board Dataflash driver broken due to incorrect preprocessor commands
* - Fixed inverted XPLAIN LED driver output (LED turned on when it was supposed to be turned off, and vice-versa) * - Fixed inverted XPLAIN LED driver output (LED turned on when it was supposed to be turned off, and vice-versa)
* - Fixed Class Driver struct interface numbers in the KeyboardMouse and VirtualSerialMouse demos (thanks to Renaud Cerrato) * - Fixed Class Driver struct interface numbers in the KeyboardMouse and VirtualSerialMouse demos (thanks to Renaud Cerrato)
* - Fixed invalid USB controller PLL prescaler values for the ATMEGAxxU2 controllers
* - Fixed lack of support for the ATMEGA32U2 in the DFU and CDC class bootloaders
* *
* \section Sec_ChangeLog091223 Version 091223 * \section Sec_ChangeLog091223 Version 091223
* *

@ -12,7 +12,7 @@
volatile clock_time_t clock_datetime = 0; volatile clock_time_t clock_datetime = 0;
//Overflow interrupt //Overflow interrupt
ISR(TIMER0_OVF_vect) ISR(TIMER1_COMPA_vect)
{ {
clock_datetime += 1; clock_datetime += 1;
} }
@ -20,14 +20,10 @@ ISR(TIMER0_OVF_vect)
//Initialise the clock //Initialise the clock
void clock_init() void clock_init()
{ {
//Activate overflow interrupt for timer0 OCR1A = ((F_CPU / 1024) / 100);
TIMSK0 |= (1<<TOIE0); TCCR1A = (1 << WGM12);
TCCR1B = ((1 << CS12) | (1 << CS10));
//Use prescaler 1024 TIMSK1 = (1 << OCIE1A);
TCCR0B |= ((1<<CS12)|(1<<CS10));
//Activate interrupts
sei();
} }
//Return time //Return time

@ -5,7 +5,7 @@
#include <stdint.h> #include <stdint.h>
typedef uint16_t clock_time_t; typedef uint16_t clock_time_t;
#define CLOCK_CONF_SECOND (F_CPU / 1024 / 255) //Freqency divided prescaler and counter register size #define CLOCK_CONF_SECOND 100
void clock_init(void); void clock_init(void);
clock_time_t clock_time(void); clock_time_t clock_time(void);

@ -57,13 +57,13 @@ USB_ClassInfo_RNDIS_Host_t Ethernet_RNDIS_Interface =
}, },
}; };
volatile uint8_t uIPManagementTimeout; struct timer ConnectionTimer, ARPTimer;
uint16_t MillisecondTickCount;
/** ISR for the management of the connection management timeout counter */ /** ISR for the management of the connection management timeout counter */
ISR(TIMER0_COMPA_vect, ISR_BLOCK) ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{ {
if (uIPManagementTimeout) MillisecondTickCount++;
uIPManagementTimeout--;
} }
void TCPCallback(void) void TCPCallback(void)
@ -186,9 +186,8 @@ void ProcessIncommingPacket(void)
printf("0x%02X ", uip_buf[i]); printf("0x%02X ", uip_buf[i]);
printf("\r\n\r\n"); printf("\r\n\r\n");
#define BUF ((struct uip_eth_hdr *)&uip_buf[0]) struct uip_eth_hdr* EthernetHeader = (struct uip_eth_hdr*)&uip_buf[0];
if (EthernetHeader->type == HTONS(UIP_ETHTYPE_IP))
if (BUF->type == HTONS(UIP_ETHTYPE_IP))
{ {
/* Filter packet by MAC destination */ /* Filter packet by MAC destination */
uip_arp_ipin(); uip_arp_ipin();
@ -200,7 +199,7 @@ void ProcessIncommingPacket(void)
if (uip_len > 0) if (uip_len > 0)
uip_arp_out(); uip_arp_out();
} }
else if (BUF->type == HTONS(UIP_ETHTYPE_ARP)) else if (EthernetHeader->type == HTONS(UIP_ETHTYPE_ARP))
{ {
/* Process ARP packet */ /* Process ARP packet */
uip_arp_arpin(); uip_arp_arpin();
@ -221,8 +220,10 @@ void ProcessIncommingPacket(void)
void ManageConnections(void) void ManageConnections(void)
{ {
if (!(uIPManagementTimeout)) if (timer_expired(&ConnectionTimer))
{ {
timer_reset(&ConnectionTimer);
LEDs_SetAllLEDs(LEDMASK_USB_BUSY); LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
for (uint8_t i = 0; i < UIP_CONNS; i++) for (uint8_t i = 0; i < UIP_CONNS; i++)
@ -235,12 +236,14 @@ void ManageConnections(void)
RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, &uip_buf, uip_len); RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, &uip_buf, uip_len);
} }
uip_arp_timer();
uIPManagementTimeout = 250;
LEDs_SetAllLEDs(LEDMASK_USB_READY); LEDs_SetAllLEDs(LEDMASK_USB_READY);
} }
if (timer_expired(&ARPTimer))
{
timer_reset(&ARPTimer);
uip_arp_timer();
}
} }
/** Configures the board hardware and chip peripherals for the demo's functionality. */ /** Configures the board hardware and chip peripherals for the demo's functionality. */
@ -258,17 +261,16 @@ void SetupHardware(void)
LEDs_Init(); LEDs_Init();
USB_Init(); USB_Init();
/* Millisecond timer initialization for managing the command timeout counter */ /* uIP Timing Initialization */
OCR0A = ((F_CPU / 64) / 1000); clock_init();
TCCR0A = (1 << WGM01); timer_set(&ConnectionTimer, CLOCK_SECOND / 2);
TCCR0B = ((1 << CS01) | (1 << CS00)); timer_set(&ARPTimer, CLOCK_SECOND * 10);
/* uIP Stack Initialization */ /* uIP Stack Initialization */
uip_init(); uip_init();
uip_ipaddr_t IPAddress, Netmask, GatewayIPAddress; uip_ipaddr_t IPAddress, Netmask, GatewayIPAddress;
uip_ipaddr(&IPAddress, 192, 168, 1, 10); uip_ipaddr(&IPAddress, 192, 168, 1, 10);
uip_ipaddr(&Netmask, 0xFF, 0xFF, 0xFF, 0x00); uip_ipaddr(&Netmask, 255, 255, 255, 0);
uip_ipaddr(&GatewayIPAddress, 192, 168, 1, 1); uip_ipaddr(&GatewayIPAddress, 192, 168, 1, 1);
uip_sethostaddr(&IPAddress); uip_sethostaddr(&IPAddress);
uip_setnetmask(&Netmask); uip_setnetmask(&Netmask);

@ -52,6 +52,7 @@
#include <uip.h> #include <uip.h>
#include <uip_arp.h> #include <uip_arp.h>
#include <timer.h>
/* Macros: */ /* Macros: */
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */

@ -142,6 +142,7 @@ SRC = $(TARGET).c \
Lib/uip/psock.c \ Lib/uip/psock.c \
Lib/uip/timer.c \ Lib/uip/timer.c \
Lib/uip/uip-neighbor.c \ Lib/uip/uip-neighbor.c \
Lib/uip/conf/clock-arch.c \
# List C++ source files here. (C dependencies are automatically generated.) # List C++ source files here. (C dependencies are automatically generated.)

Loading…
Cancel
Save