Beispiel #1
0
// CMSIS-DAP task
__task void hid_process(void * argv) {
    dapTask = os_tsk_self();
    while (1) {
        os_evt_wait_or(DAP_PAQUET_RECEIVED, 0xffff);
        usbd_hid_process ();
        main_blink_dap_led(0);
    }
}
Beispiel #2
0
void main (void) 
{
	// set pll out 48Mhz, set cpu clock 48Mhz
	SYS_UnlockReg();
	CLK_EnableXtalRC(CLK_PWRCON_XTL12M_EN_Msk);
	CLK_WaitClockReady(CLK_CLKSTATUS_XTL12M_STB_Msk);
	CLK_SetCoreClock(48000000);
	CLK_EnableModuleClock(USBD_MODULE);
	CLK_SetModuleClock(USBD_MODULE, 0, CLK_CLKDIV_USB(1));
	
	
	DAP_Setup();
	
	USBD_Open(&gsInfo, HID_ClassRequest, NULL);
	HID_Init();
	balabala_hid_init();
	USBD_Start();
	NVIC_EnableIRQ(USBD_IRQn);	
	
	while(1)
	{
		usbd_hid_process();
	}
}
Beispiel #3
0
int main(void)
{
	BoardInit();
	SystemCoreClockUpdate();

	LedConnectedOn();
	if (UserAppDescriptor.UserInit != NULL)
	{
		pUserAppDescriptor = &UserAppDescriptor;
		pUserAppDescriptor->UserInit((CoreDescriptor_t *)&CoreDescriptor);
	}
	LedConnectedOff();

	Delay_ms(100);
	/*
	led_count = 0;
	// Check for USB connected
	while ((GPIOA->IDR & GPIO_Pin_11) != 0)
	{
		if (led_count++ == 0)
			LedConnectedOn();
		else if (led_count == 5)
			LedConnectedOff();
		else if (led_count == 25)
			led_count = 0;
		Delay_ms(10);
	}
	LedConnectedOff();
	*/
	// USB Device Initialization and connect
	usbd_init();
	usbd_connect(__TRUE);

	led_count = 0;
	while (!usbd_configured())	// Wait for USB Device to configure
	{
		if (led_count++ == 0)
			LedConnectedOn();
		else if (led_count == 5)
			LedConnectedOff();
		else if (led_count == 50)
			led_count = 0;
		Delay_ms(10);
	}
	LedConnectedOff();
	Delay_ms(100);				// Wait for 100ms

	led_count = 0;
	led_timeout = TIMEOUT_DELAY;
	usb_rx_ch = -1;
	usb_tx_ch = -1;

	while (1)
	{
		if (pUserAppDescriptor == NULL)
		{	// No user application
			if (led_count++ == 1000000)
			{
				led_count = 0;
				LedConnectedToggle();
			}
			usbd_hid_process();
		}
		else if (!usbd_hid_process())
		{
			// No packet processing
			if (led_timeout == 1000)
			{
				LedConnectedOn();
			}
			else if (led_timeout == 0)
			{
				LedConnectedOff();
				led_timeout = TIMEOUT_DELAY;
			}
			led_timeout--;
			
		}
		else
		{
			led_timeout = TIMEOUT_DELAY;
		}

#if (USBD_CDC_ACM_ENABLE == 1)

		NotifyOnStatusChange();

		// USB -> UART
		if (usb_rx_ch == -1)
			usb_rx_ch = USBD_CDC_ACM_GetChar();

		if (usb_rx_ch != -1)
		{
			if (UART_PutChar (usb_rx_ch) == usb_rx_ch)
				usb_rx_ch = -1;
		}

		// UART -> USB
		if (usb_tx_ch == -1)
			usb_tx_ch = UART_GetChar();

		if (usb_tx_ch != -1)
		{
			if (USBD_CDC_ACM_PutChar(usb_tx_ch) == usb_tx_ch)
				usb_tx_ch = -1;
		}
#endif
	}
}