Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
DAP_vendor.c
00001 /* 00002 * Copyright (c) 2013-2016 ARM Limited. All rights reserved. 00003 * Copyright 2019, Cypress Semiconductor Corporation 00004 * or a subsidiary of Cypress Semiconductor Corporation. 00005 * 00006 * SPDX-License-Identifier: Apache-2.0 00007 * 00008 * Licensed under the Apache License, Version 2.0 (the License); you may 00009 * not use this file except in compliance with the License. 00010 * You may obtain a copy of the License at 00011 * 00012 * www.apache.org/licenses/LICENSE-2.0 00013 * 00014 * Unless required by applicable law or agreed to in writing, software 00015 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00016 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00017 * See the License for the specific language governing permissions and 00018 * limitations under the License. 00019 * 00020 * ---------------------------------------------------------------------- 00021 * 00022 * $Date: 20. May 2015 00023 * $Revision: V1.10 00024 * 00025 * Project: CMSIS-DAP Source 00026 * Title: DAP_vendor.c CMSIS-DAP Vendor Commands 00027 * 00028 *---------------------------------------------------------------------------*/ 00029 00030 #include "rl_usb.h" 00031 #include "DAP_config.h" 00032 #include "DAP.h" 00033 #include "info.h" 00034 #include "main.h" 00035 #include "uart.h" 00036 #include "settings.h" 00037 #include "target_family.h" 00038 #include "flash_manager.h" 00039 #include <string.h> 00040 00041 00042 #ifdef DRAG_N_DROP_SUPPORT 00043 #include "file_stream.h" 00044 #endif 00045 00046 //************************************************************************************************** 00047 /** 00048 \defgroup DAP_Vendor_Adapt_gr Adapt Vendor Commands 00049 \ingroup DAP_Vendor_gr 00050 @{ 00051 00052 The file DAP_vendor.c provides template source code for extension of a Debug Unit with 00053 Vendor Commands. Copy this file to the project folder of the Debug Unit and add the 00054 file to the MDK-ARM project under the file group Configuration. 00055 */ 00056 00057 /** Process DAP Vendor Command and prepare Response Data 00058 \param request pointer to request data 00059 \param response pointer to response data 00060 \return number of bytes in response (lower 16 bits) 00061 number of bytes in request (upper 16 bits) 00062 */ 00063 uint32_t DAP_ProcessVendorCommand(const uint8_t *request, uint8_t *response) { 00064 uint32_t num = (1U << 16) | 1U; 00065 00066 *response++ = *request; // copy Command ID 00067 00068 switch (*request++) { // first byte in request is Command ID 00069 case ID_DAP_Vendor0: { 00070 const char *id_str = info_get_unique_id(); 00071 uint8_t len = strlen(id_str); 00072 *response++ = len; 00073 memcpy(response, id_str, len); 00074 num += (len + 1); // increment response count by ID length + length byte 00075 break; 00076 } 00077 case ID_DAP_Vendor1: { 00078 // get line coding 00079 int32_t read_len = sizeof(CDC_LINE_CODING); 00080 CDC_LINE_CODING cdc_line_coding; 00081 USBD_CDC_ACM_PortGetLineCoding(&cdc_line_coding); 00082 memcpy(response, &cdc_line_coding, read_len); 00083 num += (read_len + 1); 00084 break; 00085 } 00086 case ID_DAP_Vendor2: { 00087 // set uart configuration 00088 CDC_LINE_CODING cdc_line_coding; 00089 USBD_CDC_ACM_PortGetLineCoding(&cdc_line_coding); 00090 //set BaudRate 00091 uint32_t baud_rate = 0; 00092 memcpy(&baud_rate, request, sizeof(uint32_t)); 00093 cdc_line_coding.dwDTERate = baud_rate; 00094 USBD_CDC_ACM_PortSetLineCoding(&cdc_line_coding); 00095 USBD_CDC_ACM_SendBreak(0); 00096 *response = 1; 00097 num += (sizeof(uint32_t) << 16) | 1; 00098 break; 00099 } 00100 case ID_DAP_Vendor3: { 00101 // uart read 00102 int32_t read_len = 62; 00103 read_len = uart_read_data(response + 1, read_len); 00104 response[0] = read_len; 00105 // increment request and response count 00106 num += (read_len + 1); 00107 break; 00108 } 00109 case ID_DAP_Vendor4: { 00110 // uart write 00111 int32_t write_len = *request; 00112 request++; 00113 uart_write_data((uint8_t *)request, write_len); 00114 *response = 1; 00115 num += ((write_len + 1) << 16) | 1; 00116 break; 00117 } 00118 case ID_DAP_Vendor5: break; 00119 case ID_DAP_Vendor6: break; 00120 case ID_DAP_Vendor7: break; 00121 case ID_DAP_Vendor8: { 00122 *response = 1; 00123 if (0 == *request) { 00124 main_usb_set_test_mode(false); 00125 } else if (1 == *request) { 00126 main_usb_set_test_mode(true); 00127 } else { 00128 *response = 0; 00129 } 00130 num += (1U << 16) | 1U; // increment request and response count each by 1 00131 break; 00132 } 00133 case ID_DAP_Vendor9: { 00134 // reset target 00135 *response = 1; 00136 if (!config_get_auto_rst()) { 00137 target_set_state(RESET_RUN); 00138 } 00139 num += 1; 00140 break; 00141 } 00142 #ifdef DRAG_N_DROP_SUPPORT 00143 case ID_DAP_Vendor10: { 00144 // open mass storage device stream 00145 *response = stream_open((stream_type_t)(*request)); 00146 num += (1 << 16) | 1; 00147 break; 00148 } 00149 case ID_DAP_Vendor11: { 00150 // close mass storage device stream 00151 *response = stream_close(); 00152 num += 1; 00153 break; 00154 } 00155 case ID_DAP_Vendor12: { 00156 // write to mass storage device 00157 uint32_t write_len = *request; 00158 request++; 00159 *response = stream_write((uint8_t *)request, write_len); 00160 num += ((write_len + 1) << 16) | 1; 00161 break; 00162 } 00163 #endif 00164 case ID_DAP_Vendor13: { 00165 // switching between chip erase and page erase 00166 // COMMAND(OUT Packet) 00167 // BYTE 0 1000 1110 0x8D 00168 // BYTE 1 Desired Mode: 00169 // 0x00 - Chip Erase 00170 // nonzero - Page Erase 00171 // RESPONSE(IN Packet) 00172 // BYTE 0 00173 // 0x00 - OK 00174 *response = DAP_OK; 00175 if (0x00U == *request) { 00176 flash_manager_set_page_erase(false); 00177 } else { 00178 flash_manager_set_page_erase(true); 00179 } 00180 num += (1U << 16) | 1U; // increment request and response count each by 1 00181 break; 00182 } 00183 case ID_DAP_Vendor14: break; 00184 case ID_DAP_Vendor15: break; 00185 case ID_DAP_Vendor16: break; 00186 case ID_DAP_Vendor17: break; 00187 case ID_DAP_Vendor18: break; 00188 case ID_DAP_Vendor19: break; 00189 case ID_DAP_Vendor20: break; 00190 case ID_DAP_Vendor21: break; 00191 case ID_DAP_Vendor22: break; 00192 case ID_DAP_Vendor23: break; 00193 case ID_DAP_Vendor24: break; 00194 case ID_DAP_Vendor25: break; 00195 case ID_DAP_Vendor26: break; 00196 case ID_DAP_Vendor27: break; 00197 case ID_DAP_Vendor28: break; 00198 case ID_DAP_Vendor29: break; 00199 case ID_DAP_Vendor30: break; 00200 case ID_DAP_Vendor31: break; 00201 default: break; 00202 } 00203 00204 return (num); 00205 } 00206 00207 ///@}
Generated on Tue Jul 12 2022 15:37:15 by
1.7.2