Example #1
0
//! \brief Test 15 - HID mouse with too large endpoint size (USBB hardware limit)
static void main_test15(void)
{
	udd_attach_device();
	main_usb_enum_step1();
	main_usb_enum_step2();
	main_usb_enum_step3();
	main_usb_enum_step4();
	main_usb_enum_step5();
	main_usb_enum_step6();
	main_usb_enum_step7();
	main_usb_enum_step8();
	main_usb_enum_step9();
	main_usb_enum_step10();
	main_usb_enum_step11();
	main_usb_enum_step12();

	// Get configuration descriptor
	main_usb_wait_setup_packet();
	main_conf_desc.conf.bDescriptorType = USB_DT_CONFIGURATION;
	main_conf_desc.conf.bMaxPower       = USB_CONFIG_MAX_POWER(USB_DEVICE_POWER),
	main_conf_desc.conf.bmAttributes         = USB_CONFIG_ATTR_MUST_SET | USB_DEVICE_ATTR,
	main_conf_desc.iface.bInterfaceProtocol  = HID_PROTOCOL_MOUSE;
	main_conf_desc.ep.wMaxPacketSize         = LE16(1023);
	main_usb_send_in((uint8_t*)&main_conf_desc, sizeof(main_conf_desc));
	main_usb_wait_out(NULL,0);
	main_usb_wait_suspend();
	main_detach();
}
//! \brief Test 11 - Wrong value in first setup request get configuration 0
static void main_test11(void)
{
	uint8_t nb_fail;

	main_otg_init();
	udd_attach_device();
	nb_fail = 4;
	while (nb_fail--) {
		main_usb_enum_step1();
		main_usb_enum_step2();
		main_usb_enum_step3();
		main_usb_enum_step4();
		main_usb_enum_step5();
		main_usb_enum_step6();
		main_usb_enum_step7();
		main_usb_enum_step8();
		main_usb_enum_step9();
		main_usb_enum_step10();
		main_usb_enum_step11();

		// Get configuration descriptor
		main_usb_wait_setup_packet();
		main_conf_desc.conf.bDescriptorType = 0xFF;
		main_conf_desc.conf.bMaxPower       = USB_CONFIG_MAX_POWER(USB_DEVICE_POWER);
		main_conf_desc.conf.bmAttributes         = USB_CONFIG_ATTR_MUST_SET | USB_DEVICE_ATTR,
		main_usb_send_in((uint8_t*)&main_conf_desc, sizeof(usb_conf_desc_t));
		main_usb_wait_out(NULL,0);
	}
	main_usb_wait_suspend();
	main_detach();
}
Example #3
0
//! \brief Test 13 - To high power consumption in setup request get configuration 0
static void main_test13(void)
{
	udd_attach_device();
	main_usb_enum_step1();
	main_usb_enum_step2();
	main_usb_enum_step3();
	main_usb_enum_step4();
	main_usb_enum_step5();
	main_usb_enum_step6();
	main_usb_enum_step7();
	main_usb_enum_step8();
	main_usb_enum_step9();
	main_usb_enum_step10();
	main_usb_enum_step11();

	// Get configuration descriptor
	main_usb_wait_setup_packet();
	main_conf_desc.conf.bDescriptorType = USB_DT_CONFIGURATION;
	main_conf_desc.conf.bMaxPower       = USB_CONFIG_MAX_POWER(300);
	main_conf_desc.conf.bmAttributes         = USB_CONFIG_ATTR_MUST_SET | USB_DEVICE_ATTR,
	main_usb_send_in((uint8_t*)&main_conf_desc, sizeof(usb_conf_desc_t));
	main_usb_wait_out(NULL,0);
	main_usb_wait_suspend();
	main_detach();
}
void udd_attach(void)
{
	irqflags_t flags;
	flags = cpu_irq_save();

	// At startup the USB bus state is unknown,
	// therefore the state is considered IDLE to not miss any USB event
	udd_sleep_mode(true);

	// Enable peripheral clock and USB clock
	udd_enable_periph_ck();

	// Authorize attach if VBus is present
	udd_enable_transceiver();
	udd_attach_device();

	// Enable USB line events
	udd_enable_suspend_interrupt();
	udd_enable_wake_up_interrupt();
	udd_enable_resume_interrupt();
	udd_enable_ext_resume_interrupt();
	udd_enable_sof_interrupt();

	cpu_irq_restore(flags);
}
Example #5
0
//! \brief Test 16 - Stall SET CONFIGURATION (with configuration in SELF + 300mA -> must be pass)
static void main_test16(void)
{
	uint8_t nb_fail;

	udd_attach_device();
	nb_fail = 4;
	while (nb_fail--) {
		main_usb_enum_step1();
		main_usb_enum_step2();
		main_usb_enum_step3();
		main_usb_enum_step4();
		main_usb_enum_step5();
		main_usb_enum_step6();
		main_usb_enum_step7();
		main_usb_enum_step8();
		main_usb_enum_step9();
		main_usb_enum_step10();
		main_usb_enum_step11();
		main_usb_enum_step12();
		// Get configuration descriptor
		main_usb_wait_setup_packet();
		main_conf_desc.conf.bDescriptorType = USB_DT_CONFIGURATION;
		main_conf_desc.conf.bMaxPower       = USB_CONFIG_MAX_POWER(300),
		main_conf_desc.conf.bmAttributes         = USB_CONFIG_ATTR_MUST_SET | USB_CONFIG_ATTR_SELF_POWERED;
		main_conf_desc.iface.bInterfaceProtocol  = HID_PROTOCOL_MOUSE;
		main_conf_desc.ep.wMaxPacketSize         = LE16(8);
		main_usb_send_in((uint8_t*)&main_conf_desc, sizeof(main_conf_desc));
		main_usb_wait_out(NULL,0);
		// Set configuration
		main_usb_wait_setup_packet();
		main_usb_stall_after_setup_packet();
	}
	main_usb_wait_suspend();
	main_detach();
}
Example #6
0
void udd_attach(void)
{
	irqflags_t flags;
	flags = cpu_irq_save();

	// At startup the USB bus state is unknown,
	// therefore the state is considered IDLE to not miss any USB event
	udd_sleep_mode(true);
	otg_unfreeze_clock();
	while (!Is_otg_clock_usable());

	// Authorize attach if Vbus is present
	udd_attach_device();

	// Enable USB line events
	udd_enable_reset_interrupt();
	udd_enable_suspend_interrupt();
	udd_enable_wake_up_interrupt();
	udd_enable_sof_interrupt();

	// Reset following interrupts flag
	udd_ack_reset();
	udd_ack_sof();

	// The first suspend interrupt must be forced
	udd_raise_suspend();
	udd_ack_wake_up();
	otg_freeze_clock();
	cpu_irq_restore(flags);
}
Example #7
0
//! \brief Test 20 - Test upstream resume (from USB device)
static void main_test20(void)
{
	udd_attach_device();
	main_usb_enum_step1();
	main_usb_enum_step2();
	main_usb_enum_step3();
	main_usb_enum_step4();
	main_usb_enum_step5();
	main_usb_enum_step6();
	main_usb_enum_step7();
	main_usb_enum_step8();
	main_usb_enum_step9();
	main_usb_enum_step10();
	main_usb_enum_step11();
	main_usb_enum_step12();
	main_usb_enum_step13();
	main_usb_enum_step14();

	// Setup set remotewakeup
	main_usb_wait_setup_packet();
	main_usb_send_in(NULL,0);

	main_usb_wait_suspend();
	delay_ms(100);

	udd_initiate_remote_wake_up();
	main_usb_wait_wakeup();
	main_usb_wait_sof();

	// Setup clear remotewakeup
	main_usb_wait_setup_packet();
	main_usb_send_in(NULL,0);
}
Example #8
0
void udd_attach(void)
{
	irqflags_t flags;
	flags = cpu_irq_save();

	// At startup the USB bus state is unknown, 
	// therefore the state is considered IDLE to not miss any USB event
	udd_sleep_mode(true);
	otg_unfreeze_clock();
	
	// This section of clock check can be improved with a chek of 
	// USB clock source via sysclk()
#if UC3A3
	// For parts with high speed feature, the "USABLE" clock is the UTMI clock,
	// and the UTMI clock is disabled in suspend mode. Thereby, the utmi clock
	// can't be checked when USB line is not attached or in suspend mode 
	// But it is not a issue, because the clock source is the OSC
#else
	// Check USB clock because the source can be a PLL
	while( !Is_clock_usable() );
#endif
	// Authorize attach if VBus is present
	udd_attach_device();

	// (RESET_AND_WAKEUP)
	// After the attach and the first USB suspend, the following USB Reset time can be inferior to CPU restart clock time.
	// Thus, the USB Reset state is not detected and endpoint control is not allocated
	// In this case, a Reset is do automatically after attach.
	udc_reset();	// Reset USB Device Stack Core
	udd_reset_ep_ctrl();	// Reset endpoint control
	udd_ctrl_init();	// Reset endpoint control management

	// Enable USB line events
	udd_enable_reset_interrupt();
	udd_enable_suspend_interrupt();
	udd_enable_wake_up_interrupt();
#ifdef UDC_SOF_EVENT
	udd_enable_sof_interrupt();
#endif
	// Reset following interupts flag
	udd_ack_reset();
	udd_ack_sof();
   
   // The first suspend interrupt must be forced
#if UC3A3
   // With UTMI, the first suspend is detected but must be cleared to reoccur interrupt
   udd_ack_suspend();
#else
   // The first suspend interrupt is not detected else raise it
   udd_raise_suspend();
#endif
	udd_ack_wake_up();
	otg_freeze_clock();
	cpu_irq_restore(flags);
}
Example #9
0
//! \brief Test 3  - Detach after first setup packet
static void main_test3(void)
{
	udd_attach_device();
	main_usb_enum_step1();
	main_usb_enum_step2();
	main_usb_enum_step3();
	main_usb_enum_step4();
	main_usb_wait_setup_packet();
	main_usb_wait_sof();
	main_detach();
}
Example #10
0
//! \brief Test 7  - Detach before reset
static void main_test7(void)
{
	udd_attach_device();
	main_usb_enum_step1();
	main_usb_enum_step2();
	main_usb_enum_step3();
	main_usb_enum_step4();
	main_usb_enum_step5();
	main_usb_wait_sof();
	main_detach();
}
Example #11
0
//! \brief Test 4  - No response data (NACK IN) after first setup packet
static void main_test4(void)
{
	main_otg_init();
	udd_attach_device();
	main_usb_enum_step1();
	main_usb_enum_step2();
	main_usb_enum_step3();
	main_usb_enum_step4();
	main_usb_wait_setup_packet();
	main_usb_enum_step1();
	main_usb_enum_step2();
	main_detach();
}
//! \brief Test 9  - Detach after reset after first setup request get descriptor
static void main_test9(void)
{
	main_otg_init();
	udd_attach_device();
	main_usb_enum_step1();
	main_usb_enum_step2();
	main_usb_enum_step3();
	main_usb_enum_step4();
	main_usb_enum_step5();
	main_usb_enum_step6();
	main_usb_enum_step7();
	main_usb_wait_sof();
	main_detach();
}
Example #13
0
//! \brief Test 5  - Detach after IN data phase of first setup request
static void main_test5(void)
{
	udd_attach_device();
	main_usb_enum_step1();
	main_usb_enum_step2();
	main_usb_enum_step3();
	main_usb_enum_step4();

	// Get Device Descriptor
	main_usb_wait_setup_packet();
	main_device_desc.bDescriptorType = USB_DT_DEVICE;
	main_device_desc.bMaxPacketSize0 = (speed==0)?8:64;
	main_usb_send_in((uint8_t*)&main_device_desc,8);
	main_detach();
}
Example #14
0
//! \brief Test 1 - Attach and no response
static void main_test1(void)
{
	uint8_t nb_fail;

	udd_attach_device();
	nb_fail = 4;
	while (nb_fail--) {
		udd_disable_endpoint(0);
		udd_unallocate_memory(0);
		main_usb_enum_step1();
		main_usb_enum_step2();
		main_usb_enum_step3();
		// Here Host try to communicate on control endpoint 0
	}
	main_usb_wait_suspend();
	main_detach();
}
Example #15
0
//! \brief Test 10 - No send ZLP (NAK IN) after second setup packet (set address)
static void main_test10(void)
{
	udd_attach_device();
	main_usb_enum_step1();
	main_usb_enum_step2();
	main_usb_enum_step3();
	main_usb_enum_step4();
	main_usb_enum_step5();
	main_usb_enum_step6();
	main_usb_enum_step7();
	main_usb_enum_step8();
	main_usb_enable_ctrl_ep(0, (speed==0)?8:64);
	main_usb_wait_setup_packet();
	main_usb_enum_step1();
	main_usb_enum_step2();
	main_detach();
}
Example #16
0
//! \brief Test 8  - Detach during reset after first setup request get descriptor
static void main_test8(void)
{
	udd_attach_device();
	main_usb_enum_step1();
	main_usb_enum_step2();
	main_usb_enum_step3();
	main_usb_enum_step4();
	main_usb_enum_step5();
	main_usb_enum_step6();
	if (Is_udd_low_speed_enable()) {
		delay_ms(25);
	} else {
		main_usb_wait_reset_start();
	}
	main_detach();
	udd_ack_reset(); // Ack previous reset finish by detach
}
Example #17
0
//! \brief Test 17 - Enumeration success (with configuration in BUS + 100mA -> must be pass)
static void main_test17(void)
{
	udd_attach_device();
	main_usb_enum_step1();
	main_usb_enum_step2();
	main_usb_enum_step3();
	main_usb_enum_step4();
	main_usb_enum_step5();
	main_usb_enum_step6();
	main_usb_enum_step7();
	main_usb_enum_step8();
	main_usb_enum_step9();
	main_usb_enum_step10();
	main_usb_enum_step11();
	main_usb_enum_step12();
	main_usb_enum_step13();
	main_usb_enum_step14();
}
Example #18
0
//! \brief Test 2  - Disable endpoint 0 after first setup packet
static void main_test2(void)
{
	uint8_t nb_fail;

	udd_attach_device();
	nb_fail = 4;
	while (nb_fail--) {
		main_usb_enum_step1();
		main_usb_enum_step2();
		main_usb_enum_step3();
		main_usb_enum_step4();
		main_usb_wait_setup_packet();
		udd_disable_endpoint(0);
		// Here Host try to send IN on control endpoint 0
	}
	main_usb_wait_suspend();
	main_detach();
}
Example #19
0
void udd_attach(void)
{
	irqflags_t flags;
	flags = cpu_irq_save();

	// At startup the USB bus state is unknown,
	// therefore the state is considered IDLE to not miss any USB event
	udd_sleep_mode(true);

	udd_ack_suspend_event();
	udd_ack_resume_event();
	udd_attach_device();
	// Enable main USB interrupts
	udd_enable_tc_interrupt();
	udd_enable_busevt_interrupt();
	udd_enable_setup_interrupt();
	udd_enable_start_of_frame_interrupt();

	cpu_irq_restore(flags);
}
Example #20
0
void udd_attach(void)
{
	irqflags_t flags;
	flags = cpu_irq_save();

	// At startup the USB bus state is unknown,
	// therefore the state is considered IDLE to not miss any USB event
	udd_sleep_mode(true);
	otg_unfreeze_clock();
	while( !Is_otg_clock_usable() );

	// Authorize attach if Vbus is present
	udd_attach_device();

	// Enable USB line events
	udd_enable_reset_interrupt();
	udd_enable_suspend_interrupt();
	udd_enable_wake_up_interrupt();
	udd_enable_sof_interrupt();
#ifdef USB_DEVICE_HS_SUPPORT
	udd_enable_msof_interrupt();
#endif
	// Reset following interrupts flag
	udd_ack_reset();
	udd_ack_sof();
	udd_ack_msof();

	// The first suspend interrupt must be forced
#if UC3A3
	// With UTMI, the first suspend is detected but must be cleared to reoccur interrupt
	udd_ack_suspend();
#else
	// The first suspend interrupt is not detected else raise it
	udd_raise_suspend();
#endif
	udd_ack_wake_up();
	otg_freeze_clock();
	cpu_irq_restore(flags);
}
Example #21
0
//! \brief Test 6  - Wrong value in first setup request get descriptor
static void main_test6(void)
{
	uint8_t nb_fail;

	udd_attach_device();
	nb_fail = 4;
	while (nb_fail--) {
		main_usb_enum_step1();
		main_usb_enum_step2();
		main_usb_enum_step3();
		main_usb_enum_step4();

		// Get Device Descriptor
		main_usb_wait_setup_packet();
		main_device_desc.bDescriptorType = 0xFF;
		main_device_desc.bMaxPacketSize0 = 0xFF;
		main_usb_send_in((uint8_t*)&main_device_desc,8);
		main_usb_wait_out(NULL,0);
	}
	main_usb_wait_suspend();
	main_detach();
}