// Application Main program __NO_RETURN void app_main (void *argument) { (void)argument; DAP_Setup(); // DAP Setup USBD_Initialize(0U); // USB Device Initialization USBD_Connect(0U); // USB Device Connect while (!USBD_Configured(0U)); // Wait for USB Device to configure LED_CONNECTED_OUT(1U); // Turn on Debugger Connected LED LED_RUNNING_OUT(1U); // Turn on Target Running LED Delayms(500U); // Wait for 500ms LED_RUNNING_OUT(0U); // Turn off Target Running LED LED_CONNECTED_OUT(0U); // Turn off Debugger Connected LED // Create DAP Thread DAP_ThreadId = osThreadNew(DAP_Thread, NULL, &DAP_ThreadAttr); // Create SWO Thread SWO_ThreadId = osThreadNew(SWO_Thread, NULL, &SWO_ThreadAttr); osDelay(osWaitForever); for (;;) {}; }
int main (void) { USB_Init(); ProtocolInit(); // Connect in[0] = XLINK_MODE_SWD; XLINK_Connect(in, out); // Out sequence in[0] = sizeof(jtag2swd) * 8; memcpy(in + 1, jtag2swd, sizeof(jtag2swd)); XLINK_SWJ_Sequence(in, out); // Read ID do { id = 0; in[0] = 0; in[1] = 1; in[2] = 0; in[3] = 1 << 1; XLINK_SWDTransferBlock(in, out); id = *(unsigned long *)&out[3]; }while ((id & 0xFFF) == 0x477); LED_CONNECTED_OUT(0); LED_RUNNING_OUT(0); USB_Connect(__FALSE); USB_Connect(__TRUE); while (!USB_configured()) { LED_CONNECTED_OUT(0); LED_RUNNING_OUT(0); Delayms(50); LED_CONNECTED_OUT(1); LED_RUNNING_OUT(1); Delayms(50); } LED_CONNECTED_OUT(1); LED_RUNNING_OUT(1); while (1) { USB_ProcessCommand(); } }
// Process USB HID Data void usbd_hid_process (void) { uint32_t n; // Process pending requests if ((USB_RequestOut != USB_RequestIn) || USB_RequestFlag) { LED_CONNECTED_OUT(1); // Process DAP Command and prepare response DAP_ProcessCommand(USB_Request[USB_RequestOut], USB_Response[USB_ResponseIn]); // Update request index and flag n = USB_RequestOut + 1; if (n == DAP_PACKET_COUNT) { n = 0; } USB_RequestOut = n; if (USB_RequestOut == USB_RequestIn) { USB_RequestFlag = 0; } if (USB_ResponseIdle) { // Request that data is send back to host USB_ResponseIdle = 0; usbd_hid_get_report_trigger(0, USB_Response[USB_ResponseIn], DAP_PACKET_SIZE); } else { // Update response index and flag n = USB_ResponseIn + 1; if (n == DAP_PACKET_COUNT) { n = 0; } USB_ResponseIn = n; if (USB_ResponseIn == USB_ResponseOut) { USB_ResponseFlag = 1; } } } else { LED_CONNECTED_OUT(0); } }
// Main program int main (void) { DAP_Setup(); // DAP Setup USBD_Initialize(0U); // USB Device Initialization USBD_Connect(0U); // USB Device Connect while (!USBD_Configured(0U)); // Wait for USB Device to configure LED_CONNECTED_OUT(1U); // Turn on Debugger Connected LED LED_RUNNING_OUT(1U); // Turn on Target Running LED Delayms(500U); // Wait for 500ms LED_RUNNING_OUT(0U); // Turn off Target Running LED LED_CONNECTED_OUT(0U); // Turn off Debugger Connected LED // Create HID Thread HID0_ThreadId = osThreadCreate(osThread(HID0_Thread), NULL); osThreadSetPriority(osThreadGetId(), osPriorityIdle); for (;;); // Endless Loop }
// Process Host Status command and prepare response // request: pointer to request data // response: pointer to response data // return: number of bytes in response static uint32_t DAP_HostStatus(uint8_t *request, uint8_t *response) { switch (*request) { case DAP_DEBUGGER_CONNECTED: LED_CONNECTED_OUT((*(request+1) & 1)); break; case DAP_TARGET_RUNNING: LED_RUNNING_OUT((*(request+1) & 1)); break; default: *response = DAP_ERROR; return (1); } *response = DAP_OK; return (1); }