"help for "A request for the USB device descriptor failed

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys

I am working with at32uc3b1256. I'm using atmel studio 6. I want to send something to my computer. I began with "USB device HID example-EVK1101" and modified it according to my board. then I programmed my MCU. but when I plugged it in to my computer I received this error : "A request for the USB device descriptor failed". I checked the process with wireshark. its result has been shown in below image:

and these are main.c and config files:

main.c:


#include "compiler.h"
#include "preprocessor.h"
#include "board.h"
#include "gpio.h"
#include "sysclk.h"
#include "sleepmgr.h"
#include "conf_usb.h"
#include "udc.h"
#include "udd.h"
#include "ui.h"

//volatile static bool main_b_kbd_enable = false;
volatile static bool main_b_kbd_enable = true;

/*! \brief Main function. Execution starts here.
 */
int main(void)
{
	irq_initialize_vectors();
	cpu_irq_enable();

	// Initialize the sleep manager
	sleepmgr_init();

	sysclk_init();

	board_init();
	ui_init();
	ui_powerdown();
	ui_wakeup_enable();
volatile uint32_t freq = sysclk_get_cpu_hz();
freq ++;
LED_Toggle(LED3);

	// Start USB stack to authorize VBus monitoring
	udc_start();
	//udc_attach();

	if (!udc_include_vbus_monitoring()) {
		// VBUS monitoring is not available on this product
		// thereby VBUS has to be considered as present
		main_vbus_action(true);
	}

	// The main loop manages only the power mode
	// because the USB management is done by interrupt
	while (true) {
#ifdef   USB_DEVICE_LOW_SPEED
		// No USB "Keep a live" interrupt available in low speed
		// to scan keyboard interface then use main loop
		if (main_b_kbd_enable) {
			static uint16_t virtual_sof_sub = 0;
			if (700 == virtual_sof_sub++) {
				virtual_sof_sub = 0;
				static uint16_t virtual_sof = 0;
				ui_process(virtual_sof++);
			}
		}
#else
		sleepmgr_enter_sleep();
#endif
	}
}

void main_vbus_action(bool b_high)
{
	//if (b_high) {
		// Attach USB Device
		udc_attach();
	//} else {
		// VBUS not present
		//udc_detach();
	//}
}

void main_suspend_action(void)
{
	ui_powerdown();
}

void main_resume_action(void)
{
	ui_wakeup();
}

void main_sof_action(void)
{
	if (!main_b_kbd_enable)
		return;
	ui_process(udd_get_frame_number());
}

void main_remotewakeup_enable(void)
{
	ui_wakeup_enable();
}

void main_remotewakeup_disable(void)
{
	ui_wakeup_disable();
}

bool main_kbd_enable(void)
{
	main_b_kbd_enable = true;
	return true;
}

void main_kbd_disable(void)
{
	main_b_kbd_enable = false;
}

the config_clock.h : (I am using a 12MHz crystal)

#ifndef CONF_CLOCK_H_INCLUDED
#define CONF_CLOCK_H_INCLUDED

// ===== System Clock Source Options
//#define CONFIG_SYSCLK_SOURCE        SYSCLK_SRC_RCSYS
//#define CONFIG_SYSCLK_SOURCE          SYSCLK_SRC_OSC0
#define CONFIG_SYSCLK_SOURCE        SYSCLK_SRC_PLL0

// ===== PLL0 Options
#define CONFIG_PLL0_SOURCE            PLL_SRC_OSC0
//#define CONFIG_PLL0_SOURCE          PLL_SRC_OSC1
#define CONFIG_PLL0_MUL               2 /* Fpll = (Fclk * PLL_mul) / PLL_div */
#define CONFIG_PLL0_DIV               2 /* Fpll = (Fclk * PLL_mul) / PLL_div */

// ===== PLL1 Options
#define CONFIG_PLL1_SOURCE          PLL_SRC_OSC0
//#define CONFIG_PLL1_SOURCE          PLL_SRC_OSC1
#define CONFIG_PLL1_MUL             4 /* Fpll = (Fclk * PLL_mul) / PLL_div */
#define CONFIG_PLL1_DIV             1 /* Fpll = (Fclk * PLL_mul) / PLL_div */

// ===== System Clock Bus Division Options
//#define CONFIG_SYSCLK_CPU_DIV       1 /* Fcpu = Fsys/(2 ^ CPU_div) */
//#define CONFIG_SYSCLK_PBA_DIV       1 /* Fpba = Fsys/(2 ^ PBA_div) */
//#define CONFIG_SYSCLK_PBB_DIV       1 /* Fpbb = Fsys/(2 ^ PBB_div) */

// ===== Peripheral Clock Management Options
//#define CONFIG_SYSCLK_INIT_CPUMASK  ((1 << SYSCLK_SYSTIMER) | (1 << SYSCLK_OCD))
//#define CONFIG_SYSCLK_INIT_PBAMASK  (1 << SYSCLK_USART0)
//#define CONFIG_SYSCLK_INIT_PBBMASK  (1 << SYSCLK_HMATRIX)
//#define CONFIG_SYSCLK_INIT_HSBMASK  (1 << SYSCLK_MDMA_HSB)

// ===== USB Clock Source Options
//#define CONFIG_USBCLK_SOURCE        USBCLK_SRC_OSC0
//#define CONFIG_USBCLK_SOURCE          USBCLK_SRC_PLL0
#define CONFIG_USBCLK_SOURCE        USBCLK_SRC_PLL1
#define CONFIG_USBCLK_DIV             0 /* Fusb = Fsys/(2 ^ USB_div) */

#endif /* CONF_CLOCK_H_INCLUDED */

and this my conf_usb.h file:


#ifndef _CONF_USB_H_
#define _CONF_USB_H_

#include "compiler.h"

/**
 * USB Device Configuration
 * @{
 */

//! Device definition (mandatory)
#define  USB_DEVICE_VENDOR_ID             USB_VID_ATMEL
#define  USB_DEVICE_PRODUCT_ID            USB_PID_ATMEL_AVR_HIDKEYBOARD
#define  USB_DEVICE_MAJOR_VERSION         1
#define  USB_DEVICE_MINOR_VERSION         0
#define  USB_DEVICE_POWER                 100 // Consumption on Vbus line (mA)
#define  USB_DEVICE_ATTR                  \
	(USB_CONFIG_ATTR_REMOTE_WAKEUP|USB_CONFIG_ATTR_SELF_POWERED)
//	(USB_CONFIG_ATTR_REMOTE_WAKEUP|USB_CONFIG_ATTR_BUS_POWERED)
//	(USB_CONFIG_ATTR_SELF_POWERED)
//	(USB_CONFIG_ATTR_BUS_POWERED)

//! USB Device string definitions (Optional)
#define  USB_DEVICE_MANUFACTURE_NAME      "ALVAND"
#define  USB_DEVICE_PRODUCT_NAME          "HAMEDAN"
// #define  USB_DEVICE_SERIAL_NAME           "12...EF"

/**
 * Device speeds support
 * @{
 */
//! To define a Low speed device
//#define  USB_DEVICE_LOW_SPEED

//! To authorize the High speed
#if (UC3A3||UC3A4)
//#define  USB_DEVICE_HS_SUPPORT
#endif
//@}

/**
 * USB Device Callbacks definitions (Optional)
 * @{
 */
#define  UDC_VBUS_EVENT(b_vbus_high)      main_vbus_action(b_vbus_high)
#define  UDC_SOF_EVENT()                  main_sof_action()
#define  UDC_SUSPEND_EVENT()              main_suspend_action()
#define  UDC_RESUME_EVENT()               main_resume_action()
//! Mandatory when USB_DEVICE_ATTR authorizes remote wakeup feature
#define  UDC_REMOTEWAKEUP_ENABLE()        main_remotewakeup_enable()
#define  UDC_REMOTEWAKEUP_DISABLE()       main_remotewakeup_disable()
//! When a extra string descriptor must be supported
//! other than manufacturer, product and serial string
// #define  UDC_GET_EXTRA_STRING()
//@}

//@}

/**
 * USB Interface Configuration
 * @{
 */
/**
 * Configuration of HID Keyboard interface
 * @{
 */
//! Interface callback definition
#define  UDI_HID_KBD_ENABLE_EXT()       main_kbd_enable()
#define  UDI_HID_KBD_DISABLE_EXT()      main_kbd_disable()
#define  UDI_HID_KBD_CHANGE_LED(value)  ui_kbd_led(value)
//@}
//@}

/**
 * USB Device Driver Configuration
 * @{
 */
//@}

//! The includes of classes and other headers must be done at the end of this file to avoid compile error
#include "udi_hid_kbd_conf.h"
#include "main.h"
#include "ui.h"

#endif // _CONF_USB_H_

could anyone tell me, what I should do? 

thanks a lot.

This topic has a solution.
Last Edited: Fri. Apr 21, 2017 - 01:02 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In many cases where USB or connections generally fail it is bad soldering, bad cables or an intermittent contact.

And in my experience these things can cause the weirdest behaviour.

 

That would be my starting point.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks for the comment. I checked it. it seems to be OK. the usb part of my board is composed of just a connector and two resistors.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When you speak of "your board" it is hard to distinguish whether you have soldered and designed it yourself or bought a ready board.

 

Another idea would be to use another USB port of your PC. Or -if you have- use another hub or none at all.

 

This effect may occur as well, if

 

- a USB hub is damaged

- a USB hub that has insufficient supply current (in case you have a bus powered circuit) is used

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It could be the USB code is bad.  After your device attaches to the bus, the host issues a RESET and then sends a setup packet requesting a device descriptor.  It doesn't receive the device descriptor.

 

It could also be the clock for the USB hardware is not correct. 

 

I only know the Xmega.  For low speed USB the USB hardware needs a 12MHz clock and for full speed it needs 48MHz.  The clock has to be fairly accurate.  I think you are using a crystal so accuracy shouldn't be a problem.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks for your attention. "my board" is designed by me and it is also soldered by me. I tested it another port and another computer, but it did not worked.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks for the comment. I don't think that is a bad code, because it is an ASF example project. it is written for AT32UC3B0512 IC (EVK1101 board) and I just modified it according my board. I am also using a 12 MHz crystal like EVK1101 board.

 

I apologize for my bad English.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't use ASF so I can't help you there.  Your English is not bad.

 

If you have a debugger you could learn more about the problem.  There are also USB analyzer programs that run on the PC that might help.

 

There is a lot of initialization to the USB registers and endpoint registers that must be done before attaching to the bus.  The speed must be selected.  If the USB hardware has a 12 MHz clock, it must be low speed.  The bus device address must be set to 0.  Endpoint zero must be set to allow input data.  If interrupt driven, the USB interrupts must be enabled.  And probably more.

 

Maybe it's this simple:

http://www.avrfreaks.net/forum/usb-works-at32uc3c2256-not-at32uc3c1256?skey=at32uc3 usb

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hamidkavianathar wrote:

 the usb part of my board is composed of just a connector and two resistors.

Interesting.  The Xmega has the resistors on the chip.  I guess they are electronic because they are calibrated at the factory and the calibration values are stored in the production signature row.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks all for your attentions. thanks for sharing your valuable experiences. finally I found the solution. I had a stupid mistake in connecting D- and D+ to the microcontroller.