diff --git a/common/rddi_dap_cmsis.h b/common/rddi_dap_cmsis.h index a5718f7..aae84ba 100644 --- a/common/rddi_dap_cmsis.h +++ b/common/rddi_dap_cmsis.h @@ -161,4 +161,8 @@ RDDI_FUNC int CMSIS_DAP_GetGUID(const RDDIHandle handle, int ifNo, char *str, co */ RDDI_FUNC int CMSIS_DAP_Capabilities(const RDDIHandle handle, int ifNo, int *cap_info); +RDDI_FUNC int CMSIS_DAP_SWJ_Sequence(const RDDIHandle handle, int num, unsigned char *request); + +RDDI_FUNC int CMSIS_DAP_SWJ_Pins(const RDDIHandle handle, unsigned char pinselect, unsigned char pinout, int *res, int wait); + #endif diff --git a/elaphureLinkAGDI/DbgCM/AGDI.CPP b/elaphureLinkAGDI/DbgCM/AGDI.CPP index 025c65e..a04d8a4 100644 --- a/elaphureLinkAGDI/DbgCM/AGDI.CPP +++ b/elaphureLinkAGDI/DbgCM/AGDI.CPP @@ -17565,6 +17565,7 @@ static U32 DapAcc_Pins(ACCDAP *pIn) int status = 0; U32 nE = ACCDAP_DONE; bool bForce = false; + int res; if (pIn == NULL) { return (ACCDAP_BADPARM); @@ -17593,7 +17594,6 @@ static U32 DapAcc_Pins(ACCDAP *pIn) } //---TODO: Write data to JTAG/SWD pins and wait for pins to stabilize - DEVELOP_MSG("Todo: \nWrite data to JTAG/SWD pins and wait for pins to stabilize"); // Members of pIn to use: // - pIn->pOut8 : Value to Write // - pIn->nMask : Pin mask to select pins for value change @@ -17607,6 +17607,9 @@ static U32 DapAcc_Pins(ACCDAP *pIn) // - Bit 4: nTRST (ACCDAP_PIN_nTRST) // - Bit 5: nRESET (ACCDAP_PIN_nRESET) + status = rddi::CMSIS_DAP_SWJ_Pins(rddi::k_rddi_handle, pIn->nMask, *pIn->pOut8, &res, pIn->nDelay); + *pIn->pIn8 = static_cast(res); + end: if (status != 0 && nE == ACCDAP_DONE) { diff --git a/elaphureLinkAGDI/DbgCM/COLLECT.H b/elaphureLinkAGDI/DbgCM/COLLECT.H index bb7a199..03af166 100644 --- a/elaphureLinkAGDI/DbgCM/COLLECT.H +++ b/elaphureLinkAGDI/DbgCM/COLLECT.H @@ -34,7 +34,7 @@ // Choose between this three #defines when developing the driver #define DEVELOP_MSG(str) \ - AfxMessageBox("elaphureLink does not implement this feature yet. If you see this message, please open an issue at https://github.com/windowsair/elaphureLink/issues" #str) + AfxMessageBox("elaphureLink does not implement this feature yet. If you see this message, please open an issue at https://github.com/windowsair/elaphureLink/issues\n" ##str) //#define DEVELOP_MSG OutputDebugString //#define DEVELOP_MSG txtout diff --git a/elaphureLinkAGDI/DbgCM/DbgCM.cpp b/elaphureLinkAGDI/DbgCM/DbgCM.cpp index 9079f60..9cc186d 100644 --- a/elaphureLinkAGDI/DbgCM/DbgCM.cpp +++ b/elaphureLinkAGDI/DbgCM/DbgCM.cpp @@ -151,6 +151,8 @@ inline BOOL LoadRddiDllFunction() RDDILL_GetProcAddress(CMSIS_DAP_DetectNumberOfDAPs); RDDILL_GetProcAddress(CMSIS_DAP_DetectDAPIDList); RDDILL_GetProcAddress(CMSIS_DAP_Commands); + RDDILL_GetProcAddress(CMSIS_DAP_SWJ_Sequence); + RDDILL_GetProcAddress(CMSIS_DAP_SWJ_Pins); return TRUE; } diff --git a/elaphureLinkAGDI/DbgCM/SWD.cpp b/elaphureLinkAGDI/DbgCM/SWD.cpp index d801942..230dd0d 100644 --- a/elaphureLinkAGDI/DbgCM/SWD.cpp +++ b/elaphureLinkAGDI/DbgCM/SWD.cpp @@ -1,4 +1,4 @@ -/**************************************************************************/ /** +/**************************************************************************/ /** * Cortex-M Middle/Upper layer Debug driver Template for µVision * * @version V1.1.13 @@ -3296,8 +3296,13 @@ int SWD_SwitchDP(DWORD id, bool force) // - DBGCM_RECOVERY Feature int SWD_SWJ_Sequence(int cnt, U64 val) { - //... - DEVELOP_MSG("Todo: \nImplement Function: int SWD_SWJ_Sequence (int cnt, U64 val), required for\n - DBGCM_DBG_DESCRIPTION Feature\n - DBGCM_RECOVERY Feature"); + unsigned char *p = reinterpret_cast(&val); + int ret; + + ret = rddi::CMSIS_DAP_SWJ_Sequence(rddi::k_rddi_handle, cnt, p); + if (ret) + return EU08; + return (0); } diff --git a/elaphureLinkAGDI/DbgCM/rddi_dll.cpp b/elaphureLinkAGDI/DbgCM/rddi_dll.cpp index 1ceba80..6b8a3d4 100644 --- a/elaphureLinkAGDI/DbgCM/rddi_dll.cpp +++ b/elaphureLinkAGDI/DbgCM/rddi_dll.cpp @@ -40,6 +40,8 @@ decltype(::CMSIS_DAP_Commands) *CMSIS_DAP_Commands = nullptr decltype(::CMSIS_DAP_ConfigureDAP) *CMSIS_DAP_ConfigureDAP = nullptr; //decltype(::CMSIS_DAP_GetGUID) *CMSIS_DAP_GetGUID = nullptr; decltype(::CMSIS_DAP_Capabilities) *CMSIS_DAP_Capabilities = nullptr; +decltype(::CMSIS_DAP_SWJ_Sequence) *CMSIS_DAP_SWJ_Sequence = nullptr; +decltype(::CMSIS_DAP_SWJ_Pins) *CMSIS_DAP_SWJ_Pins = nullptr; RDDIHandle k_rddi_handle; diff --git a/elaphureLinkAGDI/DbgCM/rddi_dll.hpp b/elaphureLinkAGDI/DbgCM/rddi_dll.hpp index 2ca652f..2f5bbb5 100644 --- a/elaphureLinkAGDI/DbgCM/rddi_dll.hpp +++ b/elaphureLinkAGDI/DbgCM/rddi_dll.hpp @@ -43,6 +43,8 @@ extern decltype(::CMSIS_DAP_Commands) *CMSIS_DAP_Commands; extern decltype(::CMSIS_DAP_ConfigureDAP) *CMSIS_DAP_ConfigureDAP; extern decltype(::CMSIS_DAP_GetGUID) *CMSIS_DAP_GetGUID; extern decltype(::CMSIS_DAP_Capabilities) *CMSIS_DAP_Capabilities; +extern decltype(::CMSIS_DAP_SWJ_Sequence) *CMSIS_DAP_SWJ_Sequence; +extern decltype(::CMSIS_DAP_SWJ_Pins) *CMSIS_DAP_SWJ_Pins; enum { RDDI_DAP_ERROR = 0x2000, // RDDI-DAP Error diff --git a/elaphureLinkProxy/protocol.cpp b/elaphureLinkProxy/protocol.cpp index da4cd26..feaf6c7 100644 --- a/elaphureLinkProxy/protocol.cpp +++ b/elaphureLinkProxy/protocol.cpp @@ -272,7 +272,13 @@ void SocketClient::do_data_process() p += 3; break; } - + case ID_DAP_SWJ_Pins: { + k_shared_memory_ptr->consumer_page.data_len = 1; + k_shared_memory_ptr->consumer_page.data[0] = *(p + 1); + set_consumer_status(DAP_RES_OK); + p += 2; + break; + } case ID_DAP_JTAG_Sequence: { if (*(p + 1) != 0) { // status code set_consumer_status(DAP_RES_FAULT); @@ -308,7 +314,10 @@ void SocketClient::do_data_process() break; } case ID_DAP_SWJ_Sequence: { + int status = *(p + 1); p += 2; + + set_consumer_status(status == 0 ? DAP_RES_OK : DAP_RES_ERROR); break; } case ID_DAP_SWD_Configure: { diff --git a/elaphureLinkRDDI/rddi_dap.cpp b/elaphureLinkRDDI/rddi_dap.cpp index 256771b..0ccbfe8 100644 --- a/elaphureLinkRDDI/rddi_dap.cpp +++ b/elaphureLinkRDDI/rddi_dap.cpp @@ -19,19 +19,19 @@ #define EL_FORCE_DEBUGBREAK 0 - #if (EL_FORCE_DEBUGBREAK == 1) #define EL_DEBUG_BREAK() __debugbreak() #else #define EL_DEBUG_BREAK() #endif +#define DIV_ROUND_UP(n, d) (((n) + (d)-1) / (d)) + inline const uint8_t k_dap_reg_offset_map[] = { 0x00, 0x04, 0x08, 0x0C, // for DP_0x0, DP_0x4, DP_0x8, DP_0xC 0x01, 0x05, 0x09, 0x0D, // for AP_0x0, AP_0x4, AP_0x8, AP_0xC ---> this field set APnDP }; - RDDI_FUNC int RDDI_Open(RDDIHandle *pHandle, const void *pDetails) { EL_DEBUG_BREAK(); @@ -90,7 +90,6 @@ RDDI_FUNC int RDDI_GetLastError(int *pError, char *pDetails, size_t detailsLen) return 8204; } - RDDI_FUNC void RDDI_SetLogCallback(RDDIHandle handle, RDDILogCallback pfn, void *context, int maxLogLevel) { //EL_TODO_IMPORTANT @@ -131,7 +130,6 @@ RDDI_FUNC int DAP_Disconnect(const RDDIHandle handle) return RDDI_SUCCESS; } - RDDI_FUNC int DAP_GetSupportedOptimisationLevel(const RDDIHandle handle, int *level) { //EL_TODO_IMPORTANT @@ -139,7 +137,6 @@ RDDI_FUNC int DAP_GetSupportedOptimisationLevel(const RDDIHandle handle, int *le return 8204; } - RDDI_FUNC int DAP_GetNumberOfDAPs(const RDDIHandle handle, int *noOfDAPs) { //EL_TODO_IMPORTANT @@ -147,7 +144,6 @@ RDDI_FUNC int DAP_GetNumberOfDAPs(const RDDIHandle handle, int *noOfDAPs) return 8204; } - RDDI_FUNC int DAP_GetDAPIDList(const RDDIHandle handle, int *DAP_ID_Array, size_t sizeOfArray) { //EL_TODO_IMPORTANT @@ -155,7 +151,6 @@ RDDI_FUNC int DAP_GetDAPIDList(const RDDIHandle handle, int *DAP_ID_Array, size_ return 8204; } - RDDI_FUNC int DAP_ReadReg(const RDDIHandle handle, const int DAP_ID, const int regID, int *value) { EL_DEBUG_BREAK(); @@ -200,7 +195,6 @@ RDDI_FUNC int DAP_ReadReg(const RDDIHandle handle, const int DAP_ID, const int r return RDDI_SUCCESS; } - RDDI_FUNC int DAP_WriteReg(const RDDIHandle handle, const int DAP_ID, const int regID, const int value) { EL_DEBUG_BREAK(); @@ -263,7 +257,6 @@ RDDI_FUNC int DAP_WriteReg(const RDDIHandle handle, const int DAP_ID, const int return RDDI_SUCCESS; } - RDDI_FUNC int DAP_RegAccessBlock(const RDDIHandle handle, const int DAP_ID, const int numRegs, const int *regIDArray, int *dataArray) { @@ -494,7 +487,6 @@ RDDI_FUNC int DAP_RegAccessBlock(const RDDIHandle handle, const int DAP_ID, cons return RDDI_SUCCESS; } - RDDI_FUNC int DAP_RegWriteBlock(const RDDIHandle handle, const int DAP_ID, const int numRegs, const int *regIDArray, const int *dataArray) { @@ -568,7 +560,6 @@ RDDI_FUNC int DAP_RegWriteRepeat(const RDDIHandle handle, const int DAP_ID, cons return RDDI_SUCCESS; } - RDDI_FUNC int DAP_RegReadRepeat(const RDDIHandle handle, const int DAP_ID, const int numRepeats, const int regID, int *dataArray) { @@ -619,7 +610,6 @@ RDDI_FUNC int DAP_RegReadRepeat(const RDDIHandle handle, const int DAP_ID, const return RDDI_SUCCESS; } - RDDI_FUNC int DAP_RegReadWaitForValue(const RDDIHandle handle, const int DAP_ID, const int numRepeats, const int regID, const int *mask, const int *requiredValue) { @@ -644,7 +634,6 @@ RDDI_FUNC int DAP_DefineSequence(const RDDIHandle handle, const int seqID, void return 8204; } - RDDI_FUNC int DAP_RunSequence(const RDDIHandle handle, const int seqID, void *seqInData, void *seqOutData) { //EL_TODO_IMPORTANT @@ -652,7 +641,6 @@ RDDI_FUNC int DAP_RunSequence(const RDDIHandle handle, const int seqID, void *se return 8204; } - // This function will check the num of hardware debugger that connected to the PC. RDDI_FUNC int CMSIS_DAP_Detect(const RDDIHandle handle, int *noOfIFs) { @@ -707,7 +695,6 @@ RDDI_FUNC int CMSIS_DAP_Identify(const RDDIHandle handle, int ifNo, int idNo, ch return RDDI_SUCCESS; } - RDDI_FUNC int CMSIS_DAP_ConfigureInterface(const RDDIHandle handle, int ifNo, char *str) { // parse configure string like: @@ -763,7 +750,6 @@ RDDI_FUNC int CMSIS_DAP_ConfigureInterface(const RDDIHandle handle, int ifNo, ch return RDDI_SUCCESS; } - RDDI_FUNC int CMSIS_DAP_ConfigureDAP(const RDDIHandle handle, const char *str) { EL_DEBUG_BREAK(); @@ -841,7 +827,6 @@ RDDI_FUNC int CMSIS_DAP_Capabilities(const RDDIHandle handle, int ifNo, int *cap return RDDI_SUCCESS; } - RDDI_FUNC int CMSIS_DAP_DetectNumberOfDAPs(const RDDIHandle handle, int *noOfDAPs) { //EL_TODO_IMPORTANT @@ -968,7 +953,6 @@ RDDI_FUNC int CMSIS_DAP_DetectDAPIDList(const RDDIHandle handle, int *DAP_ID_Arr return RDDI_SUCCESS; } - RDDI_FUNC int CMSIS_DAP_Commands(const RDDIHandle handle, int num, unsigned char **request, int *req_len, unsigned char **response, int *resp_len) { @@ -1002,57 +986,6 @@ RDDI_FUNC int CMSIS_DAP_Commands(const RDDIHandle handle, int num, unsigned char return RDDI_SUCCESS; } - - -////////////// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -#if 0 -RDDI_FUNC int CMSIS_DAP_GetNumberOfDevices() -{ - __debugbreak(); - return 8204; -} -#endif - -#if 0 -RDDI_FUNC int CMSIS_DAP_Connect() -{ - __debugbreak(); - return 8204; -} -#endif -#if 0 -RDDI_FUNC int CMSIS_DAP_GetDeviceIDList() -{ - __debugbreak(); - return 8204; -} -#endif - -#if 0 -RDDI_FUNC int CMSIS_DAP_DetectNumberOfDevices() -{ - __debugbreak(); - return 8204; -} -#endif - -/// -/// -/// -/// -/// -/// RDDI_FUNC int CMSIS_DAP_Disconnect() { //EL_TODO @@ -1065,37 +998,57 @@ RDDI_FUNC int DAP_SetCommTimeout() __debugbreak(); return 8204; } + RDDI_FUNC int CMSIS_DAP_GetInterfaceVersion() { __debugbreak(); return 8204; } - - RDDI_FUNC int CMSIS_DAP_ResetDAP() { __debugbreak(); return 8204; } - -RDDI_FUNC int CMSIS_DAP_SWJ_Sequence() +RDDI_FUNC int CMSIS_DAP_SWJ_Sequence(const RDDIHandle handle, int num, unsigned char *request) { - __debugbreak(); - return 8204; + EL_DEBUG_BREAK(); + + if (handle != kContext.get_rddi_handle()) { + return RDDI_INVHANDLE; + } + + int nbytes = DIV_ROUND_UP(num, 8); + + // copy to buffer + k_shared_memory_ptr->producer_page.data[0] = 0x12; // DAP_SWJ_Sequence + k_shared_memory_ptr->producer_page.data[1] = num; + memcpy(&(k_shared_memory_ptr->producer_page.data[2]), request, nbytes); + + produce_and_wait_consumer_response(1, 2 + nbytes); + + // read response + if (k_shared_memory_ptr->consumer_page.command_response != DAP_RES_OK) { + return RDDI_INTERNAL_ERROR; + } + + return RDDI_SUCCESS; } + RDDI_FUNC int CMSIS_DAP_JTAG_Sequence() { __debugbreak(); return 8204; } + RDDI_FUNC int CMSIS_DAP_Atomic_Result() { //EL_TODO //__debugbreak(); return 8204; } + RDDI_FUNC int CMSIS_DAP_Atomic_Control() { //EL_TODO @@ -1108,17 +1061,18 @@ RDDI_FUNC int CMSIS_DAP_WriteABORT() return 8204; } - RDDI_FUNC int CMSIS_DAP_JTAG_GetIDCODEs() { __debugbreak(); return 8204; } + RDDI_FUNC int CMSIS_DAP_JTAG_GetIRLengths() { __debugbreak(); return 8204; } + RDDI_FUNC int CMSIS_DAP_Delay() { //EL_TODO @@ -1126,19 +1080,43 @@ RDDI_FUNC int CMSIS_DAP_Delay() return 8204; } -RDDI_FUNC int CMSIS_DAP_SWJ_Pins() +RDDI_FUNC int CMSIS_DAP_SWJ_Pins(const RDDIHandle handle, unsigned char pinselect, unsigned char pinout, int *res, int wait) { - __debugbreak(); - return 8204; + EL_DEBUG_BREAK(); + + if (handle != kContext.get_rddi_handle()) { + return RDDI_INVHANDLE; + } + + constexpr int len = 3 + sizeof(int); + std::array req = { + ID_DAP_SWJ_Pins, pinout, pinselect + }; + + memcpy(req.data() + 3, &wait, sizeof(int)); + memcpy(k_shared_memory_ptr->producer_page.data, req.data(), len); + + produce_and_wait_consumer_response(1, len); + + if (k_shared_memory_ptr->consumer_page.command_response != DAP_RES_OK) { + return RDDI_INTERNAL_ERROR; + } + + // If not support read pinout, then set res as 0xFFFFFFFF + *res = k_shared_memory_ptr->consumer_page.data[0]; + + return RDDI_SUCCESS; } + RDDI_FUNC int CMSIS_DAP_SWJ_Clock() { __debugbreak(); return 8204; } + RDDI_FUNC int CMSIS_DAP_ConfigureDebugger() { //EL_TODO //__debugbreak(); return 8204; -} \ No newline at end of file +}