Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.

Upstream: https://github.com/ARMmbed/DAPLink

Committer:
Pawel Zarembski
Date:
Tue Apr 07 12:55:42 2020 +0200
Revision:
0:01f31e923fe2
hani: DAPLink with reset workaround

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pawel Zarembski 0:01f31e923fe2 1 /*
Pawel Zarembski 0:01f31e923fe2 2 * Copyright (c) 2013-2016 ARM Limited. All rights reserved.
Pawel Zarembski 0:01f31e923fe2 3 * Copyright 2019, Cypress Semiconductor Corporation
Pawel Zarembski 0:01f31e923fe2 4 * or a subsidiary of Cypress Semiconductor Corporation.
Pawel Zarembski 0:01f31e923fe2 5 *
Pawel Zarembski 0:01f31e923fe2 6 * SPDX-License-Identifier: Apache-2.0
Pawel Zarembski 0:01f31e923fe2 7 *
Pawel Zarembski 0:01f31e923fe2 8 * Licensed under the Apache License, Version 2.0 (the License); you may
Pawel Zarembski 0:01f31e923fe2 9 * not use this file except in compliance with the License.
Pawel Zarembski 0:01f31e923fe2 10 * You may obtain a copy of the License at
Pawel Zarembski 0:01f31e923fe2 11 *
Pawel Zarembski 0:01f31e923fe2 12 * www.apache.org/licenses/LICENSE-2.0
Pawel Zarembski 0:01f31e923fe2 13 *
Pawel Zarembski 0:01f31e923fe2 14 * Unless required by applicable law or agreed to in writing, software
Pawel Zarembski 0:01f31e923fe2 15 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
Pawel Zarembski 0:01f31e923fe2 16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Pawel Zarembski 0:01f31e923fe2 17 * See the License for the specific language governing permissions and
Pawel Zarembski 0:01f31e923fe2 18 * limitations under the License.
Pawel Zarembski 0:01f31e923fe2 19 *
Pawel Zarembski 0:01f31e923fe2 20 * ----------------------------------------------------------------------
Pawel Zarembski 0:01f31e923fe2 21 *
Pawel Zarembski 0:01f31e923fe2 22 * $Date: 20. May 2015
Pawel Zarembski 0:01f31e923fe2 23 * $Revision: V1.10
Pawel Zarembski 0:01f31e923fe2 24 *
Pawel Zarembski 0:01f31e923fe2 25 * Project: CMSIS-DAP Source
Pawel Zarembski 0:01f31e923fe2 26 * Title: DAP_vendor.c CMSIS-DAP Vendor Commands
Pawel Zarembski 0:01f31e923fe2 27 *
Pawel Zarembski 0:01f31e923fe2 28 *---------------------------------------------------------------------------*/
Pawel Zarembski 0:01f31e923fe2 29
Pawel Zarembski 0:01f31e923fe2 30 #include "rl_usb.h"
Pawel Zarembski 0:01f31e923fe2 31 #include "DAP_config.h"
Pawel Zarembski 0:01f31e923fe2 32 #include "DAP.h"
Pawel Zarembski 0:01f31e923fe2 33 #include "info.h"
Pawel Zarembski 0:01f31e923fe2 34 #include "main.h"
Pawel Zarembski 0:01f31e923fe2 35 #include "uart.h"
Pawel Zarembski 0:01f31e923fe2 36 #include "settings.h"
Pawel Zarembski 0:01f31e923fe2 37 #include "target_family.h"
Pawel Zarembski 0:01f31e923fe2 38 #include "flash_manager.h"
Pawel Zarembski 0:01f31e923fe2 39 #include <string.h>
Pawel Zarembski 0:01f31e923fe2 40
Pawel Zarembski 0:01f31e923fe2 41
Pawel Zarembski 0:01f31e923fe2 42 #ifdef DRAG_N_DROP_SUPPORT
Pawel Zarembski 0:01f31e923fe2 43 #include "file_stream.h"
Pawel Zarembski 0:01f31e923fe2 44 #endif
Pawel Zarembski 0:01f31e923fe2 45
Pawel Zarembski 0:01f31e923fe2 46 //**************************************************************************************************
Pawel Zarembski 0:01f31e923fe2 47 /**
Pawel Zarembski 0:01f31e923fe2 48 \defgroup DAP_Vendor_Adapt_gr Adapt Vendor Commands
Pawel Zarembski 0:01f31e923fe2 49 \ingroup DAP_Vendor_gr
Pawel Zarembski 0:01f31e923fe2 50 @{
Pawel Zarembski 0:01f31e923fe2 51
Pawel Zarembski 0:01f31e923fe2 52 The file DAP_vendor.c provides template source code for extension of a Debug Unit with
Pawel Zarembski 0:01f31e923fe2 53 Vendor Commands. Copy this file to the project folder of the Debug Unit and add the
Pawel Zarembski 0:01f31e923fe2 54 file to the MDK-ARM project under the file group Configuration.
Pawel Zarembski 0:01f31e923fe2 55 */
Pawel Zarembski 0:01f31e923fe2 56
Pawel Zarembski 0:01f31e923fe2 57 /** Process DAP Vendor Command and prepare Response Data
Pawel Zarembski 0:01f31e923fe2 58 \param request pointer to request data
Pawel Zarembski 0:01f31e923fe2 59 \param response pointer to response data
Pawel Zarembski 0:01f31e923fe2 60 \return number of bytes in response (lower 16 bits)
Pawel Zarembski 0:01f31e923fe2 61 number of bytes in request (upper 16 bits)
Pawel Zarembski 0:01f31e923fe2 62 */
Pawel Zarembski 0:01f31e923fe2 63 uint32_t DAP_ProcessVendorCommand(const uint8_t *request, uint8_t *response) {
Pawel Zarembski 0:01f31e923fe2 64 uint32_t num = (1U << 16) | 1U;
Pawel Zarembski 0:01f31e923fe2 65
Pawel Zarembski 0:01f31e923fe2 66 *response++ = *request; // copy Command ID
Pawel Zarembski 0:01f31e923fe2 67
Pawel Zarembski 0:01f31e923fe2 68 switch (*request++) { // first byte in request is Command ID
Pawel Zarembski 0:01f31e923fe2 69 case ID_DAP_Vendor0: {
Pawel Zarembski 0:01f31e923fe2 70 const char *id_str = info_get_unique_id();
Pawel Zarembski 0:01f31e923fe2 71 uint8_t len = strlen(id_str);
Pawel Zarembski 0:01f31e923fe2 72 *response++ = len;
Pawel Zarembski 0:01f31e923fe2 73 memcpy(response, id_str, len);
Pawel Zarembski 0:01f31e923fe2 74 num += (len + 1); // increment response count by ID length + length byte
Pawel Zarembski 0:01f31e923fe2 75 break;
Pawel Zarembski 0:01f31e923fe2 76 }
Pawel Zarembski 0:01f31e923fe2 77 case ID_DAP_Vendor1: {
Pawel Zarembski 0:01f31e923fe2 78 // get line coding
Pawel Zarembski 0:01f31e923fe2 79 int32_t read_len = sizeof(CDC_LINE_CODING);
Pawel Zarembski 0:01f31e923fe2 80 CDC_LINE_CODING cdc_line_coding;
Pawel Zarembski 0:01f31e923fe2 81 USBD_CDC_ACM_PortGetLineCoding(&cdc_line_coding);
Pawel Zarembski 0:01f31e923fe2 82 memcpy(response, &cdc_line_coding, read_len);
Pawel Zarembski 0:01f31e923fe2 83 num += (read_len + 1);
Pawel Zarembski 0:01f31e923fe2 84 break;
Pawel Zarembski 0:01f31e923fe2 85 }
Pawel Zarembski 0:01f31e923fe2 86 case ID_DAP_Vendor2: {
Pawel Zarembski 0:01f31e923fe2 87 // set uart configuration
Pawel Zarembski 0:01f31e923fe2 88 CDC_LINE_CODING cdc_line_coding;
Pawel Zarembski 0:01f31e923fe2 89 USBD_CDC_ACM_PortGetLineCoding(&cdc_line_coding);
Pawel Zarembski 0:01f31e923fe2 90 //set BaudRate
Pawel Zarembski 0:01f31e923fe2 91 uint32_t baud_rate = 0;
Pawel Zarembski 0:01f31e923fe2 92 memcpy(&baud_rate, request, sizeof(uint32_t));
Pawel Zarembski 0:01f31e923fe2 93 cdc_line_coding.dwDTERate = baud_rate;
Pawel Zarembski 0:01f31e923fe2 94 USBD_CDC_ACM_PortSetLineCoding(&cdc_line_coding);
Pawel Zarembski 0:01f31e923fe2 95 USBD_CDC_ACM_SendBreak(0);
Pawel Zarembski 0:01f31e923fe2 96 *response = 1;
Pawel Zarembski 0:01f31e923fe2 97 num += (sizeof(uint32_t) << 16) | 1;
Pawel Zarembski 0:01f31e923fe2 98 break;
Pawel Zarembski 0:01f31e923fe2 99 }
Pawel Zarembski 0:01f31e923fe2 100 case ID_DAP_Vendor3: {
Pawel Zarembski 0:01f31e923fe2 101 // uart read
Pawel Zarembski 0:01f31e923fe2 102 int32_t read_len = 62;
Pawel Zarembski 0:01f31e923fe2 103 read_len = uart_read_data(response + 1, read_len);
Pawel Zarembski 0:01f31e923fe2 104 response[0] = read_len;
Pawel Zarembski 0:01f31e923fe2 105 // increment request and response count
Pawel Zarembski 0:01f31e923fe2 106 num += (read_len + 1);
Pawel Zarembski 0:01f31e923fe2 107 break;
Pawel Zarembski 0:01f31e923fe2 108 }
Pawel Zarembski 0:01f31e923fe2 109 case ID_DAP_Vendor4: {
Pawel Zarembski 0:01f31e923fe2 110 // uart write
Pawel Zarembski 0:01f31e923fe2 111 int32_t write_len = *request;
Pawel Zarembski 0:01f31e923fe2 112 request++;
Pawel Zarembski 0:01f31e923fe2 113 uart_write_data((uint8_t *)request, write_len);
Pawel Zarembski 0:01f31e923fe2 114 *response = 1;
Pawel Zarembski 0:01f31e923fe2 115 num += ((write_len + 1) << 16) | 1;
Pawel Zarembski 0:01f31e923fe2 116 break;
Pawel Zarembski 0:01f31e923fe2 117 }
Pawel Zarembski 0:01f31e923fe2 118 case ID_DAP_Vendor5: break;
Pawel Zarembski 0:01f31e923fe2 119 case ID_DAP_Vendor6: break;
Pawel Zarembski 0:01f31e923fe2 120 case ID_DAP_Vendor7: break;
Pawel Zarembski 0:01f31e923fe2 121 case ID_DAP_Vendor8: {
Pawel Zarembski 0:01f31e923fe2 122 *response = 1;
Pawel Zarembski 0:01f31e923fe2 123 if (0 == *request) {
Pawel Zarembski 0:01f31e923fe2 124 main_usb_set_test_mode(false);
Pawel Zarembski 0:01f31e923fe2 125 } else if (1 == *request) {
Pawel Zarembski 0:01f31e923fe2 126 main_usb_set_test_mode(true);
Pawel Zarembski 0:01f31e923fe2 127 } else {
Pawel Zarembski 0:01f31e923fe2 128 *response = 0;
Pawel Zarembski 0:01f31e923fe2 129 }
Pawel Zarembski 0:01f31e923fe2 130 num += (1U << 16) | 1U; // increment request and response count each by 1
Pawel Zarembski 0:01f31e923fe2 131 break;
Pawel Zarembski 0:01f31e923fe2 132 }
Pawel Zarembski 0:01f31e923fe2 133 case ID_DAP_Vendor9: {
Pawel Zarembski 0:01f31e923fe2 134 // reset target
Pawel Zarembski 0:01f31e923fe2 135 *response = 1;
Pawel Zarembski 0:01f31e923fe2 136 if (!config_get_auto_rst()) {
Pawel Zarembski 0:01f31e923fe2 137 target_set_state(RESET_RUN);
Pawel Zarembski 0:01f31e923fe2 138 }
Pawel Zarembski 0:01f31e923fe2 139 num += 1;
Pawel Zarembski 0:01f31e923fe2 140 break;
Pawel Zarembski 0:01f31e923fe2 141 }
Pawel Zarembski 0:01f31e923fe2 142 #ifdef DRAG_N_DROP_SUPPORT
Pawel Zarembski 0:01f31e923fe2 143 case ID_DAP_Vendor10: {
Pawel Zarembski 0:01f31e923fe2 144 // open mass storage device stream
Pawel Zarembski 0:01f31e923fe2 145 *response = stream_open((stream_type_t)(*request));
Pawel Zarembski 0:01f31e923fe2 146 num += (1 << 16) | 1;
Pawel Zarembski 0:01f31e923fe2 147 break;
Pawel Zarembski 0:01f31e923fe2 148 }
Pawel Zarembski 0:01f31e923fe2 149 case ID_DAP_Vendor11: {
Pawel Zarembski 0:01f31e923fe2 150 // close mass storage device stream
Pawel Zarembski 0:01f31e923fe2 151 *response = stream_close();
Pawel Zarembski 0:01f31e923fe2 152 num += 1;
Pawel Zarembski 0:01f31e923fe2 153 break;
Pawel Zarembski 0:01f31e923fe2 154 }
Pawel Zarembski 0:01f31e923fe2 155 case ID_DAP_Vendor12: {
Pawel Zarembski 0:01f31e923fe2 156 // write to mass storage device
Pawel Zarembski 0:01f31e923fe2 157 uint32_t write_len = *request;
Pawel Zarembski 0:01f31e923fe2 158 request++;
Pawel Zarembski 0:01f31e923fe2 159 *response = stream_write((uint8_t *)request, write_len);
Pawel Zarembski 0:01f31e923fe2 160 num += ((write_len + 1) << 16) | 1;
Pawel Zarembski 0:01f31e923fe2 161 break;
Pawel Zarembski 0:01f31e923fe2 162 }
Pawel Zarembski 0:01f31e923fe2 163 #endif
Pawel Zarembski 0:01f31e923fe2 164 case ID_DAP_Vendor13: {
Pawel Zarembski 0:01f31e923fe2 165 // switching between chip erase and page erase
Pawel Zarembski 0:01f31e923fe2 166 // COMMAND(OUT Packet)
Pawel Zarembski 0:01f31e923fe2 167 // BYTE 0 1000 1110 0x8D
Pawel Zarembski 0:01f31e923fe2 168 // BYTE 1 Desired Mode:
Pawel Zarembski 0:01f31e923fe2 169 // 0x00 - Chip Erase
Pawel Zarembski 0:01f31e923fe2 170 // nonzero - Page Erase
Pawel Zarembski 0:01f31e923fe2 171 // RESPONSE(IN Packet)
Pawel Zarembski 0:01f31e923fe2 172 // BYTE 0
Pawel Zarembski 0:01f31e923fe2 173 // 0x00 - OK
Pawel Zarembski 0:01f31e923fe2 174 *response = DAP_OK;
Pawel Zarembski 0:01f31e923fe2 175 if (0x00U == *request) {
Pawel Zarembski 0:01f31e923fe2 176 flash_manager_set_page_erase(false);
Pawel Zarembski 0:01f31e923fe2 177 } else {
Pawel Zarembski 0:01f31e923fe2 178 flash_manager_set_page_erase(true);
Pawel Zarembski 0:01f31e923fe2 179 }
Pawel Zarembski 0:01f31e923fe2 180 num += (1U << 16) | 1U; // increment request and response count each by 1
Pawel Zarembski 0:01f31e923fe2 181 break;
Pawel Zarembski 0:01f31e923fe2 182 }
Pawel Zarembski 0:01f31e923fe2 183 case ID_DAP_Vendor14: break;
Pawel Zarembski 0:01f31e923fe2 184 case ID_DAP_Vendor15: break;
Pawel Zarembski 0:01f31e923fe2 185 case ID_DAP_Vendor16: break;
Pawel Zarembski 0:01f31e923fe2 186 case ID_DAP_Vendor17: break;
Pawel Zarembski 0:01f31e923fe2 187 case ID_DAP_Vendor18: break;
Pawel Zarembski 0:01f31e923fe2 188 case ID_DAP_Vendor19: break;
Pawel Zarembski 0:01f31e923fe2 189 case ID_DAP_Vendor20: break;
Pawel Zarembski 0:01f31e923fe2 190 case ID_DAP_Vendor21: break;
Pawel Zarembski 0:01f31e923fe2 191 case ID_DAP_Vendor22: break;
Pawel Zarembski 0:01f31e923fe2 192 case ID_DAP_Vendor23: break;
Pawel Zarembski 0:01f31e923fe2 193 case ID_DAP_Vendor24: break;
Pawel Zarembski 0:01f31e923fe2 194 case ID_DAP_Vendor25: break;
Pawel Zarembski 0:01f31e923fe2 195 case ID_DAP_Vendor26: break;
Pawel Zarembski 0:01f31e923fe2 196 case ID_DAP_Vendor27: break;
Pawel Zarembski 0:01f31e923fe2 197 case ID_DAP_Vendor28: break;
Pawel Zarembski 0:01f31e923fe2 198 case ID_DAP_Vendor29: break;
Pawel Zarembski 0:01f31e923fe2 199 case ID_DAP_Vendor30: break;
Pawel Zarembski 0:01f31e923fe2 200 case ID_DAP_Vendor31: break;
Pawel Zarembski 0:01f31e923fe2 201 default: break;
Pawel Zarembski 0:01f31e923fe2 202 }
Pawel Zarembski 0:01f31e923fe2 203
Pawel Zarembski 0:01f31e923fe2 204 return (num);
Pawel Zarembski 0:01f31e923fe2 205 }
Pawel Zarembski 0:01f31e923fe2 206
Pawel Zarembski 0:01f31e923fe2 207 ///@}