├── .gitattributes ├── .gitignore ├── CMakeLists.txt ├── Doxyfile ├── Doxyfile.in ├── JLink ├── General │ ├── JLink_Basic.c │ ├── JLink_Basic.h │ ├── JLink_Configuration.c │ ├── JLink_Configuration.h │ ├── JLink_Debugging.c │ ├── JLink_Debugging.h │ ├── JLink_DeviceSpecific.c │ ├── JLink_DeviceSpecific.h │ ├── JLink_FileIO.c │ ├── JLink_FileIO.h │ ├── JLink_General.c │ ├── JLink_Memory.c │ ├── JLink_Memory.h │ ├── JLink_Reset.c │ ├── JLink_Reset.h │ ├── JLink_SystemControl.c │ └── JLink_SystemControl.h ├── HSS │ ├── JLink_HSS.c │ └── JLink_HSS.h ├── JLink.h ├── JLink_Define.h ├── JLink_Init.c ├── JLink_Init.h ├── JTAG │ ├── JLink_JTAG.c │ └── JLink_JTAG.h ├── POWER │ ├── JLink_Power.c │ └── JLink_Power.h ├── RTT │ ├── JLink_RTT.c │ └── JLink_RTT.h ├── SPI │ ├── JLink_SPI.c │ └── JLink_SPI.h ├── STRACE │ ├── JLink_STRACE.c │ └── JLink_STRACE.h ├── SWD │ ├── JLink_SWD.c │ └── JLink_SWD.h └── SWO │ ├── JLink_SWO.c │ └── JLink_SWO.h ├── JLinkARM.dll ├── JLink_x64.dll ├── LICENSE ├── README.md └── version.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | *.dll filter=lfs diff=lfs merge=lfs -text 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Project exclude paths 2 | /cmake-build-debug/ 3 | /cmake-build-release/ 4 | /Document/ 5 | .idea 6 | DLL_Exports.txt 7 | *.dll.* 8 | /build -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.6) 2 | 3 | if (NOT CMAKE_BUILD_TYPE) 4 | set(CMAKE_BUILD_TYPE "Release" CACHE STRING 5 | "Choose the type of build, options are: Debug Releas." FORCE) 6 | endif () 7 | 8 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Release Debug) 9 | 10 | project(JLinkDLL) 11 | 12 | set(CMAKE_CXX_STANDARD 14) 13 | set(CMAKE_INCLUDE_CURRENT_DIR YES) 14 | 15 | if (WIN32) 16 | set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS YES) 17 | if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") 18 | add_compile_options("/utf-8") 19 | else () 20 | message(FATAL_ERROR "Unsupported Compiler ${CMAKE_CXX_COMPILER_ID}") 21 | endif () 22 | else () 23 | message(FATAL_ERROR "Linux currently not supported") 24 | endif () 25 | 26 | 27 | file(GLOB_RECURSE SRC JLink/*.c) 28 | add_library(${PROJECT_NAME} SHARED ${SRC}) 29 | set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C) 30 | set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME_DEBUG "${PROJECT_NAME}_d") 31 | 32 | set(DEFAULT_JLINK_DLL "" CACHE PATH "Use custom DLL paths") 33 | 34 | if (DEFAULT_JLINK_DLL) 35 | message(STATUS "Use User Define JLinkDLL ${DEFAULT_JLINK_DLL}") 36 | target_compile_definitions(${PROJECT_NAME} PRIVATE JLINK_LIB_PATH="${DEFAULT_JLINK_DLL}") 37 | endif () 38 | 39 | target_include_directories(${PROJECT_NAME} PUBLIC 40 | $ 41 | $) 42 | 43 | file(GLOB_RECURSE HEADER JLink/*.h) 44 | foreach (f ${HEADER}) 45 | file(RELATIVE_PATH HEADER_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${f}) 46 | get_filename_component(SECOND_FOLDER ${HEADER_PATH} DIRECTORY) 47 | install(FILES ${f} DESTINATION include/${SECOND_FOLDER}) 48 | endforeach () 49 | 50 | if (JLINK_DLL) 51 | install(FILES ${JLINK_DLL} DESTINATION bin) 52 | endif () 53 | 54 | add_executable(${PROJECT_NAME}_Version version.cpp) 55 | target_link_libraries(${PROJECT_NAME}_Version PUBLIC ${PROJECT_NAME}) 56 | set_target_properties(${PROJECT_NAME}_Version PROPERTIES OUTPUT_NAME_DEBUG "${PROJECT_NAME}_Version_d") 57 | 58 | find_package(Doxygen) 59 | if (DOXYGEN_FOUND) 60 | # set input and output files 61 | set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) 62 | set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_out) 63 | set(DOCUMENT_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/JLinkDLL_doc) 64 | 65 | if (NOT EXISTS ${DOCUMENT_OUTPUT_DIRECTORY}) 66 | file(MAKE_DIRECTORY ${DOCUMENT_OUTPUT_DIRECTORY}) 67 | endif () 68 | # request to configure the file 69 | configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) 70 | 71 | # note the option ALL which allows to build the docs together with the application 72 | add_custom_target(${PROJECT_NAME}_document ALL 73 | COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} 74 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 75 | COMMENT "Generating API documentation with Doxygen" 76 | VERBATIM) 77 | 78 | install(DIRECTORY ${DOCUMENT_OUTPUT_DIRECTORY} 79 | TYPE DOC) 80 | 81 | else (DOXYGEN_FOUND) 82 | message("Doxygen need to be installed to generate the doxygen documentation") 83 | endif (DOXYGEN_FOUND) 84 | 85 | install(TARGETS ${PROJECT_NAME} 86 | EXPORT ${PROJECT_NAME}-targets 87 | RUNTIME DESTINATION bin 88 | ARCHIVE DESTINATION lib 89 | PUBLIC_HEADER DESTINATION include) 90 | 91 | install(EXPORT ${PROJECT_NAME}-targets 92 | FILE ${PROJECT_NAME}Config.cmake 93 | DESTINATION lib/cmake) 94 | 95 | install(TARGETS ${PROJECT_NAME}_Version 96 | RUNTIME DESTINATION bin) 97 | -------------------------------------------------------------------------------- /JLink/General/JLink_Basic.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yaoji on 2022/3/18. 3 | // 4 | 5 | #include "JLink_Basic.h" 6 | #include "JLink/JLink_Init.h" 7 | 8 | static void (*P_JLINKARM_Close)(void); 9 | static int (*P_JLINKARM_Connect)(void); 10 | static void (*P_JLINKARM_Go)(void); 11 | static void (*P_JLINKARM_GoIntDis)(void); 12 | static char (*P_JLINKARM_Halt)(void); 13 | static void (*P_JLINKARM_GoEx)(uint32_t MaxEmulInsts, uint32_t Flags); 14 | static char (*P_JLINKARM_IsConnected)(void); 15 | static char (*P_JLINKARM_IsHalted)(void); 16 | static char (*P_JLINKARM_IsOpen)(void); 17 | static void (*P_JLINKARM_Lock)(void); 18 | static const char *(*P_JLINKARM_Open)(void); 19 | static const char *(*P_JLINKARM_OpenEx)(JLINKARM_LOG *pfLog, JLINKARM_LOG *pfErrorOut); 20 | static void (*P_JLINKARM_Unlock)(void); 21 | 22 | int JLINK_GERENAL_BASE_Init() { 23 | P_JLINKARM_Close = JLinkDLL_getSym("JLINKARM_Close"); 24 | if (P_JLINKARM_Close == NULL) return 0; 25 | P_JLINKARM_Connect = JLinkDLL_getSym("JLINKARM_Connect"); 26 | if (P_JLINKARM_Connect == NULL) return 0; 27 | P_JLINKARM_Go = JLinkDLL_getSym("JLINKARM_Go"); 28 | if (P_JLINKARM_Go == NULL) return 0; 29 | P_JLINKARM_GoIntDis = JLinkDLL_getSym("JLINKARM_GoIntDis"); 30 | if (P_JLINKARM_GoIntDis == NULL) return 0; 31 | P_JLINKARM_Halt = JLinkDLL_getSym("JLINKARM_Halt"); 32 | if (P_JLINKARM_Halt == NULL) return 0; 33 | P_JLINKARM_GoEx = JLinkDLL_getSym("JLINKARM_GoEx"); 34 | if (P_JLINKARM_GoEx == NULL) return 0; 35 | P_JLINKARM_IsConnected = JLinkDLL_getSym("JLINKARM_IsConnected"); 36 | if (P_JLINKARM_IsConnected == NULL) return 0; 37 | P_JLINKARM_IsHalted = JLinkDLL_getSym("JLINKARM_IsHalted"); 38 | if (P_JLINKARM_IsHalted == NULL) return 0; 39 | P_JLINKARM_IsOpen = JLinkDLL_getSym("JLINKARM_IsOpen"); 40 | if (P_JLINKARM_IsOpen == NULL) return 0; 41 | P_JLINKARM_Lock = JLinkDLL_getSym("JLINKARM_Lock"); 42 | if (P_JLINKARM_Lock == NULL) return 0; 43 | P_JLINKARM_Open = JLinkDLL_getSym("JLINKARM_Open"); 44 | if (P_JLINKARM_Open == NULL) return 0; 45 | P_JLINKARM_OpenEx = JLinkDLL_getSym("JLINKARM_OpenEx"); 46 | if (P_JLINKARM_OpenEx == NULL) return 0; 47 | P_JLINKARM_Unlock = JLinkDLL_getSym("JLINKARM_Unlock"); 48 | if (P_JLINKARM_Unlock == NULL) return 0; 49 | return 1; 50 | } 51 | //PYTHON CHECK POINT 52 | void JLINKARM_Close(void) { 53 | JLinkDLL_CALLPTR(P_JLINKARM_Close); 54 | } 55 | 56 | int JLINKARM_Connect(void) { 57 | return JLinkDLL_CALLPTR(P_JLINKARM_Connect); 58 | } 59 | 60 | void JLINKARM_Go(void) { 61 | JLinkDLL_CALLPTR(P_JLINKARM_Go); 62 | } 63 | 64 | void JLINKARM_GoIntDis(void) { 65 | JLinkDLL_CALLPTR(P_JLINKARM_GoIntDis); 66 | } 67 | 68 | char JLINKARM_Halt(void) { 69 | return JLinkDLL_CALLPTR(P_JLINKARM_Halt); 70 | } 71 | 72 | 73 | void JLINKARM_GoEx(uint32_t MaxEmulInsts, uint32_t Flags) { 74 | JLinkDLL_CALLPTR(P_JLINKARM_GoEx, MaxEmulInsts, Flags); 75 | } 76 | 77 | 78 | char JLINKARM_IsConnected(void) { 79 | return JLinkDLL_CALLPTR(P_JLINKARM_IsConnected); 80 | } 81 | 82 | char JLINKARM_IsHalted(void) { 83 | return JLinkDLL_CALLPTR(P_JLINKARM_IsHalted); 84 | } 85 | 86 | char JLINKARM_IsOpen(void) { 87 | return JLinkDLL_CALLPTR(P_JLINKARM_IsOpen); 88 | } 89 | 90 | void JLINKARM_Lock(void) { 91 | JLinkDLL_CALLPTR(P_JLINKARM_Lock); 92 | } 93 | 94 | const char *JLINKARM_Open(void) { 95 | return JLinkDLL_CALLPTR(P_JLINKARM_Open); 96 | } 97 | 98 | const char *JLINKARM_OpenEx(JLINKARM_LOG *pfLog, JLINKARM_LOG *pfErrorOut) { 99 | return JLinkDLL_CALLPTR(P_JLINKARM_OpenEx, pfLog, pfErrorOut); 100 | } 101 | 102 | void JLINKARM_Unlock(void) { 103 | JLinkDLL_CALLPTR(P_JLINKARM_Unlock); 104 | } 105 | //PYTHON CHECK POINT 106 | -------------------------------------------------------------------------------- /JLink/General/JLink_Basic.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file JLink_Basic.h 3 | * @author yao 4 | */ 5 | 6 | #ifndef JLINKDLL_JLINK_BASIC_H 7 | #define JLINKDLL_JLINK_BASIC_H 8 | 9 | #include 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | /** 15 | * This function closes the JTAG connection and the connection to the J-Link. 16 | */ 17 | void JLINKARM_Close(void); 18 | 19 | /** 20 | * This function establishes a connection to the target system. 21 | * When calling this func- tion, JLink will start its auto-detection 22 | * and identification of the target CPU. It is nec- essary to call 23 | * this function before any other target communication than low-level 24 | * JTAG/SWD sequence generation is performed. 25 | 26 | * @retval >= 0 O.K. Connection to target system established successfully. 27 | * @retval < 0 Error 28 | * @retval -1 Unspecified error 29 | * @retval <= -256 Global DLL error code. For a list of global error codes 30 | * which can be returned by this function, please refer to Global 31 | * DLL error codes on page 51. 32 | */ 33 | int JLINKARM_Connect(void); 34 | 35 | /** 36 | * Restarts the CPU core after it has been halted. If the current instruction is break- pointed, 37 | * this instruction is not automatically overstepped. Instead, the CPU will immediately stop 38 | * again. If the intention is to overstep a breakpointed instruction, there are 2 possible options: 39 | * 40 | * - Perform a single step (which oversteps any breakpointed instruction), then start the 41 | * CPU using JLINKARM_Go() 42 | * 43 | * - Use JLINKARM_GoEx() with the JLINKARM_GO_OVERSTEP_BP option 44 | * 45 | */ 46 | void JLINKARM_Go(void); 47 | 48 | /** 49 | * This function restarts the CPU core, but in addition to JLINKARM_Go() it allows to define a 50 | * maximum number of instructions which can be simulated/emulated. This especially takes 51 | * advantage when the program is located in flash and flash breakpoints are used. Simulating 52 | * instructions avoids to reprogram the flash and speeds up (single) stepping, especially on 53 | * source code level 54 | * @param MaxEmulInsts Maximum number of instructions allowed to be simulated. Instruction 55 | * simulation stops whenever a breakpointed instruction is hit, an instruction 56 | * which can not be simulated/emulated is hit or when MaxEmulInsts is reached. 57 | * @param Flags Specifies the behaviour of JLINKARM_GoEx 58 | * @see JLINKARM_GO_OVERSTEP_BP 59 | */ 60 | void JLINKARM_GoEx(uint32_t MaxEmulInsts, uint32_t Flags); 61 | 62 | /** 63 | * Disables the interrupts and restarts the CPU core. If the current instruction is breakpointed, 64 | * this instruction is not automatically overstepped. Instead, the CPU will immediately stop 65 | * again. If the intention is to overstep a breakpointed instruction, perform a single step (which 66 | * oversteps any breakpointed instruction), then start the CPU using {@link JLINKARM_GoIntDis}. 67 | */ 68 | void JLINKARM_GoIntDis(void); 69 | 70 | /** 71 | * This function halts the ARM core. It is always the first function you have to call if you want 72 | * to communicate with the ARM core 73 | * @retval 0 if ARM core has been halted 74 | * @retval 1 on error 75 | */ 76 | char JLINKARM_Halt(void); 77 | 78 | /** 79 | * This function checks whether the JTAG connection has been opened. 80 | * @retval 0 if not connected 81 | * @retval 1 if connected 82 | */ 83 | char JLINKARM_IsConnected(void); 84 | 85 | /** 86 | * This function checks whether the ARM core is halted. 87 | * @retval 0 ARM core is not halted 88 | * @retval 1 ARM core is halted 89 | * @retval <0 Error 90 | */ 91 | char JLINKARM_IsHalted(void); 92 | 93 | /** 94 | * Check if DLL has been opened ({@link JLINKARM_Open} or {@link JLINKARM_OpenEx} successfully returned) 95 | * and therefore a connection to a J-Link could be established. 96 | * @return 97 | */ 98 | char JLINKARM_IsOpen(void); 99 | 100 | /** 101 | * Per default, the J-Link API locks against other threads and processes (accessing the same 102 | * J-Link) for the duration of the API call. 103 | * 104 | * If there are have multiple API calls that need to be done in order andmust not be interrupted 105 | * by an API call from another thread / process, JLINKARM_Lock can be called to lock beyond 106 | * a single API call. 107 | * 108 | * After the multi-API call operation is finished, {@link JLINKARM_Unlock} must be called. 109 | */ 110 | void JLINKARM_Lock(void); 111 | 112 | /** 113 | * This function opens the connection to J-Link. It’s always the first function you have to call to 114 | * use the J-Link ARM DLL. After opening the connection, the function checks also if a newer 115 | * firmware version is available. 116 | * @code 117 | * sError = JLINKARM_Open(); 118 | * if (sError) { 119 | * MessageBox(NULL, sError, "J-Link", MB_OK); 120 | * exit(1); 121 | * } 122 | * @endcode 123 | * @retval NULL Ok 124 | * @retval !=NULL Pointer to an error string 125 | */ 126 | const char *JLINKARM_Open(void); 127 | 128 | /** 129 | * Opens the JTAG connection (see description of {@link JLINKARM_Open}). This function allows to 130 | * set log and error out handlers before the JTAG connection is opened. 131 | * @code 132 | * static void _LogHandler(const char* sLog) { 133 | * printf(sLog); 134 | * } 135 | * static void _ErrorOutHandler(const char* sError) { 136 | * MessageBox(NULL, sError, "J-Link", MB_OK); 137 | * } 138 | * void main(void) { 139 | * const char* sError; 140 | * sError = JLINKARM_OpenEx(_LogHandler, _ErrorOutHandler); 141 | * if (sError) { 142 | * MessageBox(NULL, sError, "J-Link", MB_OK); 143 | * exit(1); 144 | * } 145 | * } 146 | * @endcode 147 | * @param pfLog Pointer to log handler function of type JLINKARM_LOG 148 | * @param pfErrorOut Pointer to error out handler function of type JLINKARM_LOG. 149 | * @retval NULL Ok 150 | * @retval !=NULL Pointer to an error string 151 | */ 152 | const char *JLINKARM_OpenEx(JLINKARM_LOG *pfLog, JLINKARM_LOG *pfErrorOut); 153 | 154 | /** 155 | * Please refer to {link JLINKARM_Lock} 156 | * @see JLINKARM_Lock 157 | */ 158 | void JLINKARM_Unlock(void); 159 | 160 | #ifdef __cplusplus 161 | } 162 | #endif 163 | 164 | #endif //JLINKDLL_JLINK_BASIC_H 165 | -------------------------------------------------------------------------------- /JLink/General/JLink_Configuration.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yaoji on 2022/3/18. 3 | // 4 | 5 | #include "JLink_Configuration.h" 6 | #include "JLink/JLink_Init.h" 7 | 8 | static void (*P_JLINKARM_ConfigJTAG)(int IRPre, int DRPre); 9 | static int (*P_JLINK_EMU_AddLicense)(const char *sLicense); 10 | static int (*P_JLINK_EMU_EraseLicenses)(void); 11 | static int (*P_JLINK_EMU_GetLicenses)(char *pBuffer, uint32_t NumBytes); 12 | static int (*P_JLINKARM_EMU_SelectByUSBSN)(uint32_t SerialNo); 13 | static int (*P_JLINKARM_EMU_SelectIP)(char *pIPAddr, int BufferSize, uint16_t *pPort); 14 | static void (*P_JLINKARM_EMU_SelectIPBySN)(uint32_t SerialNo); 15 | static uint32_t (*P_JLINKARM_GetId)(void); 16 | static char (*P_JLINKARM_SelectIP)(const char *sHost, int Port); 17 | static char (*P_JLINKARM_SelectUSB)(int Port); 18 | static int (*P_JLINK_SetHookUnsecureDialog)(JLINK_UNSECURE_DIALOG_CB_FUNC *pfHook); 19 | static int (*P_JLINKARM_EMU_GetList)(int HostIFs, JLINKARM_EMU_CONNECT_INFO *paConnectInfo, int MaxInfos); 20 | 21 | int JLINK_GERENAL_CONFIGURATION_Init() { 22 | P_JLINKARM_ConfigJTAG = JLinkDLL_getSym("JLINKARM_ConfigJTAG"); 23 | if (P_JLINKARM_ConfigJTAG == NULL) return 0; 24 | P_JLINK_EMU_AddLicense = JLinkDLL_getSym("JLINK_EMU_AddLicense"); 25 | if (P_JLINK_EMU_AddLicense == NULL) return 0; 26 | P_JLINK_EMU_EraseLicenses = JLinkDLL_getSym("JLINK_EMU_EraseLicenses"); 27 | if (P_JLINK_EMU_EraseLicenses == NULL) return 0; 28 | P_JLINK_EMU_GetLicenses = JLinkDLL_getSym("JLINK_EMU_GetLicenses"); 29 | if (P_JLINK_EMU_GetLicenses == NULL) return 0; 30 | P_JLINKARM_EMU_SelectByUSBSN = JLinkDLL_getSym("JLINKARM_EMU_SelectByUSBSN"); 31 | if (P_JLINKARM_EMU_SelectByUSBSN == NULL) return 0; 32 | P_JLINKARM_EMU_SelectIP = JLinkDLL_getSym("JLINKARM_EMU_SelectIP"); 33 | if (P_JLINKARM_EMU_SelectIP == NULL) return 0; 34 | P_JLINKARM_EMU_SelectIPBySN = JLinkDLL_getSym("JLINKARM_EMU_SelectIPBySN"); 35 | if (P_JLINKARM_EMU_SelectIPBySN == NULL) return 0; 36 | P_JLINKARM_GetId = JLinkDLL_getSym("JLINKARM_GetId"); 37 | if (P_JLINKARM_GetId == NULL) return 0; 38 | P_JLINKARM_SelectIP = JLinkDLL_getSym("JLINKARM_SelectIP"); 39 | if (P_JLINKARM_SelectIP == NULL) return 0; 40 | P_JLINKARM_SelectUSB = JLinkDLL_getSym("JLINKARM_SelectUSB"); 41 | if (P_JLINKARM_SelectUSB == NULL) return 0; 42 | P_JLINK_SetHookUnsecureDialog = JLinkDLL_getSym("JLINK_SetHookUnsecureDialog"); 43 | if (P_JLINK_SetHookUnsecureDialog == NULL) return 0; 44 | P_JLINKARM_EMU_GetList = JLinkDLL_getSym("JLINKARM_EMU_GetList"); 45 | if (P_JLINKARM_EMU_GetList == NULL) return 0; 46 | return 1; 47 | } 48 | 49 | //PYTHON CHECK POINT 50 | void JLINKARM_ConfigJTAG(int IRPre, int DRPre) { 51 | JLinkDLL_CALLPTR(P_JLINKARM_ConfigJTAG, IRPre, DRPre); 52 | } 53 | 54 | int JLINK_EMU_AddLicense(const char *sLicense) { 55 | return JLinkDLL_CALLPTR(P_JLINK_EMU_AddLicense, sLicense); 56 | } 57 | 58 | int JLINK_EMU_EraseLicenses(void) { 59 | return JLinkDLL_CALLPTR(P_JLINK_EMU_EraseLicenses); 60 | } 61 | 62 | int JLINK_EMU_GetLicenses(char *pBuffer, uint32_t NumBytes) { 63 | return JLinkDLL_CALLPTR(P_JLINK_EMU_GetLicenses, pBuffer, NumBytes); 64 | } 65 | 66 | int JLINKARM_EMU_SelectByUSBSN(uint32_t SerialNo) { 67 | return JLinkDLL_CALLPTR(P_JLINKARM_EMU_SelectByUSBSN, SerialNo); 68 | } 69 | 70 | int JLINKARM_EMU_SelectIP(char *pIPAddr, int BufferSize, uint16_t *pPort) { 71 | return JLinkDLL_CALLPTR(P_JLINKARM_EMU_SelectIP, pIPAddr, BufferSize, pPort); 72 | } 73 | 74 | void JLINKARM_EMU_SelectIPBySN(uint32_t SerialNo) { 75 | JLinkDLL_CALLPTR(P_JLINKARM_EMU_SelectIPBySN, SerialNo); 76 | } 77 | 78 | uint32_t JLINKARM_GetId(void) { 79 | return JLinkDLL_CALLPTR(P_JLINKARM_GetId); 80 | } 81 | 82 | char JLINKARM_SelectIP(const char *sHost, int Port) { 83 | return JLinkDLL_CALLPTR(P_JLINKARM_SelectIP, sHost, Port); 84 | } 85 | 86 | char JLINKARM_SelectUSB(int Port) { 87 | return JLinkDLL_CALLPTR(P_JLINKARM_SelectUSB, Port); 88 | } 89 | 90 | int JLINK_SetHookUnsecureDialog(JLINK_UNSECURE_DIALOG_CB_FUNC *pfHook) { 91 | return JLinkDLL_CALLPTR(P_JLINK_SetHookUnsecureDialog, pfHook); 92 | } 93 | 94 | int JLINKARM_EMU_GetList(int HostIFs, JLINKARM_EMU_CONNECT_INFO *paConnectInfo, int MaxInfos) { 95 | return JLinkDLL_CALLPTR(P_JLINKARM_EMU_GetList, HostIFs, paConnectInfo, MaxInfos); 96 | } 97 | //PYTHON CHECK POINT -------------------------------------------------------------------------------- /JLink/General/JLink_Configuration.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file JLink_Configuration.h 3 | * @author yao 4 | */ 5 | 6 | #ifndef JLINKDLL_JLINK_CONFIGURATION_H 7 | #define JLINKDLL_JLINK_CONFIGURATION_H 8 | 9 | #include 10 | #include 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | /** 16 | * @param sTitle Title of the unsecure dialog. Can be shown by handler function. 17 | * @param sMsg Text of the unsecure dialog (what will happen etc.). Can be shown by 18 | * the handler function 19 | */ 20 | typedef int (*JLINK_UNSECURE_DIALOG_CB_FUNC)(const char *sTitle, const char *sMsg, uint32_t Flags); 21 | 22 | /** 23 | * This function configures the JTAG scan chain and needs to be called if the J-Link ARM is 24 | * connected to a JTAG scan chain with multiple devices. In this case this function enables you 25 | * to configure the exact position of the ARM device you want to address. 26 | * @param IRPre Total length of instruction registers of all devices closer to TDI than 27 | * the addressed ARM device. The instruction register length is defined 28 | * by the manufacturer of the device. For ARM7 and ARM9 chips, the 29 | * length of the instruction register is four. 30 | * @param DRPre Total number of data bits closer to TDI than the addressed ARM device. 31 | */ 32 | void JLINKARM_ConfigJTAG(int IRPre, int DRPre); 33 | 34 | /** 35 | * Add a custom license to the connected J-Link. Custom licenses can be stored on a J-Link 36 | * to use it as an USB dongle for software licenses. 37 | * @details J-Link V9 and J-Link ULTRA/PRO V4 have 336 Bytes memory for licenses. Previous models 38 | * support up to 80 Bytes. 39 | * For an example on how to use the J-Link License Feature, refer to Store custom licenses 40 | * on J-Link on page 178. 41 | * @param sLicense 0-Terminated license string to be added to J-Link. 42 | * @retval 0 O.K., license added. 43 | * @retval 1 O.K., license already exists. 44 | * @retval -1 Error. Unspecified 45 | * @retval -2 Error. Failed to read/write licensearea 46 | * @retval -3 Error. Not enough space on J-Link to store license 47 | */ 48 | int JLINK_EMU_AddLicense(const char *sLicense); 49 | 50 | /** 51 | * Erase all custom licenses from the connected J-Link’s. 52 | * @retval 0 O.K. 53 | * @retval <0 Error. 54 | */ 55 | int JLINK_EMU_EraseLicenses(void); 56 | 57 | /** 58 | * Get all custom licenses from the connected J-Link. 59 | * @details J-Link V9 and J-Link ULTRA/PRO V4 have 336 Bytes memory for licenses. Previous models 60 | * support up to 80 Bytes. For an example on how to use the J-Link License Feature, refer to 61 | * “Store custom licenses on J-Link” on page 178. 62 | * @param pBuffer Pointer to buffer to store the licenses into. 63 | * @param NumBytes Number of bytes available in the buffer. 64 | * @retval >=0 O.K., Number of bytes written into buffer. 65 | * @retval <0 Error. 66 | */ 67 | int JLINK_EMU_GetLicenses(char *pBuffer, uint32_t NumBytes); 68 | 69 | 70 | enum { 71 | JLINKARM_HOSTIF_USB = 0x01, 72 | JLINKARM_HOSTIF_IP = 0x02, 73 | }; 74 | 75 | /** 76 | * This function is used to get a list of all emulators which are connected to the host PC via 77 | * USB. In addition to that when calling this function, it can be specified if emulators which 78 | * are connected via TCP/IP should also be listed. This function does not commu- nicate with 79 | * the J-Link firmware in order to get the emulator information, so calling this function does 80 | * not interfere with a J-Link which is in a running debug session. 81 | * @code 82 | * int r; 83 | * int i; 84 | * char NeedDealloc; 85 | * char ac[128]; 86 | * const char *s; 87 | * uint32_t Index; 88 | * JLINKARM_EMU_CONNECT_INFO * paConnectInfo; 89 | * JLINKARM_EMU_CONNECT_INFO aConnectInfo[50]; 90 | * // 91 | * // Request emulator list 92 | * // 93 | * r = JLINKARM_EMU_GetList(JLINKARM_HOSTIF_USB, &aConnectInfo[0], COUNTOF(aConnectInfo)); 94 | * // 95 | * // Allocate memory for emulator info buffer if local buffer is not big enough 96 | * // 97 | * NeedDealloc = 0; 98 | * if (r > COUNTOF(aConnectInfo)) { 99 | * paConnectInfo = malloc(r * sizeof(JLINKARM_EMU_CONNECT_INFO)); 100 | * if (paConnectInfo == NULL) { 101 | * printf("Failed to allocate memory for emulator info buffer.\n"); 102 | * return -1; 103 | * } 104 | * JLINKARM_EMU_GetList(JLINKARM_HOSTIF_USB, paConnectInfo, r); 105 | * } 106 | * @endcode 107 | * @param HostIFs Specifies on which host interfaces should be searched for connected J-Links. 108 | * HostIFs can be JLINKARM_HOSTIF_USB or JLINKARM_HOSTIF_IP. Both host interface 109 | * types can be or-combined. 110 | * @param paConnectInfo Pointer to an array of JLINKARM_EMU_CONNECT_INFO structures which is used 111 | * to hold the information for each emulator. 112 | * @param MaxInfos Specifies the maximum number of emulators for which information can be stored 113 | * in the array pointed to by paConnectInfo . 114 | * @retval >=0 O.K., total number of emulators which have been found. 115 | * @retval <0 Error. 116 | */ 117 | int JLINKARM_EMU_GetList(int HostIFs, JLINKARM_EMU_CONNECT_INFO *paConnectInfo, int MaxInfos); 118 | 119 | /** 120 | * This function allows the user to select a specific J-Link he wants to connect to by passing 121 | * the units serial number to this function. In general there are 2 different ways how a J-Link 122 | * can be identified by the host system: 123 | * 124 | * 1. By the USB address the J-Link is connected to (deprecated) 125 | * 126 | * 2. By the serial number of the unit 127 | * 128 | * The old method to connect multiple J-Links to one PC via USB was, to configure them to 129 | * be identified by different USB addresses. This method limited the maximum number of JLinks which could be simultaneously connected to one PC to 4 (USB addr. 0 - 3). This way 130 | * of connecting multiple J-Links to the PC is deprecated and should not be used anymore. 131 | * Nevertheless, due to compatibility it is still supported by later versions of the DLL. The 132 | * identification via serial number allows a unlimited number of J-Links to be simultaneously 133 | * connected to the PC. 134 | * @code 135 | * // 136 | * // Select J-Link with serial number 58001326 137 | * // to connect to when calling JLINKARM_Open() 138 | * // 139 | * JLINKARM_EMU_SelectByUSBSN(58001326); 140 | * // 141 | * // Connect to selected J-Link 142 | * // 143 | * JLINKARM_Open(); 144 | * @endcode 145 | * @param SerialNo Serial number of the J-Link which shall be selected. 146 | * @retval >=0 Index of emulator with given serial number (0 if only one emulator is connected to the PC) 147 | * @retval <0 Error, no emulator with given serial number found 148 | */ 149 | int JLINKARM_EMU_SelectByUSBSN(uint32_t SerialNo); 150 | 151 | /** 152 | * This function opens the J-Link emulator selection dialog in order to 153 | * select between all emulators which are available over TCP/IP. 154 | * @param pIPAddr Buffer which holds the IP address of the selected emulator. 155 | * @param BufferSize Size of the buffer which pIPAddr is pointing to. 156 | * @param pPort Port number of the selected connection. 157 | * @retval <0 No emulator selected 158 | * @retval >=0 Ok 159 | */ 160 | int JLINKARM_EMU_SelectIP(char *pIPAddr, int BufferSize, uint16_t *pPort); 161 | 162 | /** 163 | * Select an emulator which is connected to the host via Ethernet, by its serial number. This 164 | * function can be used to select an emulator even if you do not know its IP address (for 165 | * environments where the IP address is changed in some intervals). You simply need the 166 | * emulator’s serial number in order to connect to it. 167 | * @param SerialNo Serial number of the emulator which shall be selected. 168 | */ 169 | void JLINKARM_EMU_SelectIPBySN(uint32_t SerialNo); 170 | 171 | /** 172 | * This function returns the Id of the ARM core. 173 | * @return 32-bit Id number. 174 | */ 175 | uint32_t JLINKARM_GetId(void); 176 | 177 | /** 178 | * This function selects and configures a connection to the J-Link via TCP/IP. 179 | * @param sHost String that contains a host name or an IP address. 180 | * @param Port TCP/IP port to be used for the connection. 181 | * @retval 0 O.K. 182 | * @retval 1 Error 183 | */ 184 | char JLINKARM_SelectIP(const char *sHost, int Port); 185 | 186 | /** 187 | * This function selects and configures a connection to J-Link via USB. Per default, the DLL 188 | * connects via USB to J-Link. In this version of the DLL up to 4 J-Links can be connected 189 | * to a single host. 190 | * @note This function should be called before trying to connect to the J-Link using {@link JLINKARM_Open} or {@link JLINKARM_OpenEx}. 191 | * @param Port USB port to be used for the connection. Valid values range from 0 to 3. 192 | * @retval 0 O.K. 193 | * @retval 1 Error 194 | */ 195 | char JLINKARM_SelectUSB(int Port); 196 | 197 | /** 198 | * Sets a hook function that is called instead of showing the device-unsecure-dialog of the 199 | * J-Link DLL. Can be used to customize the unsecure dialog that potentially shows up for 200 | * certain devices, if they are locked/secured. This especially makes sense, if an IDE vendor 201 | * etc. wants to show additional / other information in the unsecure dialog etc. 202 | * @note This dialog is only available for certain devices. It is not available for all ones. 203 | * @note This function should be called after {@link JLINK_Open} but before {@link JLINK_Connect}. 204 | * @param pfHook Pointer to unsecure dialog handling type JLINK_UNSECURE_DIALOG_CB_FUNC. 205 | * @retval >=0 O.K. 206 | * @retval <0 Error 207 | */ 208 | int JLINK_SetHookUnsecureDialog(JLINK_UNSECURE_DIALOG_CB_FUNC *pfHook); 209 | 210 | #ifdef __cplusplus 211 | } 212 | #endif 213 | 214 | #endif //JLINKDLL_JLINK_CONFIGURATION_H 215 | -------------------------------------------------------------------------------- /JLink/General/JLink_Debugging.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yaoji on 2022/3/18. 3 | // 4 | 5 | #include "JLink_Debugging.h" 6 | #include 7 | 8 | static int (*P_JLINKARM_ClrWP)(int WPHandle); 9 | static int (*P_JLINKARM_ClrDataEvent)(uint32_t Handle); 10 | static void (*P_JLINKARM_ClrBP)(unsigned int BPIndex); 11 | static int (*P_JLINKARM_ClrBPEx)(int BPHandle); 12 | static int (*P_JLINKARM_SetDataEvent)(JLINKARM_DATA_EVENT *pEvent, uint32_t *pHandle); 13 | static uint32_t (*P_JLINKARM_CORE_GetFound)(void); 14 | static void (*P_JLINKARM_EnableSoftBPs)(char Enable); 15 | static int (*P_JLINKARM_FindBP)(uint32_t Addr); 16 | static uint32_t (*P_JLINKARM_GetBPInfo)(int BPHandle); 17 | static unsigned (*P_JLINKARM_GetNumBPs)(void); 18 | static int (*P_JLINKARM_GetBPInfoEx)(int iBP, JLINKARM_BP_INFO *pInfo); 19 | static unsigned (*P_JLINKARM_GetNumWPs)(void); 20 | static int (*P_JLINKARM_GetNumBPUnits)(JLINKARM_BP_TYPE Type); 21 | static int (*P_JLINKARM_GetNumWPUnits)(void); 22 | static int (*P_JLINKARM_GetRegisterList)(uint32_t *paList, int MaxNumItems); 23 | static const char *(*P_JLINKARM_GetRegisterName)(uint32_t RegIndex); 24 | static int (*P_JLINKARM_GetWPInfoEx)(int iWP, JLINKARM_WP_INFO *pInfo); 25 | static void (*P_JLINKARM_GoAllowSim)(uint32_t NumInsts); 26 | static int (*P_JLINKARM_ReadCodeMem)(uint32_t Addr, uint32_t NumBytes, void *pData); 27 | static uint32_t (*P_JLINKARM_ReadICEReg)(int RegIndex); 28 | static uint32_t (*P_JLINKARM_ReadReg)(ARM_REG RegIndex); 29 | static int (*P_JLINKARM_ReadRegs)(const uint32_t *paRegIndex, uint32_t *paData, uint8_t *paStatus, uint32_t NumRegs); 30 | static int (*P_JLINKARM_ReadTerminal)(uint8_t *pBuffer, uint32_t BufferSize); 31 | static char (*P_JLINKARM_SimulateInstruction)(uint32_t Inst); 32 | static void (*P_JLINKARM_SetBP)(unsigned BPIndex, uint32_t Addr); 33 | static int (*P_JLINKARM_SetBPEx)(uint32_t Addr, uint32_t TypeFlags); 34 | static int (*P_JLINKARM_SetDataEvent)(JLINKARM_DATA_EVENT *pEvent, uint32_t *pHandle); 35 | static char (*P_JLINKARM_Step)(void); 36 | static char (*P_JLINKARM_StepComposite)(void); 37 | static int (*P_JLINKARM_WaitForHalt)(int TimeOut); 38 | static void (*P_JLINKARM_WriteICEReg)(int RegIndex, uint32_t Value, int AllowDelay); 39 | static char (*P_JLINKARM_WriteReg)(ARM_REG RegIndex, uint32_t Data); 40 | static int (*P_JLINKARM_WriteRegs)(const uint32_t *paRegIndex, const uint32_t *paData, uint8_t *paStatus, uint32_t NumRegs); 41 | static int (*P_JLINKARM_WriteVectorCatch)(uint32_t Value); 42 | static int (*P_JLINKARM_ReadDCC)(uint32_t *pData, uint32_t NumItems, int TimeOut); 43 | static void (*P_JLINKARM_ReadDCCFast)(uint32_t *pData, uint32_t NumItems); 44 | static int (*P_JLINKARM_WaitDCCRead)(int TimeOut); 45 | static int (*P_JLINKARM_WriteDCC)(const uint32_t *pData, uint32_t NumItems, int TimeOut); 46 | static void (*P_JLINKARM_WriteDCCFast)(const uint32_t *pData, uint32_t NumItems); 47 | 48 | int JLINK_GERENAL_DEBUGGING_Init() { 49 | P_JLINKARM_ClrWP = JLinkDLL_getSym("JLINKARM_ClrWP"); 50 | if (P_JLINKARM_ClrWP == NULL) return 0; 51 | P_JLINKARM_ClrDataEvent = JLinkDLL_getSym("JLINKARM_ClrDataEvent"); 52 | if (P_JLINKARM_ClrDataEvent == NULL) return 0; 53 | P_JLINKARM_ClrBP = JLinkDLL_getSym("JLINKARM_ClrBP"); 54 | if (P_JLINKARM_ClrBP == NULL) return 0; 55 | P_JLINKARM_ClrBPEx = JLinkDLL_getSym("JLINKARM_ClrBPEx"); 56 | if (P_JLINKARM_ClrBPEx == NULL) return 0; 57 | P_JLINKARM_SetDataEvent = JLinkDLL_getSym("JLINKARM_SetDataEvent"); 58 | if (P_JLINKARM_SetDataEvent == NULL) return 0; 59 | P_JLINKARM_CORE_GetFound = JLinkDLL_getSym("JLINKARM_CORE_GetFound"); 60 | if (P_JLINKARM_CORE_GetFound == NULL) return 0; 61 | P_JLINKARM_EnableSoftBPs = JLinkDLL_getSym("JLINKARM_EnableSoftBPs"); 62 | if (P_JLINKARM_EnableSoftBPs == NULL) return 0; 63 | P_JLINKARM_FindBP = JLinkDLL_getSym("JLINKARM_FindBP"); 64 | if (P_JLINKARM_FindBP == NULL) return 0; 65 | P_JLINKARM_GetBPInfo = JLinkDLL_getSym("JLINKARM_GetBPInfo"); 66 | if (P_JLINKARM_GetBPInfo == NULL) return 0; 67 | P_JLINKARM_GetNumBPs = JLinkDLL_getSym("JLINKARM_GetNumBPs"); 68 | if (P_JLINKARM_GetNumBPs == NULL) return 0; 69 | P_JLINKARM_GetBPInfoEx = JLinkDLL_getSym("JLINKARM_GetBPInfoEx"); 70 | if (P_JLINKARM_GetBPInfoEx == NULL) return 0; 71 | P_JLINKARM_GetNumWPs = JLinkDLL_getSym("JLINKARM_GetNumWPs"); 72 | if (P_JLINKARM_GetNumWPs == NULL) return 0; 73 | P_JLINKARM_GetNumBPUnits = JLinkDLL_getSym("JLINKARM_GetNumBPUnits"); 74 | if (P_JLINKARM_GetNumBPUnits == NULL) return 0; 75 | P_JLINKARM_GetNumWPUnits = JLinkDLL_getSym("JLINKARM_GetNumWPUnits"); 76 | if (P_JLINKARM_GetNumWPUnits == NULL) return 0; 77 | P_JLINKARM_GetRegisterList = JLinkDLL_getSym("JLINKARM_GetRegisterList"); 78 | if (P_JLINKARM_GetRegisterList == NULL) return 0; 79 | P_JLINKARM_GetRegisterName = JLinkDLL_getSym("JLINKARM_GetRegisterName"); 80 | if (P_JLINKARM_GetRegisterName == NULL) return 0; 81 | P_JLINKARM_GetWPInfoEx = JLinkDLL_getSym("JLINKARM_GetWPInfoEx"); 82 | if (P_JLINKARM_GetWPInfoEx == NULL) return 0; 83 | P_JLINKARM_GoAllowSim = JLinkDLL_getSym("JLINKARM_GoAllowSim"); 84 | if (P_JLINKARM_GoAllowSim == NULL) return 0; 85 | P_JLINKARM_ReadCodeMem = JLinkDLL_getSym("JLINKARM_ReadCodeMem"); 86 | if (P_JLINKARM_ReadCodeMem == NULL) return 0; 87 | P_JLINKARM_ReadICEReg = JLinkDLL_getSym("JLINKARM_ReadICEReg"); 88 | if (P_JLINKARM_ReadICEReg == NULL) return 0; 89 | P_JLINKARM_ReadReg = JLinkDLL_getSym("JLINKARM_ReadReg"); 90 | if (P_JLINKARM_ReadReg == NULL) return 0; 91 | P_JLINKARM_ReadRegs = JLinkDLL_getSym("JLINKARM_ReadRegs"); 92 | if (P_JLINKARM_ReadRegs == NULL) return 0; 93 | P_JLINKARM_ReadTerminal = JLinkDLL_getSym("JLINKARM_ReadTerminal"); 94 | if (P_JLINKARM_ReadTerminal == NULL) return 0; 95 | P_JLINKARM_SimulateInstruction = JLinkDLL_getSym("JLINKARM_SimulateInstruction"); 96 | if (P_JLINKARM_SimulateInstruction == NULL) return 0; 97 | P_JLINKARM_SetBP = JLinkDLL_getSym("JLINKARM_SetBP"); 98 | if (P_JLINKARM_SetBP == NULL) return 0; 99 | P_JLINKARM_SetBPEx = JLinkDLL_getSym("JLINKARM_SetBPEx"); 100 | if (P_JLINKARM_SetBPEx == NULL) return 0; 101 | P_JLINKARM_SetDataEvent = JLinkDLL_getSym("JLINKARM_SetDataEvent"); 102 | if (P_JLINKARM_SetDataEvent == NULL) return 0; 103 | P_JLINKARM_Step = JLinkDLL_getSym("JLINKARM_Step"); 104 | if (P_JLINKARM_Step == NULL) return 0; 105 | P_JLINKARM_StepComposite = JLinkDLL_getSym("JLINKARM_StepComposite"); 106 | if (P_JLINKARM_StepComposite == NULL) return 0; 107 | P_JLINKARM_WaitForHalt = JLinkDLL_getSym("JLINKARM_WaitForHalt"); 108 | if (P_JLINKARM_WaitForHalt == NULL) return 0; 109 | P_JLINKARM_WriteICEReg = JLinkDLL_getSym("JLINKARM_WriteICEReg"); 110 | if (P_JLINKARM_WriteICEReg == NULL) return 0; 111 | P_JLINKARM_WriteReg = JLinkDLL_getSym("JLINKARM_WriteReg"); 112 | if (P_JLINKARM_WriteReg == NULL) return 0; 113 | P_JLINKARM_WriteRegs = JLinkDLL_getSym("JLINKARM_WriteRegs"); 114 | if (P_JLINKARM_WriteRegs == NULL) return 0; 115 | P_JLINKARM_WriteVectorCatch = JLinkDLL_getSym("JLINKARM_WriteVectorCatch"); 116 | if (P_JLINKARM_WriteVectorCatch == NULL) return 0; 117 | P_JLINKARM_ReadDCC = JLinkDLL_getSym("JLINKARM_ReadDCC"); 118 | if (P_JLINKARM_ReadDCC == NULL) return 0; 119 | P_JLINKARM_ReadDCCFast = JLinkDLL_getSym("JLINKARM_ReadDCCFast"); 120 | if (P_JLINKARM_ReadDCCFast == NULL) return 0; 121 | P_JLINKARM_WaitDCCRead = JLinkDLL_getSym("JLINKARM_WaitDCCRead"); 122 | if (P_JLINKARM_WaitDCCRead == NULL) return 0; 123 | P_JLINKARM_WriteDCC = JLinkDLL_getSym("JLINKARM_WriteDCC"); 124 | if (P_JLINKARM_WriteDCC == NULL) return 0; 125 | P_JLINKARM_WriteDCCFast = JLinkDLL_getSym("JLINKARM_WriteDCCFast"); 126 | if (P_JLINKARM_WriteDCCFast == NULL) return 0; 127 | return 1; 128 | } 129 | 130 | //PYTHON CHECK POINT 131 | int JLINKARM_ClrWP(int WPHandle) { 132 | return JLinkDLL_CALLPTR(P_JLINKARM_ClrWP, WPHandle); 133 | } 134 | 135 | int JLINKARM_ClrDataEvent(uint32_t Handle) { 136 | return JLinkDLL_CALLPTR(P_JLINKARM_ClrDataEvent, Handle); 137 | } 138 | 139 | void JLINKARM_ClrBP(unsigned int BPIndex) { 140 | JLinkDLL_CALLPTR(P_JLINKARM_ClrBP, BPIndex); 141 | } 142 | 143 | int JLINKARM_ClrBPEx(int BPHandle) { 144 | return JLinkDLL_CALLPTR(P_JLINKARM_ClrBPEx, BPHandle); 145 | } 146 | 147 | uint32_t JLINKARM_CORE_GetFound(void) { 148 | return JLinkDLL_CALLPTR(P_JLINKARM_CORE_GetFound); 149 | } 150 | 151 | void JLINKARM_EnableSoftBPs(char Enable) { 152 | JLinkDLL_CALLPTR(P_JLINKARM_EnableSoftBPs, Enable); 153 | } 154 | 155 | int JLINKARM_FindBP(uint32_t Addr) { 156 | return JLinkDLL_CALLPTR(P_JLINKARM_FindBP, Addr); 157 | } 158 | 159 | uint32_t JLINKARM_GetBPInfo(int BPHandle) { 160 | return JLinkDLL_CALLPTR(P_JLINKARM_GetBPInfo, BPHandle); 161 | } 162 | 163 | unsigned JLINKARM_GetNumBPs(void) { 164 | return JLinkDLL_CALLPTR(P_JLINKARM_GetNumBPs); 165 | } 166 | 167 | int JLINKARM_GetBPInfoEx(int iBP, JLINKARM_BP_INFO *pInfo) { 168 | return JLinkDLL_CALLPTR(P_JLINKARM_GetBPInfoEx, iBP, pInfo); 169 | } 170 | 171 | unsigned JLINKARM_GetNumWPs(void) { 172 | return JLinkDLL_CALLPTR(P_JLINKARM_GetNumWPs); 173 | } 174 | 175 | int JLINKARM_GetNumBPUnits(JLINKARM_BP_TYPE Type) { 176 | return JLinkDLL_CALLPTR(P_JLINKARM_GetNumBPUnits, Type); 177 | } 178 | 179 | int JLINKARM_GetNumWPUnits(void) { 180 | return JLinkDLL_CALLPTR(P_JLINKARM_GetNumWPUnits); 181 | } 182 | 183 | int JLINKARM_GetRegisterList(uint32_t *paList, int MaxNumItems) { 184 | return JLinkDLL_CALLPTR(P_JLINKARM_GetRegisterList, paList, MaxNumItems); 185 | } 186 | 187 | const char *JLINKARM_GetRegisterName(uint32_t RegIndex) { 188 | return JLinkDLL_CALLPTR(P_JLINKARM_GetRegisterName, RegIndex); 189 | } 190 | 191 | int JLINKARM_GetWPInfoEx(int iWP, JLINKARM_WP_INFO *pInfo) { 192 | return JLinkDLL_CALLPTR(P_JLINKARM_GetWPInfoEx, iWP, pInfo); 193 | } 194 | 195 | void JLINKARM_GoAllowSim(uint32_t NumInsts) { 196 | JLinkDLL_CALLPTR(P_JLINKARM_GoAllowSim, NumInsts); 197 | } 198 | 199 | int JLINKARM_ReadCodeMem(uint32_t Addr, uint32_t NumBytes, void *pData) { 200 | return JLinkDLL_CALLPTR(P_JLINKARM_ReadCodeMem, Addr, NumBytes, pData); 201 | } 202 | 203 | uint32_t JLINKARM_ReadICEReg(int RegIndex) { 204 | return JLinkDLL_CALLPTR(P_JLINKARM_ReadICEReg, RegIndex); 205 | } 206 | 207 | uint32_t JLINKARM_ReadReg(ARM_REG RegIndex) { 208 | return JLinkDLL_CALLPTR(P_JLINKARM_ReadReg, RegIndex); 209 | } 210 | 211 | int JLINKARM_ReadRegs(const uint32_t *paRegIndex, uint32_t *paData, uint8_t *paStatus, uint32_t NumRegs) { 212 | return JLinkDLL_CALLPTR(P_JLINKARM_ReadRegs, paRegIndex, paData, paStatus, NumRegs); 213 | } 214 | 215 | int JLINKARM_ReadTerminal(uint8_t *pBuffer, uint32_t BufferSize) { 216 | return JLinkDLL_CALLPTR(P_JLINKARM_ReadTerminal, pBuffer, BufferSize); 217 | } 218 | 219 | char JLINKARM_SimulateInstruction(uint32_t Inst) { 220 | return JLinkDLL_CALLPTR(P_JLINKARM_SimulateInstruction, Inst); 221 | } 222 | 223 | void JLINKARM_SetBP(uint32_t BPIndex, uint32_t Addr) { 224 | JLinkDLL_CALLPTR(P_JLINKARM_SetBP, BPIndex, Addr); 225 | } 226 | 227 | int JLINKARM_SetBPEx(uint32_t Addr, uint32_t TypeFlags) { 228 | return JLinkDLL_CALLPTR(P_JLINKARM_SetBPEx, Addr, TypeFlags); 229 | } 230 | 231 | int JLINKARM_SetDataEvent(JLINKARM_DATA_EVENT *pEvent, uint32_t *pHandle) { 232 | return JLinkDLL_CALLPTR(P_JLINKARM_SetDataEvent, pEvent, pHandle); 233 | } 234 | 235 | char JLINKARM_Step(void) { 236 | return JLinkDLL_CALLPTR(P_JLINKARM_Step); 237 | } 238 | 239 | char JLINKARM_StepComposite(void) { 240 | return JLinkDLL_CALLPTR(P_JLINKARM_StepComposite); 241 | } 242 | 243 | int JLINKARM_WaitForHalt(int TimeOut) { 244 | return JLinkDLL_CALLPTR(P_JLINKARM_WaitForHalt, TimeOut); 245 | } 246 | 247 | void JLINKARM_WriteICEReg(int RegIndex, uint32_t Value, int AllowDelay) { 248 | JLinkDLL_CALLPTR(P_JLINKARM_WriteICEReg, RegIndex, Value, AllowDelay); 249 | } 250 | 251 | char JLINKARM_WriteReg(ARM_REG RegIndex, uint32_t Data) { 252 | return JLinkDLL_CALLPTR(P_JLINKARM_WriteReg, RegIndex, Data); 253 | } 254 | 255 | int JLINKARM_WriteRegs(const uint32_t *paRegIndex, const uint32_t *paData, uint8_t *paStatus, uint32_t NumRegs) { 256 | return JLinkDLL_CALLPTR(P_JLINKARM_WriteRegs, paRegIndex, paData, paStatus, NumRegs); 257 | } 258 | 259 | int JLINKARM_WriteVectorCatch(uint32_t Value) { 260 | return JLinkDLL_CALLPTR(P_JLINKARM_WriteVectorCatch, Value); 261 | } 262 | 263 | int JLINKARM_ReadDCC(uint32_t *pData, uint32_t NumItems, int TimeOut) { 264 | return JLinkDLL_CALLPTR(P_JLINKARM_ReadDCC, pData, NumItems, TimeOut); 265 | } 266 | 267 | void JLINKARM_ReadDCCFast(uint32_t *pData, uint32_t NumItems) { 268 | JLinkDLL_CALLPTR(P_JLINKARM_ReadDCCFast, pData, NumItems); 269 | } 270 | 271 | int JLINKARM_WaitDCCRead(int TimeOut) { 272 | return JLinkDLL_CALLPTR(P_JLINKARM_WaitDCCRead, TimeOut); 273 | } 274 | 275 | int JLINKARM_WriteDCC(const uint32_t *pData, uint32_t NumItems, int TimeOut) { 276 | return JLinkDLL_CALLPTR(P_JLINKARM_WriteDCC, pData, NumItems, TimeOut); 277 | } 278 | 279 | void JLINKARM_WriteDCCFast(const uint32_t *pData, uint32_t NumItems) { 280 | JLinkDLL_CALLPTR(P_JLINKARM_WriteDCCFast, pData, NumItems); 281 | } 282 | //PYTHON CHECK POINT 283 | -------------------------------------------------------------------------------- /JLink/General/JLink_Debugging.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file JLink_Debugging.h 3 | * @author yao 4 | */ 5 | 6 | #ifndef JLINKDLL_JLINK_DEBUGGING_H 7 | #define JLINKDLL_JLINK_DEBUGGING_H 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | /** 17 | * This function clears a data event set via JLINKARM_SetDataEvent(). 18 | * @param Handle Handle of watchpoint to be removed. It is also possible to use the 19 | * JLINKARM_EVENT_HANDLE_ALL handle in order to remove all breakpoints, 20 | * which were set via JLINKARM_SetDataEvent(). 21 | * @see JLINKARM_SetDataEvent 22 | * @retval 0 Ok 23 | * @retval 1 Error 24 | */ 25 | int JLINKARM_ClrDataEvent(uint32_t Handle); 26 | 27 | 28 | /** 29 | * This function removes a watchpoint set by JLINKARM_SetWP(). 30 | * @note This function is deprecated! Use {@link JLINKARM_ClrDataEvent} instead. 31 | * @see JLINKARM_SetWP 32 | * @param WPHandle Handle of watchpoint to be removed. It is also possible to use the 33 | * JLINKARM_WP_HANDLE_ALL handle in order to remove all breakpoints, 34 | * which were set via JLINKARM_SetWP(). 35 | * @retval 0 if watchpoint has been cleared 36 | * @retval -1 Error 37 | */ 38 | int JLINKARM_ClrWP(int WPHandle); 39 | 40 | /** 41 | * This function removes a breakpoint set by JLINKARM_SetBP(). 42 | * @details 43 | * This function writes directly to the ICE-breaker registers. This function can not be used 44 | * together with JLINKARM_ClrBPEx(). JLINKARM_ClrBPEx() may overwrite the ICE-breaker 45 | * registers. 46 | * @code 47 | * JLINKARM_SetBP(1, Addr); 48 | * JLINKARM_ClrBP(1); 49 | * @endcode 50 | * 51 | * @see JLINKARM_SetBP 52 | * @see JLINKARM_ClrBPEx 53 | * @param BPIndex Number of breakpoint. Either 0 or 1. 54 | */ 55 | void JLINKARM_ClrBP(uint32_t BPIndex); 56 | 57 | /** 58 | * This function removes a breakpoint set by JLINKARM_SetBPEx() 59 | * @details This function does not write directly to the ICE-breaker registers. The 60 | * ICE-breaker registers will be written when starting the core. This function 61 | * can not be used together with JLINKARM_ClrBP(). JLINKARM_ClrBP() may overwrite 62 | * the ICE-breaker registers. 63 | * @code 64 | * int BPHandle; 65 | * BPHandle = JLINKARM_SetBPEx(Addr, JLINKARM_BP_TYPE_THUMB); 66 | * JLINKARM_ClrBPEx(BPHandle); 67 | * @endcode 68 | * @param BPHandle Handle of breakpoint to be removed. It is also possible to use the 69 | * JLINKARM_BP_HANDLE_ALL handle in order to remove all breakpoints, 70 | * which were set via JLINKARM_SetBPEx(). 71 | * 72 | * @see JLINKARM_ClrBP 73 | * @see JLINKARM_SetBPEx 74 | * 75 | * @retval 0 if breakpoint has been cleared 76 | * @retval -1 Error 77 | */ 78 | int JLINKARM_ClrBPEx(int BPHandle); 79 | 80 | /** 81 | * Extended version of {@link JLINKARM_SetWP}. Allows specifying data events which halt the CPU, 82 | * trigger SWO output, trigger trace output. 83 | * @param pEvent 84 | * @param pHandle 85 | * @return 86 | */ 87 | int JLINKARM_SetDataEvent(JLINKARM_DATA_EVENT *pEvent, uint32_t *pHandle); 88 | 89 | /** 90 | * This function returns the CPU core identified by J-Link after {@link JLINKARM_Connect} has been 91 | * called. This function may only be used after {@link JLINKARM_Connect} has succeeded. 92 | * @retval 0 J-Link is not connected to a target 93 | * @retval >0 Target connected 94 | */ 95 | uint32_t JLINKARM_CORE_GetFound(void); 96 | 97 | /** 98 | * This function allows the use of software breakpoints. 99 | * @param Enable Enables (=1) or disables (=0) the software breakpoint feature 100 | */ 101 | void JLINKARM_EnableSoftBPs(char Enable); 102 | 103 | /** 104 | * This function tries to find a breakpoint at the given address 105 | * @param Addr Address to be searched for 106 | * @return Handle of breakpoint at given address or zero if no matching breakpoint exist 107 | */ 108 | int JLINKARM_FindBP(uint32_t Addr); 109 | 110 | /** 111 | * Returns the breakpoint type. 112 | * @param BPHandle Handle of breakpoint. 113 | * @retval -1 Error 114 | * @return Bit 0 - 30 Reserved; 115 | * Bit 31 0 = Hardware breakpoint; 116 | * 1 = Software breakpoint 117 | */ 118 | uint32_t JLINKARM_GetBPInfo(int BPHandle); 119 | 120 | /** 121 | * This function retrieves the number of currently active breakpoints. These are breakpoints 122 | * which have been set using {@link JLINKARM_SetBPEx} and have not been cleared (using {@link JLINKARM_ClrBPEx}). 123 | * @return Number of breakpoints. 124 | */ 125 | uint32_t JLINKARM_GetNumBPs(void); 126 | 127 | /** 128 | * Gets information about a breakpoint, such as breakpoint handle, address and implementation type. 129 | * @param iBP Index of breakpoint of which information is requested. If the index 130 | * is unknown, use -1 and fill in the handle member of the JLINKARM_BP_INFO structure instead. 131 | * @param pInfo Pointer to structure of type JLINKARM_BP_INFO. 132 | * @return Number of breakpoints which are currently in the DLL internal breakpoint list. 133 | */ 134 | int JLINKARM_GetBPInfoEx(int iBP, JLINKARM_BP_INFO *pInfo); 135 | 136 | /** 137 | * This function retrieves the number of watchpoints. 138 | * @return unsigned JLINKARM_GetNumWPs(void); 139 | */ 140 | uint32_t JLINKARM_GetNumWPs(void); 141 | 142 | /** 143 | * This function retrieves the total number of available breakpoints on specified breakpoint units. 144 | * @see JLINKARM_BP_TYPE 145 | * @param Type Specifies the breakpoint units to be queried. (Described below) 146 | * @return Total number of available hardware breakpoints. 147 | */ 148 | int JLINKARM_GetNumBPUnits(JLINKARM_BP_TYPE Type); 149 | 150 | /** 151 | * This function retrieves the number of available watchpoints. 152 | * @return Total number of available watchpoints 153 | */ 154 | int JLINKARM_GetNumWPUnits(void); 155 | 156 | /** 157 | * Stores a list of indices for all registers that are supported by the connected CPU into a given 158 | * buffer. These indices can then be used to read the register content via {@link JLINKARM_ReadRegs}. 159 | * @note This function may only be called after a successful call to {@link JLINKARM_Connect}. 160 | * @code 161 | * uint32_t aRegIndex[JLINKARM_MAX_NUM_CPU_REGS]; 162 | * uint32_t aRegData[JLINKARM_MAX_NUM_CPU_REGS]; 163 | * int NumRegs; 164 | * int i; 165 | * NumRegs = JLINKARM_GetRegisterList(aRegIndex, JLINKARM_MAX_NUM_CPU_REGS); 166 | * JLINKARM_ReadRegs(aRegIndex, aRegData, NULL, NumRegs); 167 | * for (i = 0; i < NumRegs; i++) { 168 | * printf("%s = %.8X\n", JLINKARM_GetRegisterName(aRegIndex[i]), aRegData[i]); 169 | * } 170 | * @endcode 171 | * @param paList Pointer to buffer of uint32_t items which is used to store the register indices. 172 | * @param MaxNumItems Maximum number of indices that can be stored in paList . 173 | * @retval >=0 Number of indices that have been stored in paList . 174 | */ 175 | int JLINKARM_GetRegisterList(uint32_t *paList, int MaxNumItems); 176 | 177 | /** 178 | * The function retrieves and returns the name of the ARM CPU register for the given index. 179 | * @param RegIndex 180 | * @return Name of the register 181 | */ 182 | const char *JLINKARM_GetRegisterName(uint32_t RegIndex); 183 | 184 | 185 | /** 186 | * Gets information about a watchpoint and returns the number of watchpoints which are 187 | * currently in the DLL internal watchpoint list. 188 | * @param iWP Index of the watchpoint. 189 | * @param pInfo Pointer to structre of type {@link JLINKARM_WP_INFO}. 190 | * @return Number of watchpoints which are currently in the DLL internal watchpoint list. 191 | */ 192 | int JLINKARM_GetWPInfoEx(int iWP, JLINKARM_WP_INFO *pInfo); 193 | 194 | /** 195 | * @see JLINKARM_Go 196 | * Allows the DLL so simulate up to NumInsts instructions. Can be useful for source level 197 | * debugging when perfoming a Step-over over small functions. 198 | * @note If any breakpoint is hit during simulation, the DLL stops simulating instructions. 199 | */ 200 | void JLINKARM_GoAllowSim(uint32_t NumInsts); 201 | 202 | /** 203 | * Read code memory. 204 | * 205 | * Not used by most applications; it has the advantage that it uses a cache and reads ahead. 206 | * Primary purpose is to accelerate applications such as IAR and a GDB-server which read 207 | * small chunks of data for a disassembly window. 208 | * @param Addr Address to start reading 209 | * @param NumBytes Number of bytes that should be read. 210 | * @param pData Pointer to a buffer where the data should be stored. Make sure that it 211 | * points to valid memory and that there is sufficient space for the entire 212 | * number of data items. 213 | * @retval >=0 Number of items read succesfully 214 | * @retval <0 Error 215 | */ 216 | int JLINKARM_ReadCodeMem(uint32_t Addr, uint32_t NumBytes, void *pData); 217 | 218 | /** 219 | * The function reads an ARM ICE register. 220 | * @code 221 | * int v0; 222 | * JLINKARM_WriteICEReg(0x08, 0x12345678, 1); 223 | * v0 = JLINKARM_ReadICEReg(0x08); 224 | * if (v0 != 0x12345678) { 225 | * sprintf(ac, "ICE communication failed: Expected 0x12345678 in ICE registers 0x8. Found %8X", v0); 226 | * } else { 227 | * printf("ICE communication o.k.\n"); 228 | * } 229 | * @endcode 230 | * @param RegIndex Register to read. Either 0 or 1. 231 | * @return Content of the queried ICE register. 232 | */ 233 | uint32_t JLINKARM_ReadICEReg(int RegIndex); 234 | 235 | /** 236 | * The function reads and returns the value of the specified ARM CPU register. 237 | * @param RegIndex Register to read. 238 | * @return Content of the queried register. 239 | */ 240 | uint32_t JLINKARM_ReadReg(ARM_REG RegIndex); 241 | 242 | /** 243 | * Reads multiple CPU registers. Especially useful if the debugger needs the values of a specific 244 | * set of registers in a defined order in an array. 245 | * The register list passed to this function does not need to have continuous register indexes. 246 | * @param paRegIndex Pointer to array of register indexes. 247 | * @param paData Pointer to array of memory areas to store the register values 248 | * @param paStatus Pointer to array of status bytes. May be NULL. 249 | * 250 | * - 0 if corresponding register has been successfully read. 251 | * 252 | * - -1 if register could not be read. 253 | * @param NumRegs Number of registers to read 254 | * @retval 0 O.K. 255 | * @retval <0 Error 256 | */ 257 | int JLINKARM_ReadRegs(const uint32_t *paRegIndex, uint32_t *paData, uint8_t *paStatus, uint32_t NumRegs); 258 | 259 | /** 260 | * Currently only used internally by the J-Link GlueDLL for Renesas HEW and IAR EWRX. 261 | * Read terminal data from J-Link. 262 | * @note Currently only implemented for Renesas RX series which implement virtual terminal 263 | * via E2C / C2E functionality and use the Renesas library. 264 | * @retval >=0 Number of bytes read 265 | * @retval <0 Error 266 | */ 267 | int JLINKARM_ReadTerminal(uint8_t *pBuffer, uint32_t BufferSize); 268 | 269 | /** 270 | * This function tries to simulate the specified instruction. 271 | * @param Inst Instruction to simulate. 272 | * @retval 0 if instruction has been simulated 273 | * @retval 1 if instruction could not be simulated 274 | */ 275 | char JLINKARM_SimulateInstruction(uint32_t Inst); 276 | 277 | /** 278 | * This function inserts a hardware breakpoint with index BPIndex at address Addr . 279 | * @note This function writes directly to the ICE-breaker registers. This function can not be 280 | * used together with {@link JLINKARM_SetBPEx}. {@link JLINKARM_SetBPEx} may overwrite the 281 | * ICE-breaker registers. 282 | * @note The use of {@note JLINKARM_SetBPEx} is recommended instead 283 | * @code 284 | * uint32_t Addr; 285 | * Addr = 0x00200000; 286 | * JLINKARM_SetBP(1, Addr); 287 | * @endcode 288 | * @param BPIndex Number of breakpoint. Either 0 or 1. 289 | * @param Addr Address 290 | */ 291 | void JLINKARM_SetBP(uint32_t BPIndex, uint32_t Addr); 292 | 293 | /** 294 | * This function sets a breakpoint of a specific type at a specified address. If the breakpoint 295 | * needs to be set in a specific depends on the CPU which is used. Which breakpoint modes 296 | * are available also depends on the CPU that is used. For more information about which 297 | * breakpoint modes are available for which CPU, please refer to the breakpoint mode table 298 | * below. This function can set all types of breakpoints: 299 | * 300 | * - Hardware 301 | * 302 | * - Software (in RAM) 303 | * 304 | * - Software (in Flash memory). 305 | * 306 | * Various implementation flags allow control of the type of breakpoint to set 307 | * @param Addr Address where the breakpoint shall be set. This address can be in RAM, flash or ROM. 308 | * @param TypeFlags Specifies the desired breakpoint type. (Described below) 309 | * @retval >0 O.K., handle of new breakpoint 310 | * @retval 0 On Error 311 | */ 312 | int JLINKARM_SetBPEx(uint32_t Addr, uint32_t TypeFlags); 313 | 314 | /** 315 | * This function executes a single step on the target. The instruction is overstepped even if it is breakpointed. 316 | * @retval 0 O.K. 317 | * @retval 1 Error 318 | */ 319 | char JLINKARM_Step(void); 320 | 321 | /** 322 | * This function executes a single step on the target in THUMB mode. 323 | * @retval 0 O.K. 324 | * @retval 1 Error 325 | */ 326 | char JLINKARM_StepComposite(void); 327 | 328 | /** 329 | * Waits for CPU to be halted 330 | * Returns on: 331 | * 332 | * - CPU halted 333 | * 334 | * - Error while retrieving CPU state 335 | * 336 | * - Timeout reached 337 | * 338 | * @param TimeOut Number of milliseconds to wait for halt before a timeout occurs. 339 | * @retval 1 CPU halted 340 | * @retval 0 CPU not halted (timeout reached) 341 | * @retval <0 Error 342 | */ 343 | int JLINKARM_WaitForHalt(int TimeOut); 344 | 345 | /** 346 | * This function writes in the selected ICE Breaker register. 347 | * @code 348 | * int v0; 349 | * JLINKARM_WriteICEReg(0x08, 0x12345678, 1); 350 | * v0 = JLINKARM_ReadICEReg(0x08); 351 | * if (v0 != 0x12345678) { 352 | * sprintf(ac, "ICE communication failed: Expected 0x12345678 in ICE registers 0x8. Found %8X", v0); 353 | * } else { 354 | * printf("ICE communication o.k.\n"); 355 | * } 356 | * @endcode 357 | * @param RegIndex Register to write. 358 | * @param Value Data that should be written to the register. 359 | * @param AllowDelay 0 for not allowing a delay. Data will be written directly to the target. 360 | */ 361 | void JLINKARM_WriteICEReg(int RegIndex, uint32_t Value, int AllowDelay); 362 | 363 | /** 364 | * Writes into an ARM register. The data is not immediately written into the register. Instead 365 | * we first write into a cache and the data is transferred to the register on CPU start. 366 | * For a list of different register sets, please refer to {@link JLINKARM_ReadReg}. 367 | * @param RegIndex Register to write. (See description of {@link JLINKARM_ReadReg} for detailed information of the {@link ARM_REG} type) 368 | * @param Data Data to write. 369 | * @retval 0 if register has been written 370 | * @retval 1 on error 371 | */ 372 | char JLINKARM_WriteReg(ARM_REG RegIndex, uint32_t Data); 373 | 374 | /** 375 | * Writes multiple CPU registers. Especially useful if the debugger gives the values of a specific 376 | * set of registers in a defined order in an array. 377 | * @param paRegIndex Pointer to array of registers (by index) to write. 378 | * @param paData Pointer to array of data to write. 379 | * @param paStatus Pointer to status array. May be NULL. 380 | * 0 if corresponding register has been successfully written. 381 | * -1 if register could not be written. 382 | * @param NumRegs Number of registers to write 383 | * @retval 0 384 | */ 385 | int JLINKARM_WriteRegs(const uint32_t *paRegIndex, const uint32_t *paData, uint8_t *paStatus, uint32_t NumRegs); 386 | 387 | /** 388 | * This function allows to set the vector catch bits of the processor. If the CPU jumps to a 389 | * vector on which vector catch is active/set, the CPU normally enters debug state or takes 390 | * a debug exception. For example, the vector catch for reset vector is usually set by the 391 | * debugger before the CPU is reset, in order to halt it immediately after the reset. (If the 392 | * CPU supports vector catch for the reset vector) 393 | * @param Value Bitmask which determines which vector catch bits shall be written. 394 | * (See bit description for different CPU cores below) 395 | * @retval >=0 O.K. 396 | * @retval <0 On error. 397 | */ 398 | int JLINKARM_WriteVectorCatch(uint32_t Value); 399 | 400 | /** 401 | * Read code memory. 402 | * Reads data items (32-bits) from ARM core via DCC. 403 | * @param pData Pointer to a buffer where the data should be stored. Make sure that it 404 | * points to valid memory and that there is sufficient space for the entire 405 | * number of data items. 406 | * @param NumItems Number of 32-bit data items that should be read. 407 | * @param TimeOut Timeout in milliseconds for a single data item. 408 | * @return Number of 32-bit data items read. 409 | */ 410 | int JLINKARM_ReadDCC(uint32_t *pData, uint32_t NumItems, int TimeOut); 411 | 412 | /** 413 | * Read code memory. 414 | * Reads data items (32-bits) from ARM core via DCC without checking if the requested data is available. 415 | * @param pData Pointer to a buffer where the data should be stored. Make sure that it 416 | * points to valid memory and that there is sufficient space for the entire 417 | * number of data items. 418 | * @param NumItems Number of 32-bit data items that should be read. 419 | */ 420 | void JLINKARM_ReadDCCFast(uint32_t *pData, uint32_t NumItems); 421 | 422 | /** 423 | * This function checks if new DCC data is available. If no data item is available after the 424 | * specified amount of time, a timeout error occurs. 425 | * @param TimeOut Number of milliseconds to wait for data before a timeout occurs. 426 | * @retval 0 if a timeout occurred 427 | * @retval 1 if new DCC data is available 428 | */ 429 | int JLINKARM_WaitDCCRead(int TimeOut); 430 | 431 | /** 432 | * Writes data items (32-bits) to ARM core via DCC. 433 | * @param pData Pointer to buffer containing data to be written. 434 | * @param NumItems Number of 32-bit data items that should be written. 435 | * @param TimeOut Timeout in milliseconds for a single data item. 436 | * @return Number of 32-bit data items written. 437 | */ 438 | int JLINKARM_WriteDCC(const uint32_t *pData, uint32_t NumItems, int TimeOut); 439 | 440 | /** 441 | * Writes data items (32-bits) to ARM core via DCC without checking if the target is ready 442 | * to accept the data. 443 | * @param pData Pointer to buffer containing data to be written. 444 | * @param NumItems Number of 32-bit data items that should be written. 445 | */ 446 | void JLINKARM_WriteDCCFast(const uint32_t *pData, uint32_t NumItems); 447 | 448 | 449 | #ifdef __cplusplus 450 | } 451 | #endif 452 | 453 | #endif //JLINKDLL_JLINK_DEBUGGING_H 454 | -------------------------------------------------------------------------------- /JLink/General/JLink_DeviceSpecific.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yaoji on 2022/3/18. 3 | // 4 | 5 | #include "JLink_DeviceSpecific.h" 6 | #include "JLink/JLink_Init.h" 7 | 8 | static int (*P_JLINKARM_DEVICE_GetInfo)(int DeviceIndex, JLINKARM_DEVICE_INFO *pDeviceInfo); 9 | 10 | int JLINK_GERENAL_DEVICE_SPECIFIC_Init() { 11 | P_JLINKARM_DEVICE_GetInfo = JLinkDLL_getSym("JLINKARM_DEVICE_GetInfo"); 12 | return P_JLINKARM_DEVICE_GetInfo != NULL; 13 | } 14 | //PYTHON CHECK POINT 15 | int JLINKARM_DEVICE_GetInfo(int DeviceIndex, JLINKARM_DEVICE_INFO *pDeviceInfo) { 16 | return JLinkDLL_CALLPTR(P_JLINKARM_DEVICE_GetInfo, DeviceIndex, pDeviceInfo); 17 | } 18 | //PYTHON CHECK POINT -------------------------------------------------------------------------------- /JLink/General/JLink_DeviceSpecific.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file JLink_DeviceSpecific.h 3 | * @author yao 4 | */ 5 | 6 | #ifndef JLINKDLL_JLINK_DEVICESPECIFIC_H 7 | #define JLINKDLL_JLINK_DEVICESPECIFIC_H 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | 17 | /** 18 | * This function can be used to acquire information about which devices are supported by 19 | * the J-Link DLL. Moreover, more detailed information for a specific device can be acquired 20 | * (CoreId, Flash addr, ...). 21 | * @param DeviceIndex Index of device for which information is acquired. 22 | * @param pDeviceInfo Pointer to structure variable which is used to hold information for the 23 | * specified device. 24 | * @return Number of devices which are supported by the J-Link DLL. 25 | */ 26 | int JLINKARM_DEVICE_GetInfo(int DeviceIndex, JLINKARM_DEVICE_INFO *pDeviceInfo); 27 | 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif //JLINKDLL_JLINK_DEVICESPECIFIC_H 34 | -------------------------------------------------------------------------------- /JLink/General/JLink_FileIO.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yaoji on 2022/3/18. 3 | // 4 | 5 | #include "JLink_FileIO.h" 6 | #include "JLink/JLink_Init.h" 7 | 8 | static int (*P_JLINKARM_EMU_FILE_Delete)(const char *sFile); 9 | static int (*P_JLINKARM_EMU_FILE_GetSize)(const char *sFile); 10 | static int (*P_JLINKARM_EMU_FILE_Read)(const char *sFile, uint8_t *pData, uint32_t Offset, uint32_t NumBytes); 11 | static int (*P_JLINKARM_EMU_FILE_Write)(const char *sFile, const uint8_t *pData, uint32_t Offset, uint32_t NumBytes); 12 | 13 | int JLINK_GERENAL_FILE_IO_Init() { 14 | P_JLINKARM_EMU_FILE_Delete = JLinkDLL_getSym("JLINKARM_EMU_FILE_Delete"); 15 | if (P_JLINKARM_EMU_FILE_Delete == NULL) return 0; 16 | P_JLINKARM_EMU_FILE_GetSize = JLinkDLL_getSym("JLINKARM_EMU_FILE_GetSize"); 17 | if (P_JLINKARM_EMU_FILE_GetSize == NULL) return 0; 18 | P_JLINKARM_EMU_FILE_Read = JLinkDLL_getSym("JLINKARM_EMU_FILE_Read"); 19 | if (P_JLINKARM_EMU_FILE_Read == NULL) return 0; 20 | P_JLINKARM_EMU_FILE_Write = JLinkDLL_getSym("JLINKARM_EMU_FILE_Write"); 21 | if (P_JLINKARM_EMU_FILE_Write == NULL) return 0; 22 | return 1; 23 | } 24 | //PYTHON CHECK POINT 25 | int JLINKARM_EMU_FILE_Delete(const char *sFile) { 26 | return JLinkDLL_CALLPTR(P_JLINKARM_EMU_FILE_Delete, sFile); 27 | } 28 | 29 | int JLINKARM_EMU_FILE_GetSize(const char *sFile) { 30 | return JLinkDLL_CALLPTR(P_JLINKARM_EMU_FILE_GetSize, sFile); 31 | } 32 | 33 | int JLINKARM_EMU_FILE_Read(const char *sFile, uint8_t *pData, uint32_t Offset, uint32_t NumBytes) { 34 | return JLinkDLL_CALLPTR(P_JLINKARM_EMU_FILE_Read, sFile, pData, Offset, NumBytes); 35 | } 36 | 37 | int JLINKARM_EMU_FILE_Write(const char *sFile, const uint8_t *pData, uint32_t Offset, uint32_t NumBytes) { 38 | return JLinkDLL_CALLPTR(P_JLINKARM_EMU_FILE_Write, sFile, pData, Offset, NumBytes); 39 | } 40 | //PYTHON CHECK POINT -------------------------------------------------------------------------------- /JLink/General/JLink_FileIO.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file JLink_FileIO.h 3 | * @author yao 4 | */ 5 | 6 | #ifndef JLINKDLL_JLINK_FILEIO_H 7 | #define JLINKDLL_JLINK_FILEIO_H 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | /** 16 | * On emulators which support file I/O this function deletes a specific file. 17 | * Check if a specific emulator supports file I/O by calling {@link JLINKARM_GetEmuCaps}. 18 | * Currently, only Flasher models support file I/O. 19 | * @retval >=0 Ok 20 | * @retval <0 Error 21 | */ 22 | int JLINKARM_EMU_FILE_Delete(const char *sFile); 23 | 24 | /** 25 | * On emulators which support file I/O this function gets the size of a specific file. 26 | * Check if a specific emulator supports file I/O by calling {@link JLINKARM_GetEmuCaps}. 27 | * Currently, only Flasher models support file I/O. 28 | * @retval >=0 Size of specified file 29 | * @retval <0 Error 30 | */ 31 | int JLINKARM_EMU_FILE_GetSize(const char *sFile); 32 | 33 | /** 34 | * On emulators which support file I/O this function reads a specific file. 35 | * Check if a specific emulator supports file I/O by calling {@link JLINKARM_GetEmuCaps}. 36 | * Currently, only Flasher models support file I/O. 37 | * @retval >=0 Number of bytes read succesfully. 38 | * @retval <0 Error 39 | */ 40 | int JLINKARM_EMU_FILE_Read(const char *sFile, uint8_t *pData, uint32_t Offset, uint32_t NumBytes); 41 | 42 | /** 43 | * On emulators which support file I/O this function writes a specific file. 44 | * Check if a specific emulator supports file I/O by calling {@link JLINKARM_GetEmuCaps}. 45 | * Currently, only Flasher models support file I/O. 46 | * @return Number of bytes written succesfully. 47 | * @retval <0 Error 48 | */ 49 | int JLINKARM_EMU_FILE_Write(const char *sFile, const uint8_t *pData, uint32_t Offset, uint32_t NumBytes); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif //JLINKDLL_JLINK_FILEIO_H 56 | -------------------------------------------------------------------------------- /JLink/General/JLink_General.c: -------------------------------------------------------------------------------- 1 | 2 | #define INIT_MODULE(MODULE) \ 3 | int JLINK_##MODULE##_Init(); \ 4 | if (!JLINK_##MODULE##_Init()) return 0; 5 | 6 | int JLINK_General_Init() { 7 | INIT_MODULE(GERENAL_BASE) 8 | INIT_MODULE(GERENAL_SystemControl) 9 | INIT_MODULE(GERENAL_FILE_IO) 10 | INIT_MODULE(GERENAL_CONFIGURATION) 11 | INIT_MODULE(GERENAL_DEVICE_SPECIFIC) 12 | INIT_MODULE(GERENAL_RESET) 13 | INIT_MODULE(GERENAL_DEBUGGING) 14 | INIT_MODULE(GERENAL_MEM) 15 | return 1; 16 | } -------------------------------------------------------------------------------- /JLink/General/JLink_Memory.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yaoji on 2022/3/18. 3 | // 4 | 5 | #include "JLink_Memory.h" 6 | #include 7 | 8 | static int (*P_JLINK_GetMemZones)(JLINK_MEM_ZONE_INFO *paZoneInfo, int MaxNumZones); 9 | static int (*P_JLINKARM_ReadMem)(uint32_t Addr, uint32_t NumBytes, void *pData); 10 | static int (*P_JLINKARM_ReadMemEx)(uint32_t Addr, uint32_t NumBytes, void *pData, uint32_t AccessWidth); 11 | static int (*P_JLINKARM_ReadMemIndirect)(uint32_t Addr, uint32_t NumBytes, void *pData); 12 | static int (*P_JLINKARM_ReadMemHW)(uint32_t Addr, uint32_t NumBytes, void *pData); 13 | static int (*P_JLINKARM_ReadMemU8)(uint32_t Addr, uint32_t NumItems, uint8_t *pData, uint8_t *pStatus); 14 | static int (*P_JLINKARM_ReadMemU16)(uint32_t Addr, uint32_t NumItems, uint16_t *pData, uint8_t *pStatus); 15 | static int (*P_JLINKARM_ReadMemU32)(uint32_t Addr, uint32_t NumItems, uint32_t *pData, uint8_t *pStatus); 16 | static int (*P_JLINKARM_ReadMemU64)(uint32_t Addr, uint32_t NumItems, uint64_t *pData, uint8_t *pStatus); 17 | static int (*P_JLINK_ReadMemZonedEx)(uint32_t Addr, uint32_t NumBytes, void *pData, uint32_t AccessWidth, 18 | const char *sZone); 19 | static int (*P_JLINKARM_WriteMem)(uint32_t Addr, uint32_t Count, const void *pData); 20 | static int (*P_JLINKARM_WriteMemDelayed)(uint32_t Addr, uint32_t Count, const void *pData); 21 | static int (*P_JLINKARM_WriteMemEx)(uint32_t Addr, uint32_t NumBytes, const void *p, uint32_t AccessWidth); 22 | static int (*P_JLINK_WriteMemZonedEx)(uint32_t Addr, uint32_t NumBytes, const void *p, uint32_t AccessWidth, 23 | const char *sZone); 24 | static int (*P_JLINKARM_WriteU8)(uint32_t Addr, uint8_t Data); 25 | static int (*P_JLINKARM_WriteU16)(uint32_t Addr, uint16_t Data); 26 | static int (*P_JLINKARM_WriteU32)(uint32_t Addr, uint32_t Data); 27 | static int (*P_JLINKARM_WriteU64)(uint32_t Addr, uint64_t Data); 28 | 29 | int JLINK_GERENAL_MEM_Init() { 30 | P_JLINK_GetMemZones = JLinkDLL_getSym("JLINK_GetMemZones"); 31 | if (P_JLINK_GetMemZones == NULL) return 0; 32 | P_JLINKARM_ReadMem = JLinkDLL_getSym("JLINKARM_ReadMem"); 33 | if (P_JLINKARM_ReadMem == NULL) return 0; 34 | P_JLINKARM_ReadMemEx = JLinkDLL_getSym("JLINKARM_ReadMemEx"); 35 | if (P_JLINKARM_ReadMemEx == NULL) return 0; 36 | P_JLINKARM_ReadMemIndirect = JLinkDLL_getSym("JLINKARM_ReadMemIndirect"); 37 | if (P_JLINKARM_ReadMemIndirect == NULL) return 0; 38 | P_JLINKARM_ReadMemHW = JLinkDLL_getSym("JLINKARM_ReadMemHW"); 39 | if (P_JLINKARM_ReadMemHW == NULL) return 0; 40 | P_JLINKARM_ReadMemU8 = JLinkDLL_getSym("JLINKARM_ReadMemU8"); 41 | if (P_JLINKARM_ReadMemU8 == NULL) return 0; 42 | P_JLINKARM_ReadMemU16 = JLinkDLL_getSym("JLINKARM_ReadMemU16"); 43 | if (P_JLINKARM_ReadMemU16 == NULL) return 0; 44 | P_JLINKARM_ReadMemU32 = JLinkDLL_getSym("JLINKARM_ReadMemU32"); 45 | if (P_JLINKARM_ReadMemU32 == NULL) return 0; 46 | P_JLINKARM_ReadMemU64 = JLinkDLL_getSym("JLINKARM_ReadMemU64"); 47 | if (P_JLINKARM_ReadMemU64 == NULL) return 0; 48 | P_JLINK_ReadMemZonedEx = JLinkDLL_getSym("JLINK_ReadMemZonedEx"); 49 | if (P_JLINK_ReadMemZonedEx == NULL) return 0; 50 | P_JLINKARM_WriteMem = JLinkDLL_getSym("JLINKARM_WriteMem"); 51 | if (P_JLINKARM_WriteMem == NULL) return 0; 52 | P_JLINKARM_WriteMemDelayed = JLinkDLL_getSym("JLINKARM_WriteMemDelayed"); 53 | if (P_JLINKARM_WriteMemDelayed == NULL) return 0; 54 | P_JLINKARM_WriteMemEx = JLinkDLL_getSym("JLINKARM_WriteMemEx"); 55 | if (P_JLINKARM_WriteMemEx == NULL) return 0; 56 | P_JLINK_WriteMemZonedEx = JLinkDLL_getSym("JLINK_WriteMemZonedEx"); 57 | if (P_JLINK_WriteMemZonedEx == NULL) return 0; 58 | P_JLINKARM_WriteU8 = JLinkDLL_getSym("JLINKARM_WriteU8"); 59 | if (P_JLINKARM_WriteU8 == NULL) return 0; 60 | P_JLINKARM_WriteU16 = JLinkDLL_getSym("JLINKARM_WriteU16"); 61 | if (P_JLINKARM_WriteU16 == NULL) return 0; 62 | P_JLINKARM_WriteU32 = JLinkDLL_getSym("JLINKARM_WriteU32"); 63 | if (P_JLINKARM_WriteU32 == NULL) return 0; 64 | P_JLINKARM_WriteU64 = JLinkDLL_getSym("JLINKARM_WriteU64"); 65 | if (P_JLINKARM_WriteU64 == NULL) return 0; 66 | return 1; 67 | } 68 | //PYTHON CHECK POINT 69 | int JLINK_GetMemZones(JLINK_MEM_ZONE_INFO *paZoneInfo, int MaxNumZones) { 70 | return JLinkDLL_CALLPTR(P_JLINK_GetMemZones, paZoneInfo, MaxNumZones); 71 | } 72 | 73 | int JLINKARM_ReadMem(uint32_t Addr, uint32_t NumBytes, void *pData) { 74 | return JLinkDLL_CALLPTR(P_JLINKARM_ReadMem, Addr, NumBytes, pData); 75 | } 76 | 77 | int JLINKARM_ReadMemEx(uint32_t Addr, uint32_t NumBytes, void *pData, uint32_t AccessWidth) { 78 | return JLinkDLL_CALLPTR(P_JLINKARM_ReadMemEx, Addr, NumBytes, pData, AccessWidth); 79 | } 80 | 81 | int JLINKARM_ReadMemIndirect(uint32_t Addr, uint32_t NumBytes, void *pData) { 82 | return JLinkDLL_CALLPTR(P_JLINKARM_ReadMemIndirect, Addr, NumBytes, pData); 83 | } 84 | 85 | int JLINKARM_ReadMemHW(uint32_t Addr, uint32_t NumBytes, void *pData) { 86 | return JLinkDLL_CALLPTR(P_JLINKARM_ReadMemHW, Addr, NumBytes, pData); 87 | } 88 | 89 | int JLINKARM_ReadMemU8(uint32_t Addr, uint32_t NumItems, uint8_t *pData, uint8_t *pStatus) { 90 | return JLinkDLL_CALLPTR(P_JLINKARM_ReadMemU8, Addr, NumItems, pData, pStatus); 91 | } 92 | 93 | int JLINKARM_ReadMemU16(uint32_t Addr, uint32_t NumItems, uint16_t *pData, uint8_t *pStatus) { 94 | return JLinkDLL_CALLPTR(P_JLINKARM_ReadMemU16, Addr, NumItems, pData, pStatus); 95 | } 96 | 97 | int JLINKARM_ReadMemU32(uint32_t Addr, uint32_t NumItems, uint32_t *pData, uint8_t *pStatus) { 98 | return JLinkDLL_CALLPTR(P_JLINKARM_ReadMemU32, Addr, NumItems, pData, pStatus); 99 | } 100 | 101 | int JLINKARM_ReadMemU64(uint32_t Addr, uint32_t NumItems, uint64_t *pData, uint8_t *pStatus) { 102 | return JLinkDLL_CALLPTR(P_JLINKARM_ReadMemU64, Addr, NumItems, pData, pStatus); 103 | } 104 | 105 | int JLINK_ReadMemZonedEx(uint32_t Addr, uint32_t NumBytes, void *pData, uint32_t AccessWidth, const char *sZone) { 106 | return JLinkDLL_CALLPTR(P_JLINK_ReadMemZonedEx, Addr, NumBytes, pData, AccessWidth, sZone); 107 | } 108 | 109 | int JLINKARM_WriteMem(uint32_t Addr, uint32_t Count, const void *pData) { 110 | return JLinkDLL_CALLPTR(P_JLINKARM_WriteMem, Addr, Count, pData); 111 | } 112 | 113 | int JLINKARM_WriteMemDelayed(uint32_t Addr, uint32_t Count, const void *pData) { 114 | return JLinkDLL_CALLPTR(P_JLINKARM_WriteMemDelayed, Addr, Count, pData); 115 | } 116 | 117 | int JLINKARM_WriteMemEx(uint32_t Addr, uint32_t NumBytes, const void *p, uint32_t AccessWidth) { 118 | return JLinkDLL_CALLPTR(P_JLINKARM_WriteMemEx, Addr, NumBytes, p, AccessWidth); 119 | } 120 | 121 | int JLINK_WriteMemZonedEx(uint32_t Addr, uint32_t NumBytes, const void *p, uint32_t AccessWidth, const char *sZone) { 122 | return JLinkDLL_CALLPTR(P_JLINK_WriteMemZonedEx, Addr, NumBytes, p, AccessWidth, sZone); 123 | } 124 | 125 | int JLINKARM_WriteU8(uint32_t Addr, uint8_t Data) { 126 | return JLinkDLL_CALLPTR(P_JLINKARM_WriteU8, Addr, Data); 127 | } 128 | 129 | int JLINKARM_WriteU16(uint32_t Addr, uint16_t Data) { 130 | return JLinkDLL_CALLPTR(P_JLINKARM_WriteU16, Addr, Data); 131 | } 132 | 133 | int JLINKARM_WriteU32(uint32_t Addr, uint32_t Data) { 134 | return JLinkDLL_CALLPTR(P_JLINKARM_WriteU32, Addr, Data); 135 | } 136 | 137 | int JLINKARM_WriteU64(uint32_t Addr, uint64_t Data) { 138 | return JLinkDLL_CALLPTR(P_JLINKARM_WriteU64, Addr, Data); 139 | } 140 | //PYTHON CHECK POINT 141 | -------------------------------------------------------------------------------- /JLink/General/JLink_Memory.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file JLink_Memory.h 3 | * @author yao 4 | */ 5 | 6 | #ifndef JLINKDLL_JLINK_MEMORY_H 7 | #define JLINKDLL_JLINK_MEMORY_H 8 | 9 | #include 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | 15 | /** 16 | * Get the different memory zones supported by the currently connected CPU. Some CPUs 17 | * (Like 8051 based devices) support multiple memory zones where the physical address of 18 | * the different zones may overlap. For example, the 8051 cores support the following zones, 19 | * each zone starting at address 0x0: 20 | * 21 | * - IDATA 22 | * 23 | * - DDATA 24 | * 25 | * - XDATA 26 | * 27 | * - CODE 28 | * 29 | * To access the different zones, the J-Link API provides some functions to route a memory 30 | * access to a specific memory zone. These functions will fail if: 31 | * 32 | * - The connected CPU core does not provide any zones. 33 | * 34 | * - An unknown zone is passed for sZone. All of these function may only be called after 35 | * JLINK_Connect() has been called successfully. 36 | * 37 | * @code 38 | * // Shows all memory zones of the target CPU. 39 | * static int _ShowAllMemZones (void) { 40 | * int r; 41 | * JLINK_MEM_ZONE_INFO* paZoneInfo; 42 | * JLINK_MEM_ZONE_INFO aZoneInfo[10]; 43 | * r = JLINK_GetMemZones(aZoneInfo, COUNTOF(aZoneInfo)); 44 | * if (r < 0) { 45 | * return -1; 46 | * } 47 | * if (r > COUNTOF(aZoneInfo)) { 48 | * // 49 | * // Allocate memory for memory zones info buffer if local buffer is not big enough 50 | * // 51 | * paZoneInfo = malloc(r * sizeof(JLINK_MEM_ZONE_INFO)); 52 | * if (paZoneInfo == NULL) { 53 | * printf("Failed to allocate memory for memory zones info buffer.\n"); 54 | * return -1; 55 | * } 56 | * r = JLINK_GetMemZones(paZoneInfo, r); 57 | * for (int i = 0; i < r; i++) { 58 | * printf ("Zone Number: %d Zone Name: %s /n", (i + 1), paZoneInfo[i].sName); 59 | * } 60 | * free(paZoneInfo); 61 | * return 0; 62 | * } 63 | * for (int i = 0; i < r; i++) { 64 | * printf ("Zone Number: %d Zone Name: %s /n", (i + 1), aZoneInfo[i].sName); 65 | * } 66 | * return 0; 67 | * } 68 | * @endcode 69 | * @param paZoneInfo Pointer to an array of JLINK_MEM_ZONE_INFO to get the memory zone info into. 70 | * @param MaxNumZones Maximum number of memory zones available in the array pointed to by paZoneInfo . 71 | * @retval >=0 Number of zones supported by the connected CPU. 72 | * @retval <0 Error 73 | */ 74 | int JLINK_GetMemZones(JLINK_MEM_ZONE_INFO *paZoneInfo, int MaxNumZones); 75 | 76 | /** 77 | * The function reads memory from the target system. If necessary, the target CPU is halted 78 | * in order to read memory. 79 | * @param Addr Start address 80 | * @param NumBytes Number of bytes to read 81 | * @param pData Pointer to the memory area where the data should be stored. Make 82 | * sure that it points to a valid memory area and that there is sufficient 83 | * space for the entire number of bytes. 84 | * @retval 0 O.K. Memory could be read 85 | * @retval 1 Error/Abort. Memory could not be read 86 | */ 87 | int JLINKARM_ReadMem(uint32_t Addr, uint32_t NumBytes, void *pData); 88 | 89 | /** 90 | * Reads memory from the target system {@link JLINKARM_ReadMem} with the given access width. 91 | * @see JLINKARM_ReadMem 92 | * @param Addr Start address 93 | * @param NumBytes Number of bytes to read 94 | * @param pData Pointer to the memory area where the data should be stored. Make 95 | * sure that it points to a valid memory area and that there is sufficient 96 | * space for the entire number of bytes. 97 | * @param AccessWidth Forces a specific memory access width. 98 | * @retval >=0 O.K., number of bytes that could be read. 99 | * @retval <0 Error while reading memory. No bytes in pData can be assumed as valid. 100 | */ 101 | int JLINKARM_ReadMemEx(uint32_t Addr, uint32_t NumBytes, void *pData, uint32_t AccessWidth); 102 | 103 | /** 104 | * Reads memory from the target system (see description of {@link JLINKARM_ReadMem}). 105 | * @see JLINKARM_ReadMem 106 | * @param Addr Start address 107 | * @param NumBytes Number of bytes to read 108 | * @param pData Pointer to the memory area where the data should be stored. Make 109 | * sure that it points to a valid memory area and that there is sufficient 110 | * space for the entire number of bytes. 111 | * @retval >=0 Number of bytes read 112 | * @retval <0 Error 113 | */ 114 | int JLINKARM_ReadMemIndirect(uint32_t Addr, uint32_t NumBytes, void *pData); 115 | 116 | /** 117 | * Reads memory from the target system (see description of {@link JLINKARM_ReadMem}). This 118 | * function reads memory immediately from the hardware without caching the memory contents. 119 | * @see JLINKARM_ReadMem 120 | * @param Addr Start address 121 | * @param NumBytes Number of bytes to read 122 | * @param pData Pointer to the memory area where the data should be stored. Make 123 | * sure that it points to a valid memory area and that there is sufficient 124 | * space for the entire number of bytes. 125 | * @retval 0 O.K. Memory could be read 126 | * @retval 1 Error/Abort. Memory could not be read 127 | */ 128 | int JLINKARM_ReadMemHW(uint32_t Addr, uint32_t NumBytes, void *pData); 129 | 130 | /** 131 | * The function reads memory from the target system in units of bytes. 132 | * @param Addr Start address 133 | * @param NumItems Number of bytes to read 134 | * @param pData Pointer to the memory area where the data should be stored. Make 135 | * sure that it points to a valid memory area. 136 | * @param pStatus Pointer to a memory area of min. NumItems bytes in size, to receive 137 | * status information for each item. May be NULL. 138 | * @retval >=0 Number of data units (bytes) successfully read. 139 | * @retval <0 Error, such as JTAG problem, communication problem. 140 | */ 141 | int JLINKARM_ReadMemU8(uint32_t Addr, uint32_t NumItems, uint8_t *pData, uint8_t *pStatus); 142 | 143 | /** 144 | * The function reads memory from the target system in units of 16-bits. 145 | * @param Addr Start address 146 | * @param NumItems Number of bytes to read @bug 官方文档对此处的描写可能存在问题,猜测是Number of 16-bit units (half words) to read. 147 | * @param pData Pointer to the memory area where the data should be stored. Make 148 | * sure that it points to a valid memory area and that there is sufficient 149 | * space for the entire number of 16-bit units. 150 | * @param pStatus Pointer to a memory area of min. NumItems bytes in size, to receive 151 | * status information for each item. May be NULL. 152 | * @retval >=0 Number of data units (half words) successfully read. 153 | * @retval <0 Error, such as JTAG problem, communication problem. 154 | */ 155 | int JLINKARM_ReadMemU16(uint32_t Addr, uint32_t NumItems, uint16_t *pData, uint8_t *pStatus); 156 | 157 | /** 158 | * The function reads memory from the target system in units of 32-bits. 159 | * @param Addr Start address 160 | * @param NumItems Number of 32-bit units (words) to read. 161 | * @param pData Pointer to the memory area where the data should be stored. Make 162 | * sure that it points to a valid memory area and that there is sufficient 163 | * space for the entire number of 32-bit units. 164 | * @param pStatus Pointer to a memory area of min. NumItems bytes in size, to receive 165 | * status information for each item. May be NULL. 166 | * @retval >=0 Number of data units (bytes) successfully read. 167 | * @retval <0 Error, such as JTAG problem, communication problem. 168 | */ 169 | int JLINKARM_ReadMemU32(uint32_t Addr, uint32_t NumItems, uint32_t *pData, uint8_t *pStatus); 170 | 171 | /** 172 | * The function reads memory from the target system in units of 64-bits. 173 | * @param Addr Start address 174 | * @param NumItems Number of 64-bit units (long words) to read. 175 | * @param pData Pointer to the memory area where the data should be stored. Make 176 | * sure that it points to a valid memory area and that there is sufficient 177 | * space for the entire number of 64-bit units. 178 | * @param pStatus Pointer to a memory area of min. NumItems bytes in size, to receive 179 | * status information for each item. May be NULL. 180 | * @retval >=0 Number of data units (bytes) successfully read. 181 | * @retval <0 Error, such as JTAG problem, communication problem. 182 | */ 183 | int JLINKARM_ReadMemU64(uint32_t Addr, uint32_t NumItems, uint64_t *pData, uint8_t *pStatus); 184 | 185 | /** 186 | * Reads from a specific memory zone. 187 | * Some CPUs (Like 8051 based devices) support multiple memory zones where the physical 188 | * address of the different zones may overlap. For example, the 8051 cores support the 189 | * following zones, each zone starting at address 0x0: 190 | * 191 | * - IDATA 192 | * 193 | * - DDATA 194 | * 195 | * - XDATA 196 | * 197 | * - CODE 198 | * 199 | * To access the different zones, the J-Link API provides some functions to route a memory 200 | * access to a specific memory zone. 201 | * 202 | * - The connected CPU core does not provide any zones. 203 | * 204 | * - An unknown zone is passed for sZone. 205 | * 206 | * All of these function may only be called after {@link JLINK_Connect} has been called successfully. 207 | * @param Addr Start address 208 | * @param NumBytes Number of bytes to read 209 | * @param pData Pointer to the memory area where the data should be stored. Make 210 | * sure that it points to a valid memory area and that there is sufficient 211 | * space for the entire number of bytes. 212 | * @param AccessWidth Forces a specific memory access width. 213 | * @param sZone Name of memory zone to access. 214 | * @retval >=0 Number of items read successfully. 215 | * @retval <0 Error 216 | * @retval -1,-2,-3,-4 Reserved for regular ReadMem error codes 217 | * @retval -5 Zone not found 218 | */ 219 | int JLINK_ReadMemZonedEx(uint32_t Addr, uint32_t NumBytes, void *pData, uint32_t AccessWidth, const char *sZone); 220 | 221 | 222 | /** 223 | * The function writes memory to the target system. 224 | * @param Addr Start address 225 | * @param Count Number of bytes to write. 226 | * @param pData Pointer to buffer containing the data bytes to write. 227 | * @retval >=0 Number of bytes transferred successfully. 228 | * @retval <0 Error. 229 | */ 230 | int JLINKARM_WriteMem(uint32_t Addr, uint32_t Count, const void *pData); 231 | 232 | /** 233 | * Writes memory to the target system (see description of {@link JLINKARM_WriteMem}). 234 | * This function does not write the data immediately to the target hardware. The data will be 235 | * cached. This function is obsolete and should not be used for future software development. 236 | * @see JLINKARM_WriteMem 237 | * @param Addr Start address 238 | * @param Count Number of bytes to write. 239 | * @param pData Pointer to buffer containing the data bytes to write. 240 | * @retval >=0 Number of bytes transferred successfully. 241 | * @retval <0 Error. 242 | */ 243 | int JLINKARM_WriteMemDelayed(uint32_t Addr, uint32_t Count, const void *pData); 244 | 245 | /** 246 | * Writes memory to the target system (see description of {@link JLINKARM_WriteMem}) with the 247 | * given maximum assess width. 248 | * @see JLINKARM_WriteMem 249 | * @retval >=0 Number of items transferred successfully. 250 | * @retval <0 Error. 251 | */ 252 | int JLINKARM_WriteMemEx(uint32_t Addr, uint32_t NumBytes, const void *p, uint32_t AccessWidth); 253 | 254 | /** 255 | * Writes to a specific memory zone. 256 | * Some CPUs (Like 8051 based devices) support multiple memory zones where the physical 257 | * address of the different zones may overlap. For example, the 8051 cores support the 258 | * following zones, each zone starting at address 0x0: 259 | * 260 | * - IDATA 261 | * 262 | * - DDATA 263 | * 264 | * - XDATA 265 | * 266 | * - CODE 267 | * 268 | * To access the different zones, the J-Link API provides some functions to route a memory 269 | * access to a specific memory zone. These functions will fail if: 270 | * 271 | * - The connected CPU core does not provide any zones. 272 | * 273 | * - An unknown zone is passed for sZone. 274 | * 275 | * All of these function may only be called after JLINK_Connect() has been called successfully. 276 | * 277 | * @param Addr Start address 278 | * @param NumBytes Number of bytes to write 279 | * @param p Pointer to the memory area containing the data that should be 280 | * stored. Make sure that it points to a valid memory area. 281 | * @param AccessWidth Forces a specific memory access width. 282 | * @param sZone Name of memory zone to access. 283 | * @retval >=0 Number of items written successfully. 284 | * @retval <0 Error 285 | * @retval -1,-2,-3,-4 Reserved for regular WriteMem error codes 286 | * @retval -5 Zone not found 287 | * */ 288 | int JLINK_WriteMemZonedEx(uint32_t Addr, uint32_t NumBytes, const void *p, uint32_t AccessWidth, const char *sZone); 289 | 290 | /** 291 | * The function writes one single byte to the target system. 292 | * @param Addr Address 293 | * @param Data Data byte to write 294 | * @retval 0 ok 295 | * @retval !=0 Error 296 | */ 297 | int JLINKARM_WriteU8(uint32_t Addr, uint8_t Data); 298 | 299 | /** 300 | * The function writes a unit of 16-bits to the target system. 301 | * @param Addr Address 302 | * @param Data 16-bits of data to write. 303 | * @retval 0 ok 304 | * @retval !=0 Error 305 | */ 306 | int JLINKARM_WriteU16(uint32_t Addr, uint16_t Data); 307 | 308 | /** 309 | * The function writes a unit of 32-bits to the target system. 310 | * @param Addr Address 311 | * @param Data 32-bits of data to write. 312 | * @retval 0 ok 313 | * @retval !=0 Error 314 | */ 315 | int JLINKARM_WriteU32(uint32_t Addr, uint32_t Data); 316 | 317 | /** 318 | * The function writes a unit of 64-bits to the target system. 319 | * @param Addr Address 320 | * @param Data 64-bits of data to write. 321 | * @retval 0 ok 322 | * @retval !=0 Error 323 | */ 324 | int JLINKARM_WriteU64(uint32_t Addr, uint64_t Data); 325 | 326 | #ifdef __cplusplus 327 | } 328 | #endif 329 | 330 | #endif //JLINKDLL_JLINK_MEMORY_H 331 | -------------------------------------------------------------------------------- /JLink/General/JLink_Reset.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yaoji on 2022/3/18. 3 | // 4 | 5 | #include "JLink_Reset.h" 6 | #include "JLink/JLink_Init.h" 7 | 8 | static int (*P_JLINKARM_Reset)(void); 9 | static void (*P_JLINKARM_ResetNoHalt)(void); 10 | static void (*P_JLINKARM_ResetPullsRESET)(uint8_t OnOff); 11 | static void (*P_JLINKARM_ResetPullsTRST)(uint8_t OnOff); 12 | static void (*P_JLINKARM_ResetTRST)(void); 13 | static int (*P_JLINKARM_SetInitRegsOnReset)(int OnOff); 14 | static void (*P_JLINKARM_SetResetDelay)(int ms); 15 | static void (*P_JLINKARM_SetResetType)(JLINKARM_RESET_TYPE ResetType); 16 | static int (*P_JLINKARM_GetResetTypeDesc)(int ResetType, const char **psResetName, const char **psResetDesc); 17 | 18 | int JLINK_GERENAL_RESET_Init() { 19 | P_JLINKARM_Reset = JLinkDLL_getSym("JLINKARM_Reset"); 20 | if (P_JLINKARM_Reset == NULL) return 0; 21 | P_JLINKARM_ResetNoHalt = JLinkDLL_getSym("JLINKARM_ResetNoHalt"); 22 | if (P_JLINKARM_ResetNoHalt == NULL) return 0; 23 | P_JLINKARM_ResetPullsRESET = JLinkDLL_getSym("JLINKARM_ResetPullsRESET"); 24 | if (P_JLINKARM_ResetPullsRESET == NULL) return 0; 25 | P_JLINKARM_ResetPullsTRST = JLinkDLL_getSym("JLINKARM_ResetPullsTRST"); 26 | if (P_JLINKARM_ResetPullsTRST == NULL) return 0; 27 | P_JLINKARM_ResetTRST = JLinkDLL_getSym("JLINKARM_ResetTRST"); 28 | if (P_JLINKARM_ResetTRST == NULL) return 0; 29 | P_JLINKARM_SetInitRegsOnReset = JLinkDLL_getSym("JLINKARM_SetInitRegsOnReset"); 30 | if (P_JLINKARM_SetInitRegsOnReset == NULL) return 0; 31 | P_JLINKARM_SetResetDelay = JLinkDLL_getSym("JLINKARM_SetResetDelay"); 32 | if (P_JLINKARM_SetResetDelay == NULL) return 0; 33 | P_JLINKARM_SetResetType = JLinkDLL_getSym("JLINKARM_SetResetType"); 34 | if (P_JLINKARM_SetResetType == NULL) return 0; 35 | P_JLINKARM_GetResetTypeDesc = JLinkDLL_getSym("JLINKARM_GetResetTypeDesc"); 36 | if (P_JLINKARM_GetResetTypeDesc == NULL) return 0; 37 | return 1; 38 | } 39 | //PYTHON CHECK POINT 40 | int JLINKARM_Reset(void) { 41 | return JLinkDLL_CALLPTR(P_JLINKARM_Reset); 42 | } 43 | 44 | void JLINKARM_ResetNoHalt(void) { 45 | JLinkDLL_CALLPTR(P_JLINKARM_ResetNoHalt); 46 | } 47 | 48 | void JLINKARM_ResetPullsRESET(uint8_t OnOff) { 49 | JLinkDLL_CALLPTR(P_JLINKARM_ResetPullsRESET, OnOff); 50 | } 51 | 52 | void JLINKARM_ResetPullsTRST(uint8_t OnOff) { 53 | JLinkDLL_CALLPTR(P_JLINKARM_ResetPullsTRST, OnOff); 54 | } 55 | 56 | void JLINKARM_ResetTRST(void) { 57 | JLinkDLL_CALLPTR(P_JLINKARM_ResetTRST); 58 | } 59 | 60 | int JLINKARM_SetInitRegsOnReset(int OnOff) { 61 | return JLinkDLL_CALLPTR(P_JLINKARM_SetInitRegsOnReset, OnOff); 62 | } 63 | 64 | void JLINKARM_SetResetDelay(int ms) { 65 | JLinkDLL_CALLPTR(P_JLINKARM_SetResetDelay, ms); 66 | } 67 | 68 | void JLINKARM_SetResetType(JLINKARM_RESET_TYPE ResetType) { 69 | JLinkDLL_CALLPTR(P_JLINKARM_SetResetType, ResetType); 70 | } 71 | 72 | int JLINKARM_GetResetTypeDesc(int ResetType, const char **psResetName, const char **psResetDesc) { 73 | return JLinkDLL_CALLPTR(P_JLINKARM_GetResetTypeDesc, ResetType, psResetName, psResetDesc); 74 | } 75 | //PYTHON CHECK POINT -------------------------------------------------------------------------------- /JLink/General/JLink_Reset.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file JLink_Reset.h 3 | * @author yao 4 | */ 5 | 6 | 7 | #ifndef JLINKDLL_JLINK_RESET_H 8 | #define JLINKDLL_JLINK_RESET_H 9 | 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | /** 17 | * This function performs a reset. The RESET pin and the TRST pin are toggled by default, 18 | * when this function is called. 19 | * @retval >= 0 Number of bytes read 20 | * @retval < 0 Error 21 | */ 22 | int JLINKARM_Reset(void); 23 | 24 | /** 25 | * This function performs a RESET but without halting the device. 26 | * For more detailed information please see the description of {@link JLINKARM_Reset}. 27 | */ 28 | void JLINKARM_ResetNoHalt(void); 29 | 30 | /** 31 | * This function affects the behaviour of the function JLINKARM_Reset(). If ResetPullsRESET 32 | * is enabled, the function JLINKARM_Reset() will also toggle the RESET pin on the JTAG bus 33 | * @param OnOff Enables (=1) or disables (=0) ResetPullsRESET. 34 | */ 35 | void JLINKARM_ResetPullsRESET(uint8_t OnOff); 36 | 37 | /** 38 | * This function affects the behaviour of the function JLINKARM_Reset(). If ResetPullsTRST is 39 | * enabled, the function JLINKARM_Reset() will also toggle the TRST pin on the JTAG bus. 40 | * @param OnOff Enables (=1) or disables (=0) ResetPullsTRST. 41 | */ 42 | void JLINKARM_ResetPullsTRST(uint8_t OnOff); 43 | 44 | /** 45 | * This function resets the TAP controller via TRST 46 | */ 47 | void JLINKARM_ResetTRST(void); 48 | 49 | /** 50 | * 51 | * @param OnOff 52 | * @return 53 | */ 54 | int JLINKARM_SetInitRegsOnReset(int OnOff); 55 | 56 | /** 57 | * Defines a delay in milliseconds after reset. This function is useful for some evalboards which 58 | * already contain an application or a boot loader and therefore need some time before the 59 | * core is stopped, for example to initialize hardware, the memory management unit (MMU) 60 | * or the external bus interface. Default value is 0. 61 | * 62 | * @note Boards like the ATMEL EB55 start up in 32 kHz mode. Allowing the default flash to execute 63 | * before stopping makes it possible to work with the board without writing a debugger macro 64 | * to set up the clock. It makes initial work with a board easier. Another example is when the 65 | * onboard flash sets up boards with memory like DRAM. In a final design this is not an issue, 66 | * but it makes life easier for the first playing around. 67 | * 68 | * @param ms Delay after reset in milliseconds. 69 | */ 70 | void JLINKARM_SetResetDelay(int ms); 71 | 72 | /** 73 | * Defines the reset strategy. 74 | * @param ResetType Defines the reset strategy. 75 | */ 76 | void JLINKARM_SetResetType(JLINKARM_RESET_TYPE ResetType); 77 | 78 | /** 79 | * Get description of a specific reset type available for the currently connected CPU core. 80 | * @note Target already needs to be identified by {@link JLINKARM_Connect} when calling this function. 81 | * @return Number of available reset types for CPU core J-Link is currently connected to 82 | */ 83 | int JLINKARM_GetResetTypeDesc(int ResetType, const char **psResetName, const char **psResetDesc); 84 | 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #endif //JLINKDLL_JLINK_RESET_H 91 | -------------------------------------------------------------------------------- /JLink/General/JLink_SystemControl.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yaoji on 2022/3/18. 3 | // 4 | 5 | #include "JLink_SystemControl.h" 6 | #include "JLink/JLink_Init.h" 7 | 8 | static uint32_t (*P_JLINKARM_GetDLLVersion)(); 9 | static void (*P_JLINKARM_ClrRESET)(void); 10 | static int (*P_JLINKARM_ClrTCK)(void); 11 | static void (*P_JLINKARM_ClrTDI)(void); 12 | static void (*P_JLINKARM_ClrTMS)(void); 13 | static void (*P_JLINKARM_ClrTRST)(void); 14 | static void (*P_JLINKARM_ClrError)(void); 15 | 16 | static void (*P_JLINKARM_BeginDownload)(uint32_t Flags); 17 | static uint8_t (*P_JLINKARM_Clock)(void); 18 | static int (*P_JLINKARM_CORESIGHT_Configure)(const char *sConfig); 19 | static int (*P_JLINKARM_CORESIGHT_ReadAPDPReg)(uint8_t RegIndex, uint8_t APnDP, uint32_t *pData); 20 | static int (*P_JLINKARM_CORESIGHT_WriteAPDPReg)(uint8_t RegIndex, uint8_t APnDP, uint32_t Data); 21 | static void (*P_JLINKARM_Core2CoreName)(uint32_t Core, char *pBuffer, unsigned BufferSize); 22 | static int (*P_JLINKARM_CP15_ReadEx)(uint8_t CRn, uint8_t CRm, uint8_t op1, uint8_t op2, uint32_t *pData); 23 | static int (*P_JLINKARM_CP15_WriteEx)(uint8_t CRn, uint8_t CRm, uint8_t op1, uint8_t op2, uint32_t Data); 24 | static int (*P_JLINKARM_DEVICE_GetIndex)(const char *sDeviceName); 25 | static int (*P_JLINKARM_DEVICE_SelectDialog)(void *hParent, uint32_t Flags, JLINKARM_DEVICE_SELECT_INFO *pInfo); 26 | static int (*P_JLINK_DownloadFile)(const char *sFileName, uint32_t Addr); 27 | static int (*P_JLINKARM_EMU_COM_Read)(unsigned Channel, unsigned NumBytes, void *pData); 28 | static int (*P_JLINKARM_EMU_COM_Write)(unsigned Channel, unsigned NumBytes, const void *pData); 29 | static int (*P_JLINKARM_EMU_COM_IsSupported)(void); 30 | static void (*P_JLINKARM_EMU_GetProductName)(char *pBuffer, uint32_t BufferSize); 31 | static int (*P_JLINKARM_EMU_HasCapEx)(int CapEx); 32 | static int (*P_JLINKARM_EMU_HasCPUCap)(uint32_t CPUCap); 33 | static char (*P_JLINKARM_EMU_IsConnected)(void); 34 | static void (*P_JLINKARM_EnableLog)(JLINKARM_LOG *pfLog); 35 | static void (*P_JLINKARM_EnableLogCom)(JLINKARM_LOG *pfLog); 36 | static int (*P_JLINKARM_EndDownload)(void); 37 | static int (*P_JLINK_EraseChip)(void); 38 | static const char *(*P_JLINKARM_GetCompileDateTime)(void); 39 | static void (*P_JLINKARM_GetConfigData)(int *pIRPre, int *pDRPre); 40 | static int (*P_JLINKARM_GetDebugInfo)(uint32_t Index, uint32_t *pInfo); 41 | static int (*P_JLINKARM_GetDeviceFamily)(void); 42 | static uint32_t (*P_JLINKARM_GetEmuCaps)(void); 43 | static void (*P_JLINKARM_GetEmuCapsEx)(uint8_t *pCaps, int BufferSize); 44 | static void (*P_JLINKARM_GetFeatureString)(char *pOut); 45 | static void (*P_JLINKARM_GetFirmwareString)(char *s, int BufferSize); 46 | static int (*P_JLINKARM_GetHWInfo)(uint32_t BitMask, uint32_t *pHWInfo); 47 | static int (*P_JLINKARM_GetHWStatus)(JLINKARM_HW_STATUS *pStat); 48 | static int (*P_JLINKARM_GetHardwareVersion)(void); 49 | static void (*P_JLINKARM_GetIdData)(JTAG_ID_DATA *pIdData); 50 | static int (*P_JLINKARM_GetMOEs)(JLINKARM_MOE_INFO *pInfo, int MaxNumMOEs); 51 | static char (*P_JLINKARM_GetOEMString)(char *pOut); 52 | static int (*P_JLINKARM_GetScanLen)(void); 53 | static uint16_t (*P_JLINKARM_GetSelDevice)(void); 54 | static int (*P_JLINKARM_GetSN)(void); 55 | static uint16_t (*P_JLINKARM_GetSpeed)(void); 56 | static void (*P_JLINKARM_GetSpeedInfo)(JLINKARM_SPEED_INFO *pSpeedInfo); 57 | static char (*P_JLINKARM_HasError)(void); 58 | static int (*P_JLINKARM_MeasureCPUSpeed)(uint32_t RAMAddr, int PreserveMem); 59 | static int (*P_JLINKARM_MeasureCPUSpeedEx)(uint32_t RAMAddr, int PreserveMem, int AllowFail); 60 | static int (*P_JLINKARM_MeasureSCLen)(int ScanChain); 61 | static void (*P_JLINKARM_SelDevice)(uint16_t DeviceIndex); 62 | static void (*P_JLINKARM_SelectTraceSource)(int Source); 63 | static int (*P_JLINKARM_SetEndian)(int v); 64 | static void (*P_JLINKARM_SetErrorOutHandler)(JLINKARM_LOG *pfErrorOut); 65 | static void (*P_JLINKARM_SetLogFile)(const char *sFilename); 66 | static void (*P_JLINKARM_SetMaxSpeed)(void); 67 | static void (*P_JLINKARM_SetRESET)(void); 68 | static void (*P_JLINKARM_SetSpeed)(uint32_t Speed); 69 | static int (*P_JLINKARM_SetTCK)(void); 70 | static void (*P_JLINKARM_SetTDI)(void); 71 | static void (*P_JLINKARM_SetTMS)(void); 72 | static void (*P_JLINKARM_SetTRST)(void); 73 | static void (*P_JLINKARM_StoreBits)(uint32_t TMS, uint32_t TDI, int NumBits); 74 | static void (*P_JLINKARM_TIF_GetAvailable)(uint32_t *pMask); 75 | static int (*P_JLINKARM_TIF_Select)(int Interface); 76 | static uint32_t (*P_JLINKARM_UpdateFirmwareIfNewer)(void); 77 | static void (*P_JLINKARM_SetWarnOutHandler)(JLINKARM_LOG *pfWarnOut); 78 | static void (*P_JLINKARM_WriteBits)(void); 79 | static uint32_t (*P_JLINKARM_EMU_GetNumDevices)(void); 80 | void *(*P_JLINK_GetpFunc)(JLINK_FUNC_INDEX FuncIndex); 81 | 82 | int (*P_JLINKARM_ExecCommand)(const char* sIn, char* sError, int BufferSize); 83 | //static void (*P_JLINKARM_EMU_GetDeviceInfo)(uint32_t iEmu, JLINKARM_EMU_INFO *pInfo); 84 | 85 | int JLINK_GERENAL_SystemControl_Init() { 86 | P_JLINKARM_GetDLLVersion = JLinkDLL_getSym("JLINKARM_GetDLLVersion"); 87 | if (P_JLINKARM_GetDLLVersion == NULL) return 0; 88 | P_JLINKARM_ClrRESET = JLinkDLL_getSym("JLINKARM_ClrRESET"); 89 | if (P_JLINKARM_ClrRESET == NULL) return 0; 90 | P_JLINKARM_ClrTCK = JLinkDLL_getSym("JLINKARM_ClrTCK"); 91 | if (P_JLINKARM_ClrTCK == NULL) return 0; 92 | P_JLINKARM_ClrTDI = JLinkDLL_getSym("JLINKARM_ClrTDI"); 93 | if (P_JLINKARM_ClrTDI == NULL) return 0; 94 | P_JLINKARM_ClrTMS = JLinkDLL_getSym("JLINKARM_ClrTMS"); 95 | if (P_JLINKARM_ClrTMS == NULL) return 0; 96 | P_JLINKARM_ClrTRST = JLinkDLL_getSym("JLINKARM_ClrTRST"); 97 | if (P_JLINKARM_ClrTRST == NULL) return 0; 98 | P_JLINKARM_ClrError = JLinkDLL_getSym("JLINKARM_ClrError"); 99 | if (P_JLINKARM_ClrError == NULL) return 0; 100 | P_JLINKARM_BeginDownload = JLinkDLL_getSym("JLINKARM_BeginDownload"); 101 | if (P_JLINKARM_BeginDownload == NULL) return 0; 102 | P_JLINKARM_Clock = JLinkDLL_getSym("JLINKARM_Clock"); 103 | if (P_JLINKARM_Clock == NULL) return 0; 104 | P_JLINKARM_CORESIGHT_Configure = JLinkDLL_getSym("JLINKARM_CORESIGHT_Configure"); 105 | if (P_JLINKARM_CORESIGHT_Configure == NULL) return 0; 106 | P_JLINKARM_CORESIGHT_ReadAPDPReg = JLinkDLL_getSym("JLINKARM_CORESIGHT_ReadAPDPReg"); 107 | if (P_JLINKARM_CORESIGHT_ReadAPDPReg == NULL) return 0; 108 | P_JLINKARM_CORESIGHT_WriteAPDPReg = JLinkDLL_getSym("JLINKARM_CORESIGHT_WriteAPDPReg"); 109 | if (P_JLINKARM_CORESIGHT_WriteAPDPReg == NULL) return 0; 110 | P_JLINKARM_Core2CoreName = JLinkDLL_getSym("JLINKARM_Core2CoreName"); 111 | if (P_JLINKARM_Core2CoreName == NULL) return 0; 112 | P_JLINKARM_CP15_ReadEx = JLinkDLL_getSym("JLINKARM_CP15_ReadEx"); 113 | if (P_JLINKARM_CP15_ReadEx == NULL) return 0; 114 | P_JLINKARM_CP15_WriteEx = JLinkDLL_getSym("JLINKARM_CP15_WriteEx"); 115 | if (P_JLINKARM_CP15_WriteEx == NULL) return 0; 116 | P_JLINKARM_DEVICE_GetIndex = JLinkDLL_getSym("JLINKARM_DEVICE_GetIndex"); 117 | if (P_JLINKARM_DEVICE_GetIndex == NULL) return 0; 118 | P_JLINKARM_DEVICE_SelectDialog = JLinkDLL_getSym("JLINKARM_DEVICE_SelectDialog"); 119 | if (P_JLINKARM_DEVICE_SelectDialog == NULL) return 0; 120 | P_JLINK_DownloadFile = JLinkDLL_getSym("JLINK_DownloadFile"); 121 | if (P_JLINK_DownloadFile == NULL) return 0; 122 | P_JLINKARM_EMU_COM_Read = JLinkDLL_getSym("JLINKARM_EMU_COM_Read"); 123 | if (P_JLINKARM_EMU_COM_Read == NULL) return 0; 124 | P_JLINKARM_EMU_COM_Write = JLinkDLL_getSym("JLINKARM_EMU_COM_Write"); 125 | if (P_JLINKARM_EMU_COM_Write == NULL) return 0; 126 | P_JLINKARM_EMU_COM_IsSupported = JLinkDLL_getSym("JLINKARM_EMU_COM_IsSupported"); 127 | if (P_JLINKARM_EMU_COM_IsSupported == NULL) return 0; 128 | P_JLINKARM_EMU_GetProductName = JLinkDLL_getSym("JLINKARM_EMU_GetProductName"); 129 | if (P_JLINKARM_EMU_GetProductName == NULL) return 0; 130 | P_JLINKARM_EMU_HasCapEx = JLinkDLL_getSym("JLINKARM_EMU_HasCapEx"); 131 | if (P_JLINKARM_EMU_HasCapEx == NULL) return 0; 132 | P_JLINKARM_EMU_HasCPUCap = JLinkDLL_getSym("JLINKARM_EMU_HasCPUCap"); 133 | if (P_JLINKARM_EMU_HasCPUCap == NULL) return 0; 134 | P_JLINKARM_EMU_IsConnected = JLinkDLL_getSym("JLINKARM_EMU_IsConnected"); 135 | if (P_JLINKARM_EMU_IsConnected == NULL) return 0; 136 | P_JLINKARM_EnableLog = JLinkDLL_getSym("JLINKARM_EnableLog"); 137 | if (P_JLINKARM_EnableLog == NULL) return 0; 138 | P_JLINKARM_EnableLogCom = JLinkDLL_getSym("JLINKARM_EnableLogCom"); 139 | if (P_JLINKARM_EnableLogCom == NULL) return 0; 140 | P_JLINKARM_EndDownload = JLinkDLL_getSym("JLINKARM_EndDownload"); 141 | if (P_JLINKARM_EndDownload == NULL) return 0; 142 | P_JLINK_EraseChip = JLinkDLL_getSym("JLINK_EraseChip"); 143 | if (P_JLINK_EraseChip == NULL) return 0; 144 | P_JLINKARM_GetCompileDateTime = JLinkDLL_getSym("JLINKARM_GetCompileDateTime"); 145 | if (P_JLINKARM_GetCompileDateTime == NULL) return 0; 146 | P_JLINKARM_GetConfigData = JLinkDLL_getSym("JLINKARM_GetConfigData"); 147 | if (P_JLINKARM_GetConfigData == NULL) return 0; 148 | P_JLINKARM_GetDebugInfo = JLinkDLL_getSym("JLINKARM_GetDebugInfo"); 149 | if (P_JLINKARM_GetDebugInfo == NULL) return 0; 150 | P_JLINKARM_GetDeviceFamily = JLinkDLL_getSym("JLINKARM_GetDeviceFamily"); 151 | if (P_JLINKARM_GetDeviceFamily == NULL) return 0; 152 | P_JLINKARM_GetEmuCaps = JLinkDLL_getSym("JLINKARM_GetEmuCaps"); 153 | if (P_JLINKARM_GetEmuCaps == NULL) return 0; 154 | P_JLINKARM_GetEmuCapsEx = JLinkDLL_getSym("JLINKARM_GetEmuCapsEx"); 155 | if (P_JLINKARM_GetEmuCapsEx == NULL) return 0; 156 | P_JLINKARM_GetFeatureString = JLinkDLL_getSym("JLINKARM_GetFeatureString"); 157 | if (P_JLINKARM_GetFeatureString == NULL) return 0; 158 | P_JLINKARM_GetFirmwareString = JLinkDLL_getSym("JLINKARM_GetFirmwareString"); 159 | if (P_JLINKARM_GetFirmwareString == NULL) return 0; 160 | P_JLINKARM_GetHWInfo = JLinkDLL_getSym("JLINKARM_GetHWInfo"); 161 | if (P_JLINKARM_GetHWInfo == NULL) return 0; 162 | P_JLINKARM_GetHWStatus = JLinkDLL_getSym("JLINKARM_GetHWStatus"); 163 | if (P_JLINKARM_GetHWStatus == NULL) return 0; 164 | P_JLINKARM_GetHardwareVersion = JLinkDLL_getSym("JLINKARM_GetHardwareVersion"); 165 | if (P_JLINKARM_GetHardwareVersion == NULL) return 0; 166 | P_JLINKARM_GetIdData = JLinkDLL_getSym("JLINKARM_GetIdData"); 167 | if (P_JLINKARM_GetIdData == NULL) return 0; 168 | P_JLINKARM_GetMOEs = JLinkDLL_getSym("JLINKARM_GetMOEs"); 169 | if (P_JLINKARM_GetMOEs == NULL) return 0; 170 | P_JLINKARM_GetOEMString = JLinkDLL_getSym("JLINKARM_GetOEMString"); 171 | if (P_JLINKARM_GetOEMString == NULL) return 0; 172 | P_JLINKARM_GetScanLen = JLinkDLL_getSym("JLINKARM_GetScanLen"); 173 | if (P_JLINKARM_GetScanLen == NULL) return 0; 174 | P_JLINKARM_GetSelDevice = JLinkDLL_getSym("JLINKARM_GetSelDevice"); 175 | if (P_JLINKARM_GetSelDevice == NULL) return 0; 176 | P_JLINKARM_GetSN = JLinkDLL_getSym("JLINKARM_GetSN"); 177 | if (P_JLINKARM_GetSN == NULL) return 0; 178 | P_JLINKARM_GetSpeed = JLinkDLL_getSym("JLINKARM_GetSpeed"); 179 | if (P_JLINKARM_GetSpeed == NULL) return 0; 180 | P_JLINKARM_GetSpeedInfo = JLinkDLL_getSym("JLINKARM_GetSpeedInfo"); 181 | if (P_JLINKARM_GetSpeedInfo == NULL) return 0; 182 | P_JLINKARM_HasError = JLinkDLL_getSym("JLINKARM_HasError"); 183 | if (P_JLINKARM_HasError == NULL) return 0; 184 | P_JLINKARM_MeasureCPUSpeed = JLinkDLL_getSym("JLINKARM_MeasureCPUSpeed"); 185 | if (P_JLINKARM_MeasureCPUSpeed == NULL) return 0; 186 | P_JLINKARM_MeasureCPUSpeedEx = JLinkDLL_getSym("JLINKARM_MeasureCPUSpeedEx"); 187 | if (P_JLINKARM_MeasureCPUSpeedEx == NULL) return 0; 188 | P_JLINKARM_MeasureSCLen = JLinkDLL_getSym("JLINKARM_MeasureSCLen"); 189 | if (P_JLINKARM_MeasureSCLen == NULL) return 0; 190 | P_JLINKARM_SelDevice = JLinkDLL_getSym("JLINKARM_SelDevice"); 191 | if (P_JLINKARM_SelDevice == NULL) return 0; 192 | P_JLINKARM_SelectTraceSource = JLinkDLL_getSym("JLINKARM_SelectTraceSource"); 193 | if (P_JLINKARM_SelectTraceSource == NULL) return 0; 194 | P_JLINKARM_SetEndian = JLinkDLL_getSym("JLINKARM_SetEndian"); 195 | if (P_JLINKARM_SetEndian == NULL) return 0; 196 | P_JLINKARM_SetErrorOutHandler = JLinkDLL_getSym("JLINKARM_SetErrorOutHandler"); 197 | if (P_JLINKARM_SetErrorOutHandler == NULL) return 0; 198 | P_JLINKARM_SetLogFile = JLinkDLL_getSym("JLINKARM_SetLogFile"); 199 | if (P_JLINKARM_SetLogFile == NULL) return 0; 200 | P_JLINKARM_SetMaxSpeed = JLinkDLL_getSym("JLINKARM_SetMaxSpeed"); 201 | if (P_JLINKARM_SetMaxSpeed == NULL) return 0; 202 | P_JLINKARM_SetRESET = JLinkDLL_getSym("JLINKARM_SetRESET"); 203 | if (P_JLINKARM_SetRESET == NULL) return 0; 204 | P_JLINKARM_SetSpeed = JLinkDLL_getSym("JLINKARM_SetSpeed"); 205 | if (P_JLINKARM_SetSpeed == NULL) return 0; 206 | P_JLINKARM_SetTCK = JLinkDLL_getSym("JLINKARM_SetTCK"); 207 | if (P_JLINKARM_SetTCK == NULL) return 0; 208 | P_JLINKARM_SetTDI = JLinkDLL_getSym("JLINKARM_SetTDI"); 209 | if (P_JLINKARM_SetTDI == NULL) return 0; 210 | P_JLINKARM_SetTMS = JLinkDLL_getSym("JLINKARM_SetTMS"); 211 | if (P_JLINKARM_SetTMS == NULL) return 0; 212 | P_JLINKARM_SetTRST = JLinkDLL_getSym("JLINKARM_SetTRST"); 213 | if (P_JLINKARM_SetTRST == NULL) return 0; 214 | P_JLINKARM_StoreBits = JLinkDLL_getSym("JLINKARM_StoreBits"); 215 | if (P_JLINKARM_StoreBits == NULL) return 0; 216 | P_JLINKARM_TIF_GetAvailable = JLinkDLL_getSym("JLINKARM_TIF_GetAvailable"); 217 | if (P_JLINKARM_TIF_GetAvailable == NULL) return 0; 218 | P_JLINKARM_TIF_Select = JLinkDLL_getSym("JLINKARM_TIF_Select"); 219 | if (P_JLINKARM_TIF_Select == NULL) return 0; 220 | P_JLINKARM_UpdateFirmwareIfNewer = JLinkDLL_getSym("JLINKARM_UpdateFirmwareIfNewer"); 221 | if (P_JLINKARM_UpdateFirmwareIfNewer == NULL) return 0; 222 | P_JLINKARM_SetWarnOutHandler = JLinkDLL_getSym("JLINKARM_SetWarnOutHandler"); 223 | if (P_JLINKARM_SetWarnOutHandler == NULL) return 0; 224 | P_JLINKARM_WriteBits = JLinkDLL_getSym("JLINKARM_WriteBits"); 225 | if (P_JLINKARM_WriteBits == NULL) return 0; 226 | P_JLINKARM_EMU_GetNumDevices = JLinkDLL_getSym("JLINKARM_EMU_GetNumDevices"); 227 | if (P_JLINKARM_EMU_GetNumDevices == NULL) return 0; 228 | P_JLINK_GetpFunc = JLinkDLL_getSym("JLINK_GetpFunc"); 229 | if (P_JLINK_GetpFunc == NULL) return 0; 230 | P_JLINKARM_ExecCommand = JLinkDLL_getSym("JLINKARM_ExecCommand"); 231 | if (P_JLINKARM_ExecCommand == NULL) return 0; 232 | // P_JLINKARM_EMU_GetDeviceInfo = JLinkDLL_getSym("JLINKARM_EMU_GetDeviceInfo"); 233 | // if (P_JLINKARM_EMU_GetDeviceInfo == NULL) return 0; 234 | return 1; 235 | } 236 | 237 | //PYTHON CHECK POINT 238 | uint32_t JLINKARM_GetDLLVersion(void) { 239 | return JLinkDLL_CALLPTR(P_JLINKARM_GetDLLVersion); 240 | } 241 | 242 | void JLINKARM_ClrRESET(void) { 243 | JLinkDLL_CALLPTR(P_JLINKARM_ClrRESET); 244 | } 245 | 246 | int JLINKARM_ClrTCK(void) { 247 | return JLinkDLL_CALLPTR(P_JLINKARM_ClrTCK); 248 | } 249 | 250 | void JLINKARM_ClrTDI(void) { 251 | JLinkDLL_CALLPTR(P_JLINKARM_ClrTDI); 252 | } 253 | 254 | void JLINKARM_ClrTMS(void) { 255 | JLinkDLL_CALLPTR(P_JLINKARM_ClrTMS); 256 | } 257 | 258 | void JLINKARM_ClrTRST(void) { 259 | JLinkDLL_CALLPTR(P_JLINKARM_ClrTRST); 260 | } 261 | 262 | void JLINKARM_ClrError(void) { 263 | JLinkDLL_CALLPTR(P_JLINKARM_ClrError); 264 | } 265 | 266 | void JLINKARM_BeginDownload(uint32_t Flags) { 267 | JLinkDLL_CALLPTR(P_JLINKARM_BeginDownload, Flags); 268 | } 269 | 270 | uint8_t JLINKARM_Clock(void) { 271 | return JLinkDLL_CALLPTR(P_JLINKARM_Clock); 272 | } 273 | 274 | int JLINKARM_CORESIGHT_Configure(const char *sConfig) { 275 | return JLinkDLL_CALLPTR(P_JLINKARM_CORESIGHT_Configure, sConfig); 276 | } 277 | 278 | int JLINKARM_CORESIGHT_ReadAPDPReg(uint8_t RegIndex, uint8_t APnDP, uint32_t *pData) { 279 | return JLinkDLL_CALLPTR(P_JLINKARM_CORESIGHT_ReadAPDPReg, RegIndex, APnDP, pData); 280 | } 281 | 282 | int JLINKARM_CORESIGHT_WriteAPDPReg(uint8_t RegIndex, uint8_t APnDP, uint32_t Data) { 283 | return JLinkDLL_CALLPTR(P_JLINKARM_CORESIGHT_WriteAPDPReg, RegIndex, APnDP, Data); 284 | } 285 | 286 | void JLINKARM_Core2CoreName(uint32_t Core, char *pBuffer, unsigned BufferSize) { 287 | JLinkDLL_CALLPTR(P_JLINKARM_Core2CoreName, Core, pBuffer, BufferSize); 288 | } 289 | 290 | int JLINKARM_CP15_ReadEx(uint8_t CRn, uint8_t CRm, uint8_t op1, uint8_t op2, uint32_t *pData) { 291 | return JLinkDLL_CALLPTR(P_JLINKARM_CP15_ReadEx, CRn, CRm, op1, op2, pData); 292 | } 293 | 294 | int JLINKARM_CP15_WriteEx(uint8_t CRn, uint8_t CRm, uint8_t op1, uint8_t op2, uint32_t Data) { 295 | return JLinkDLL_CALLPTR(P_JLINKARM_CP15_WriteEx, CRn, CRm, op1, op2, Data); 296 | } 297 | 298 | int JLINKARM_DEVICE_GetIndex(const char *sDeviceName) { 299 | return JLinkDLL_CALLPTR(P_JLINKARM_DEVICE_GetIndex, sDeviceName); 300 | } 301 | 302 | int JLINKARM_DEVICE_SelectDialog(void *hParent, uint32_t Flags, JLINKARM_DEVICE_SELECT_INFO *pInfo) { 303 | return JLinkDLL_CALLPTR(P_JLINKARM_DEVICE_SelectDialog, hParent, Flags, pInfo); 304 | } 305 | 306 | int JLINK_DownloadFile(const char *sFileName, uint32_t Addr) { 307 | return JLinkDLL_CALLPTR(P_JLINK_DownloadFile, sFileName, Addr); 308 | } 309 | 310 | int JLINKARM_EMU_COM_Read(unsigned Channel, unsigned NumBytes, void *pData) { 311 | return JLinkDLL_CALLPTR(P_JLINKARM_EMU_COM_Read, Channel, NumBytes, pData); 312 | } 313 | 314 | int JLINKARM_EMU_COM_Write(unsigned Channel, unsigned NumBytes, const void *pData) { 315 | return JLinkDLL_CALLPTR(P_JLINKARM_EMU_COM_Write, Channel, NumBytes, pData); 316 | } 317 | 318 | int JLINKARM_EMU_COM_IsSupported(void) { 319 | return JLinkDLL_CALLPTR(P_JLINKARM_EMU_COM_IsSupported); 320 | } 321 | 322 | uint32_t JLINKARM_EMU_GetNumDevices(void) { 323 | return JLinkDLL_CALLPTR(P_JLINKARM_EMU_GetNumDevices); 324 | } 325 | 326 | void JLINKARM_EMU_GetProductName(char *pBuffer, uint32_t BufferSize) { 327 | JLinkDLL_CALLPTR(P_JLINKARM_EMU_GetProductName, pBuffer, BufferSize); 328 | } 329 | 330 | int JLINKARM_EMU_HasCapEx(int CapEx) { 331 | return JLinkDLL_CALLPTR(P_JLINKARM_EMU_HasCapEx, CapEx); 332 | } 333 | 334 | int JLINKARM_EMU_HasCPUCap(uint32_t CPUCap) { 335 | return JLinkDLL_CALLPTR(P_JLINKARM_EMU_HasCPUCap, CPUCap); 336 | } 337 | 338 | char JLINKARM_EMU_IsConnected(void) { 339 | return JLinkDLL_CALLPTR(P_JLINKARM_EMU_IsConnected); 340 | } 341 | 342 | void JLINKARM_EnableLog(JLINKARM_LOG *pfLog) { 343 | JLinkDLL_CALLPTR(P_JLINKARM_EnableLog, pfLog); 344 | } 345 | 346 | void JLINKARM_EnableLogCom(JLINKARM_LOG *pfLog) { 347 | JLinkDLL_CALLPTR(P_JLINKARM_EnableLogCom, pfLog); 348 | } 349 | 350 | int JLINKARM_EndDownload(void) { 351 | return JLinkDLL_CALLPTR(P_JLINKARM_EndDownload); 352 | } 353 | 354 | int JLINK_EraseChip(void) { 355 | return JLinkDLL_CALLPTR(P_JLINK_EraseChip); 356 | } 357 | 358 | const char *JLINKARM_GetCompileDateTime(void) { 359 | return JLinkDLL_CALLPTR(P_JLINKARM_GetCompileDateTime); 360 | } 361 | 362 | void JLINKARM_GetConfigData(int *pIRPre, int *pDRPre) { 363 | JLinkDLL_CALLPTR(P_JLINKARM_GetConfigData, pIRPre, pDRPre); 364 | } 365 | 366 | int JLINKARM_GetDebugInfo(uint32_t Index, uint32_t *pInfo) { 367 | return JLinkDLL_CALLPTR(P_JLINKARM_GetDebugInfo, Index, pInfo); 368 | } 369 | 370 | int JLINKARM_GetDeviceFamily(void) { 371 | return JLinkDLL_CALLPTR(P_JLINKARM_GetDeviceFamily); 372 | } 373 | 374 | uint32_t JLINKARM_GetEmuCaps(void) { 375 | return JLinkDLL_CALLPTR(P_JLINKARM_GetEmuCaps); 376 | } 377 | 378 | void JLINKARM_GetEmuCapsEx(uint8_t *pCaps, int BufferSize) { 379 | JLinkDLL_CALLPTR(P_JLINKARM_GetEmuCapsEx, pCaps, BufferSize); 380 | } 381 | 382 | void JLINKARM_GetFeatureString(char *pOut) { 383 | JLinkDLL_CALLPTR(P_JLINKARM_GetFeatureString, pOut); 384 | } 385 | 386 | void JLINKARM_GetFirmwareString(char *s, int BufferSize) { 387 | JLinkDLL_CALLPTR(P_JLINKARM_GetFirmwareString, s, BufferSize); 388 | } 389 | 390 | int JLINKARM_GetHWInfo(uint32_t BitMask, uint32_t *pHWInfo) { 391 | return JLinkDLL_CALLPTR(P_JLINKARM_GetHWInfo, BitMask, pHWInfo); 392 | } 393 | 394 | int JLINKARM_GetHWStatus(JLINKARM_HW_STATUS *pStat) { 395 | return JLinkDLL_CALLPTR(P_JLINKARM_GetHWStatus, pStat); 396 | } 397 | 398 | int JLINKARM_GetHardwareVersion(void) { 399 | return JLinkDLL_CALLPTR(P_JLINKARM_GetHardwareVersion); 400 | } 401 | 402 | void JLINKARM_GetIdData(JTAG_ID_DATA *pIdData) { 403 | JLinkDLL_CALLPTR(P_JLINKARM_GetIdData, pIdData); 404 | } 405 | 406 | int JLINKARM_GetMOEs(JLINKARM_MOE_INFO *pInfo, int MaxNumMOEs) { 407 | return JLinkDLL_CALLPTR(P_JLINKARM_GetMOEs, pInfo, MaxNumMOEs); 408 | } 409 | 410 | char JLINKARM_GetOEMString(char *pOut) { 411 | return JLinkDLL_CALLPTR(P_JLINKARM_GetOEMString, pOut); 412 | } 413 | 414 | int JLINKARM_GetScanLen(void) { 415 | return JLinkDLL_CALLPTR(P_JLINKARM_GetScanLen); 416 | } 417 | 418 | uint16_t JLINKARM_GetSelDevice(void) { 419 | return JLinkDLL_CALLPTR(P_JLINKARM_GetSelDevice); 420 | } 421 | 422 | int JLINKARM_GetSN(void) { 423 | return JLinkDLL_CALLPTR(P_JLINKARM_GetSN); 424 | } 425 | 426 | uint16_t JLINKARM_GetSpeed(void) { 427 | return JLinkDLL_CALLPTR(P_JLINKARM_GetSpeed); 428 | } 429 | 430 | void JLINKARM_GetSpeedInfo(JLINKARM_SPEED_INFO *pSpeedInfo) { 431 | JLinkDLL_CALLPTR(P_JLINKARM_GetSpeedInfo, pSpeedInfo); 432 | } 433 | 434 | char JLINKARM_HasError(void) { 435 | return JLinkDLL_CALLPTR(P_JLINKARM_HasError); 436 | } 437 | 438 | int JLINKARM_MeasureCPUSpeed(uint32_t RAMAddr, int PreserveMem) { 439 | return JLinkDLL_CALLPTR(P_JLINKARM_MeasureCPUSpeed, RAMAddr, PreserveMem); 440 | } 441 | 442 | int JLINKARM_MeasureCPUSpeedEx(uint32_t RAMAddr, int PreserveMem, int AllowFail) { 443 | return JLinkDLL_CALLPTR(P_JLINKARM_MeasureCPUSpeedEx, RAMAddr, PreserveMem, AllowFail); 444 | } 445 | 446 | int JLINKARM_MeasureSCLen(int ScanChain) { 447 | return JLinkDLL_CALLPTR(P_JLINKARM_MeasureSCLen, ScanChain); 448 | } 449 | 450 | void JLINKARM_SelDevice(uint16_t DeviceIndex) { 451 | JLinkDLL_CALLPTR(P_JLINKARM_SelDevice, DeviceIndex); 452 | } 453 | 454 | void JLINKARM_SelectTraceSource(int Source) { 455 | JLinkDLL_CALLPTR(P_JLINKARM_SelectTraceSource, Source); 456 | } 457 | 458 | int JLINKARM_SetEndian(int v) { 459 | return JLinkDLL_CALLPTR(P_JLINKARM_SetEndian, v); 460 | } 461 | 462 | void JLINKARM_SetErrorOutHandler(JLINKARM_LOG *pfErrorOut) { 463 | JLinkDLL_CALLPTR(P_JLINKARM_SetErrorOutHandler, pfErrorOut); 464 | } 465 | 466 | void JLINKARM_SetLogFile(const char *sFilename) { 467 | JLinkDLL_CALLPTR(P_JLINKARM_SetLogFile, sFilename); 468 | } 469 | 470 | void JLINKARM_SetMaxSpeed(void) { 471 | JLinkDLL_CALLPTR(P_JLINKARM_SetMaxSpeed); 472 | } 473 | 474 | void JLINKARM_SetRESET(void) { 475 | JLinkDLL_CALLPTR(P_JLINKARM_SetRESET); 476 | } 477 | 478 | void JLINKARM_SetSpeed(uint32_t Speed) { 479 | JLinkDLL_CALLPTR(P_JLINKARM_SetSpeed, Speed); 480 | } 481 | 482 | int JLINKARM_SetTCK(void) { 483 | return JLinkDLL_CALLPTR(P_JLINKARM_SetTCK); 484 | } 485 | 486 | void JLINKARM_SetTDI(void) { 487 | JLinkDLL_CALLPTR(P_JLINKARM_SetTDI); 488 | } 489 | 490 | void JLINKARM_SetTMS(void) { 491 | JLinkDLL_CALLPTR(P_JLINKARM_SetTMS); 492 | } 493 | 494 | void JLINKARM_SetTRST(void) { 495 | JLinkDLL_CALLPTR(P_JLINKARM_SetTRST); 496 | } 497 | 498 | void JLINKARM_StoreBits(uint32_t TMS, uint32_t TDI, int NumBits) { 499 | JLinkDLL_CALLPTR(P_JLINKARM_StoreBits, TMS, TDI, NumBits); 500 | } 501 | 502 | void JLINKARM_TIF_GetAvailable(uint32_t *pMask) { 503 | JLinkDLL_CALLPTR(P_JLINKARM_TIF_GetAvailable, pMask); 504 | } 505 | 506 | int JLINKARM_TIF_Select(int Interface) { 507 | return JLinkDLL_CALLPTR(P_JLINKARM_TIF_Select, Interface); 508 | } 509 | 510 | uint32_t JLINKARM_UpdateFirmwareIfNewer(void) { 511 | return JLinkDLL_CALLPTR(P_JLINKARM_UpdateFirmwareIfNewer); 512 | } 513 | 514 | void JLINKARM_SetWarnOutHandler(JLINKARM_LOG *pfWarnOut) { 515 | JLinkDLL_CALLPTR(P_JLINKARM_SetWarnOutHandler, pfWarnOut); 516 | } 517 | 518 | void JLINKARM_WriteBits(void) { 519 | JLinkDLL_CALLPTR(P_JLINKARM_WriteBits); 520 | } 521 | 522 | void *JLINK_GetpFunc(JLINK_FUNC_INDEX FuncIndex) { 523 | return JLinkDLL_CALLPTR(P_JLINK_GetpFunc, FuncIndex); 524 | } 525 | //PYTHON CHECK POINT 526 | 527 | //void JLINKARM_EMU_GetDeviceInfo(uint32_t iEmu, JLINKARM_EMU_INFO *pInfo) { 528 | // P_JLINKARM_EMU_GetDeviceInfo(iEmu, pInfo); 529 | //} 530 | 531 | int JLINKARM_ExecCommand(const char* sIn, char* sError, int BufferSize) { 532 | return JLinkDLL_CALLPTR(P_JLINKARM_ExecCommand, sIn, sError, BufferSize); 533 | } -------------------------------------------------------------------------------- /JLink/General/JLink_SystemControl.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file JLink_SystemControl.h 3 | * @author yao 4 | */ 5 | 6 | #ifndef JLINKDLL_JLINK_SYSTEMCONTROL_H 7 | #define JLINKDLL_JLINK_SYSTEMCONTROL_H 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | /** 16 | * This function returns the version of the DLL. 17 | * @return 32 bit DLL version number. The version number consists of major, minor and revision 18 | * number. In decimal representation, the version can be interpreted as follows: 19 | * Mmmrr, where 20 | * M is Major number 21 | * mm is minor number, 22 | * rr is revision number. 23 | */ 24 | uint32_t JLINKARM_GetDLLVersion(void); 25 | 26 | /** 27 | * This function sets the RESET pin of the J-Link target interface to LOW (asserts reset). 28 | */ 29 | void JLINKARM_ClrRESET(void); 30 | 31 | /** 32 | * Sets the TCK pin to LOW value. 33 | * @retval 0 Ok 34 | * @retval -1 Firmware of connected emulator does not support this feature 35 | */ 36 | int JLINKARM_ClrTCK(void); 37 | 38 | /** 39 | * This function clears the test data input, therefore the TDI is set to logical 0 (GND - common ground). 40 | */ 41 | void JLINKARM_ClrTDI(void); 42 | 43 | /** 44 | * This function clears the test mode select, therefore the TMS is set to logical 0 (GND - common ground). 45 | */ 46 | void JLINKARM_ClrTMS(void); 47 | 48 | /** 49 | * This function sets the TRST pin of the J-Link target interface to LOW (asserts TRST). 50 | */ 51 | void JLINKARM_ClrTRST(void); 52 | 53 | /** 54 | * This function clears the DLL internal error state. 55 | */ 56 | void JLINKARM_ClrError(void); 57 | 58 | /** 59 | * @deprecated Use {@link JLINKARM_EMU_GetList} instead. 60 | * Get USB enumeration specific information about a specific J-Link such as serial number 61 | * used by J-Link to enumerate on USB. 62 | */ 63 | //void JLINKARM_EMU_GetDeviceInfo(uint32_t iEmu, JLINKARM_EMU_INFO *pInfo); 64 | 65 | void JLINKARM_BeginDownload(uint32_t Flags); 66 | uint8_t JLINKARM_Clock(void); 67 | int JLINKARM_CORESIGHT_Configure(const char *sConfig); 68 | int JLINKARM_CORESIGHT_ReadAPDPReg(uint8_t RegIndex, uint8_t APnDP, uint32_t *pData); 69 | int JLINKARM_CORESIGHT_WriteAPDPReg(uint8_t RegIndex, uint8_t APnDP, uint32_t Data); 70 | void JLINKARM_Core2CoreName(uint32_t Core, char *pBuffer, unsigned BufferSize); 71 | int JLINKARM_CP15_ReadEx(uint8_t CRn, uint8_t CRm, uint8_t op1, uint8_t op2, uint32_t *pData); 72 | int JLINKARM_CP15_WriteEx(uint8_t CRn, uint8_t CRm, uint8_t op1, uint8_t op2, uint32_t Data); 73 | int JLINKARM_DEVICE_GetIndex(const char *sDeviceName); 74 | int JLINKARM_DEVICE_SelectDialog(void *hParent, uint32_t Flags, JLINKARM_DEVICE_SELECT_INFO *pInfo); 75 | int JLINK_DownloadFile(const char *sFileName, uint32_t Addr); 76 | int JLINKARM_EMU_COM_Read(unsigned Channel, unsigned NumBytes, void *pData); 77 | int JLINKARM_EMU_COM_Write(unsigned Channel, unsigned NumBytes, const void *pData); 78 | int JLINKARM_EMU_COM_IsSupported(void); 79 | void JLINKARM_EMU_GetProductName(char *pBuffer, uint32_t BufferSize); 80 | int JLINKARM_EMU_HasCapEx(int CapEx); 81 | int JLINKARM_EMU_HasCPUCap(uint32_t CPUCap); 82 | char JLINKARM_EMU_IsConnected(void); 83 | void JLINKARM_EnableLog(JLINKARM_LOG *pfLog); 84 | void JLINKARM_EnableLogCom(JLINKARM_LOG *pfLog); 85 | int JLINKARM_EndDownload(void); 86 | int JLINK_EraseChip(void); 87 | const char *JLINKARM_GetCompileDateTime(void); 88 | void JLINKARM_GetConfigData(int *pIRPre, int *pDRPre); 89 | int JLINKARM_GetDebugInfo(uint32_t Index, uint32_t *pInfo); 90 | int JLINKARM_GetDeviceFamily(void); 91 | uint32_t JLINKARM_GetEmuCaps(void); 92 | void JLINKARM_GetEmuCapsEx(uint8_t *pCaps, int BufferSize); 93 | void JLINKARM_GetFeatureString(char *pOut); 94 | void JLINKARM_GetFirmwareString(char *s, int BufferSize); 95 | int JLINKARM_GetHWInfo(uint32_t BitMask, uint32_t *pHWInfo); 96 | int JLINKARM_GetHWStatus(JLINKARM_HW_STATUS *pStat); 97 | int JLINKARM_GetHardwareVersion(void); 98 | void JLINKARM_GetIdData(JTAG_ID_DATA *pIdData); 99 | int JLINKARM_GetMOEs(JLINKARM_MOE_INFO *pInfo, int MaxNumMOEs); 100 | char JLINKARM_GetOEMString(char *pOut); 101 | int JLINKARM_GetScanLen(void); 102 | uint16_t JLINKARM_GetSelDevice(void); 103 | int JLINKARM_GetSN(void); 104 | uint16_t JLINKARM_GetSpeed(void); 105 | void JLINKARM_GetSpeedInfo(JLINKARM_SPEED_INFO * pSpeedInfo); 106 | char JLINKARM_HasError(void); 107 | int JLINKARM_MeasureCPUSpeed(uint32_t RAMAddr, int PreserveMem); 108 | int JLINKARM_MeasureCPUSpeedEx(uint32_t RAMAddr, int PreserveMem, int AllowFail); 109 | int JLINKARM_MeasureSCLen(int ScanChain); 110 | void JLINKARM_SelDevice(uint16_t DeviceIndex); 111 | void JLINKARM_SelectTraceSource (int Source); 112 | int JLINKARM_SetEndian(int v); 113 | void JLINKARM_SetErrorOutHandler(JLINKARM_LOG* pfErrorOut); 114 | void JLINKARM_SetLogFile (const char* sFilename); 115 | void JLINKARM_SetMaxSpeed(void); 116 | void JLINKARM_SetRESET(void); 117 | void JLINKARM_SetSpeed(uint32_t Speed); 118 | int JLINKARM_SetTCK(void); 119 | void JLINKARM_SetTDI(void); 120 | void JLINKARM_SetTMS(void); 121 | void JLINKARM_SetTRST(void); 122 | void JLINKARM_StoreBits(uint32_t TMS, uint32_t TDI, int NumBits); 123 | void JLINKARM_TIF_GetAvailable(uint32_t* pMask); 124 | int JLINKARM_TIF_Select(int Interface); 125 | uint32_t JLINKARM_UpdateFirmwareIfNewer(void); 126 | void JLINKARM_SetWarnOutHandler(JLINKARM_LOG* pfWarnOut); 127 | void JLINKARM_WriteBits(void); 128 | uint32_t JLINKARM_EMU_GetNumDevices(void); 129 | void *JLINK_GetpFunc(JLINK_FUNC_INDEX FuncIndex); 130 | 131 | int JLINKARM_ExecCommand(const char* sIn, char* sError, int BufferSize); 132 | 133 | // 缺少JLINKARM_RTCK_REACT_INFO定义,无法使用 134 | //int JLINKARM_MeasureRTCKReactTime(JLINKARM_RTCK_REACT_INFO* pReactInfo); 135 | 136 | // 弃用函数 137 | //void JLINKARM_EMU_GetDeviceInfo(uint32_t iEmu, JLINKARM_EMU_INFO *pInfo); 138 | 139 | 140 | #ifdef __cplusplus 141 | } 142 | #endif 143 | 144 | #endif //JLINKDLL_JLINK_SYSTEMCONTROL_H 145 | -------------------------------------------------------------------------------- /JLink/HSS/JLink_HSS.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yaoji on 2022/3/20. 3 | // 4 | 5 | #include "JLink_HSS.h" 6 | #include 7 | 8 | static int (*P_JLINK_HSS_Start)(JLINK_HSS_MEM_BLOCK_DESC *paDesc, int NumBlocks, int Period_us, int Flags); 9 | static int (*P_JLINK_HSS_Stop)(void); 10 | static int (*P_JLINK_HSS_Read)(void *pBuffer, uint32_t BufferSize); 11 | 12 | int JLINK_HSS_Init() { 13 | P_JLINK_HSS_Start = JLinkDLL_getSym("JLINK_HSS_Start"); 14 | if (P_JLINK_HSS_Start == NULL) return 0; 15 | P_JLINK_HSS_Stop = JLinkDLL_getSym("JLINK_HSS_Stop"); 16 | if (P_JLINK_HSS_Stop == NULL) return 0; 17 | P_JLINK_HSS_Read = JLinkDLL_getSym("JLINK_HSS_Read"); 18 | if (P_JLINK_HSS_Read == NULL) return 0; 19 | return 1; 20 | } 21 | //PYTHON CHECK POINT 22 | int JLINK_HSS_Start(JLINK_HSS_MEM_BLOCK_DESC *paDesc, int NumBlocks, int Period_us, int Flags) { 23 | return JLinkDLL_CALLPTR(P_JLINK_HSS_Start, paDesc, NumBlocks, Period_us, Flags); 24 | } 25 | 26 | int JLINK_HSS_Stop(void) { 27 | return JLinkDLL_CALLPTR(P_JLINK_HSS_Stop); 28 | } 29 | 30 | int JLINK_HSS_Read(void *pBuffer, uint32_t BufferSize) { 31 | return JLinkDLL_CALLPTR(P_JLINK_HSS_Read, pBuffer, BufferSize); 32 | } 33 | //PYTHON CHECK POINT -------------------------------------------------------------------------------- /JLink/HSS/JLink_HSS.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file JLink_HSS.h 3 | * @author yao 4 | */ 5 | 6 | #ifndef JLINKDLL_JLINK_HSS_H 7 | #define JLINKDLL_JLINK_HSS_H 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | int JLINK_HSS_Start(JLINK_HSS_MEM_BLOCK_DESC *paDesc, int NumBlocks, int Period_us, int Flags); 16 | int JLINK_HSS_Stop(void); 17 | int JLINK_HSS_Read(void *pBuffer, uint32_t BufferSize); 18 | 19 | #ifdef __cplusplus 20 | }; 21 | #endif 22 | 23 | #endif //JLINKDLL_JLINK_HSS_H 24 | -------------------------------------------------------------------------------- /JLink/JLink.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file JLink.h 3 | * @author yao 4 | */ 5 | 6 | #ifndef JLINKDLL_JLINK_H 7 | #define JLINKDLL_JLINK_H 8 | 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #endif //JLINKDLL_JLINK_H 25 | -------------------------------------------------------------------------------- /JLink/JLink_Define.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file JLink_Define.h 3 | * @author yao 4 | */ 5 | 6 | #ifndef JLINKDLL_JLINK_DEFINE_H 7 | #define JLINKDLL_JLINK_DEFINE_H 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | //typedef uint8_t U8; 16 | //typedef uint16_t U16; 17 | //typedef uint32_t U32; 18 | //typedef uint64_t U64; 19 | 20 | typedef void (*JLINKARM_LOG)(const char *sError); 21 | 22 | /** 23 | * @name JLINK_CORE_DEFINE 24 | * @brief JLink内核代码表 25 | * @{ 26 | */ 27 | #define JLINK_CORE_NONE (0x00000000U) 28 | #define JLINK_CORE_ANY (0xFFFFFFFFU) 29 | #define JLINK_CORE_CORTEX_M1 (0x010000FFU) 30 | #define JLINK_CORE_COLDFIRE (0x02FFFFFFU) 31 | #define JLINK_CORE_CORTEX_M3 (0x030000FFU) 32 | #define JLINK_CORE_CORTEX_M3_R1P0 (0x03000010U) 33 | #define JLINK_CORE_CORTEX_M3_R1P1 (0x03000011U) 34 | #define JLINK_CORE_CORTEX_M3_R2P0 (0x03000020U) 35 | #define JLINK_CORE_SIM (0x04FFFFFFU) 36 | #define JLINK_CORE_XSCALE (0x05FFFFFFU) 37 | #define JLINK_CORE_CORTEX_M0 (0x060000FFU) 38 | #define JLINK_CORE_ARM7 (0x07FFFFFFU) 39 | #define JLINK_CORE_ARM7TDMI (0x070000FFU) 40 | #define JLINK_CORE_ARM7TDMI_R3 (0x0700003FU) 41 | #define JLINK_CORE_ARM7TDMI_R4 (0x0700004FU) 42 | #define JLINK_CORE_ARM7TDMI_S (0x070001FFU) 43 | #define JLINK_CORE_ARM7TDMI_S_R3 (0x0700013FU) 44 | #define JLINK_CORE_ARM7TDMI_S_R4 (0x0700014FU) 45 | #define JLINK_CORE_CORTEX_A8 (0x080000FFU) 46 | #define JLINK_CORE_CORTEX_A7 (0x080800FFU) 47 | #define JLINK_CORE_CORTEX_A9 (0x080900FFU) 48 | #define JLINK_CORE_CORTEX_A12 (0x080A00FFU) 49 | #define JLINK_CORE_CORTEX_A15 (0x080B00FFU) 50 | #define JLINK_CORE_CORTEX_A17 (0x080C00FFU) 51 | #define JLINK_CORE_ARM9 (0x09FFFFFFU) 52 | #define JLINK_CORE_ARM9TDMI_S (0x090001FFU) 53 | #define JLINK_CORE_ARM920T (0x092000FFU) 54 | #define JLINK_CORE_ARM922T (0x092200FFU) 55 | #define JLINK_CORE_ARM926EJ_S (0x092601FFU) 56 | #define JLINK_CORE_ARM946E_S (0x094601FFU) 57 | #define JLINK_CORE_ARM966E_S (0x096601FFU) 58 | #define JLINK_CORE_ARM968E_S (0x096801FFU) 59 | #define JLINK_CORE_ARM11 (0x0BFFFFFFU) 60 | #define JLINK_CORE_ARM1136 (0x0B36FFFFU) 61 | #define JLINK_CORE_ARM1136J (0x0B3602FFU) 62 | #define JLINK_CORE_ARM1136J_S (0x0B3603FFU) 63 | #define JLINK_CORE_ARM1136JF (0x0B3606FFU) 64 | #define JLINK_CORE_ARM1136JF_S (0x0B3607FFU) 65 | #define JLINK_CORE_ARM1156 (0x0B56FFFFU) 66 | #define JLINK_CORE_ARM1176 (0x0B76FFFFU) 67 | #define JLINK_CORE_ARM1176J (0x0B7602FFU) 68 | #define JLINK_CORE_ARM1176J_S (0x0B7603FFU) 69 | #define JLINK_CORE_ARM1176JF (0x0B7606FFU) 70 | #define JLINK_CORE_ARM1176JF_S (0x0B7607FFU) 71 | #define JLINK_CORE_CORTEX_R4 (0x0C0000FFU) 72 | #define JLINK_CORE_CORTEX_R5 (0x0C0100FFU) 73 | #define JLINK_CORE_RX (0x0DFFFFFFU) 74 | #define JLINK_CORE_RX610 (0x0D00FFFFU) 75 | #define JLINK_CORE_RX62N (0x0D01FFFFU) 76 | #define JLINK_CORE_RX62T (0x0D02FFFFU) 77 | #define JLINK_CORE_RX63N (0x0D03FFFFU) 78 | #define JLINK_CORE_RX630 (0x0D04FFFFU) 79 | #define JLINK_CORE_RX63T (0x0D05FFFFU) 80 | #define JLINK_CORE_RX210 (0x0D10FFFFU) 81 | #define JLINK_CORE_RX111 (0x0D20FFFFU) 82 | #define JLINK_CORE_RX64M (0x0D30FFFFU) 83 | #define JLINK_CORE_CORTEX_M4 (0x0E0000FFU) 84 | #define JLINK_CORE_CORTEX_M7 (0x0E0100FFU) 85 | #define JLINK_CORE_CORTEX_A5 (0x0F0000FFU) 86 | #define JLINK_CORE_POWER_PC (0x10FFFFFFU) 87 | #define JLINK_CORE_POWER_PC_N1 (0x10FF00FFU) 88 | #define JLINK_CORE_POWER_PC_N2 (0x10FF01FFU) 89 | #define JLINK_CORE_MIPS (0x11FFFFFFU) 90 | #define JLINK_CORE_MIPS_M4K (0x1100FFFFU) 91 | #define JLINK_CORE_MIPS_MICROAPTIV (0x1101FFFFU) 92 | #define JLINK_CORE_EFM8_UNSPEC (0x12FFFFFFU) 93 | #define JLINK_CORE_CIP51 (0x1200FFFFU) 94 | /** @} */ 95 | 96 | #define JLINKARM_ERR_EMU_NO_CONNECTION (-256) 97 | #define JLINKARM_ERR_EMU_COMM_ERROR (-257) 98 | #define JLINKARM_ERR_DLL_NOT_OPEN (-258) 99 | #define JLINKARM_ERR_VCC_FAILURE (-259) 100 | #define JLINK_ERR_INVALID_HANDLE (-260) 101 | #define JLINK_ERR_NO_CPU_FOUND (-261) 102 | #define JLINK_ERR_EMU_FEATURE_NOT_SUPPORTED (-262) 103 | #define JLINK_ERR_EMU_NO_MEMORY (-263) 104 | #define JLINK_ERR_TIF_STATUS_ERROR (-264) 105 | 106 | #define JLINK_ERR_FLASH_PROG_COMPARE_FAILED (-265) //!<@brief Programmed data differs from source data. 107 | #define JLINK_ERR_FLASH_PROG_PROGRAM_FAILED (-266) //!<@brief Programming error occurred. 108 | #define JLINK_ERR_FLASH_PROG_VERIFY_FAILED (-267) //!<@brief Error while verifying programmed data. 109 | #define JLINK_ERR_OPEN_FILE_FAILED (-268) //!<@brief Specified file could not be opened. 110 | #define JLINK_ERR_UNKNOWN_FILE_FORMAT (-269) //!<@brief File format of selected file is not supported. 111 | #define JLINK_ERR_WRITE_TARGET_MEMORY_FAILED (-270) //!<@brief Could not write target memory. 112 | 113 | /** 114 | * When this flag is set and the current instruction is breakpointed, JLINKARM_GoEx() oversteps the breakpoint automatically 115 | * @bug TODO 值不确定 116 | */ 117 | #define JLINKARM_GO_OVERSTEP_BP 1 118 | 119 | typedef struct AREA_INFO { 120 | uint32_t Addr; 121 | uint32_t Size; 122 | } RAM_AREA_INFO, FLASH_AREA_INFO; 123 | 124 | typedef struct { 125 | uint32_t SizeOfStruct; //!<@brief Size of the struct. 126 | char *sName; //!<@brief This element holds the name of the device. 127 | uint32_t CoreId; //!<@brief This element holds the core id of the device. 128 | uint32_t FlashAddr; //!<@brief This element holds the base address of the internal flash of the device.o 129 | uint32_t RAMAddr; //!<@brief This element holds the base address of the internal RAM of the device. 130 | /** 131 | * 0: Supports only little endian. 132 | * 1: Supports only big endian. 133 | * 2: Supports little and big endian. 134 | */ 135 | char EndianMode; 136 | uint32_t FlashSize; //!<@brief Total FLASH size in bytes. Note: Flash may contain gaps. For exact address & size of each region, please refer to aFlashArea . 137 | uint32_t RAMSize; //!<@brief Total RAM size in bytes. Note: Ram may contain gaps. For exact address & size of each region, please refer to aRamArea . 138 | char *sManu; //!<@brief Device Manufacturer. 139 | FLASH_AREA_INFO aFlashArea; //!<@brief A list of FLASH_AREA_INFO. Region size of 0 bytes marks the end of the list. 140 | RAM_AREA_INFO aRamArea; //!<@brief A list of RAM_AREA_INFO. Region size of 0 bytes marks the end of the list. 141 | uint32_t Core; //!<@brief CPU core. (See JLINKARM_Const.h for a list of all core-defines e.g. {@link JLINK_CORE_CORTEX_M3}) 142 | } JLINKARM_DEVICE_INFO; 143 | 144 | typedef struct JLINKARM_DATA_EVENT { 145 | int SizeOfStruct; 146 | int Type; 147 | uint32_t Addr; 148 | uint32_t AddrMask; 149 | uint32_t Data; 150 | uint32_t DataMask; 151 | uint8_t Access; 152 | uint8_t AccessMask; 153 | } JLINKARM_DATA_EVENT; 154 | 155 | #define JLINK_EVENT_DATA_BP_DIR_RD (0 << 0) 156 | #define JLINK_EVENT_DATA_BP_DIR_WR (1 << 0) 157 | #define JLINK_EVENT_DATA_BP_PRIV (1 << 4) 158 | #define JLINK_EVENT_DATA_BP_SIZE_8BIT (0 << 1) 159 | #define JLINK_EVENT_DATA_BP_SIZE_16BIT (1 << 1) 160 | #define JLINK_EVENT_DATA_BP_SIZE_32BIT (2 << 1) 161 | 162 | #define JLINK_EVENT_DATA_BP_MASK_SIZE (3 << 1) 163 | #define JLINK_EVENT_DATA_BP_MASK_DIR (1 << 0) 164 | #define JLINK_EVENT_DATA_BP_MASK_PRIV (1 << 4) 165 | 166 | #define JLINKARM_EVENT_TYPE_DATA_BP (2) //!<@bug TODO 不确定 167 | 168 | #define JLINKARM_EVENT_ERR_UNKNOWN (0x80000000) 169 | #define JLINKARM_EVENT_ERR_NO_MORE_EVENTS (0x80000001) 170 | #define JLINKARM_EVENT_ERR_NO_MORE_ADDR_COMP (0x80000002) 171 | #define JLINKARM_EVENT_ERR_NO_MORE_DATA_COMP (0x80000004) 172 | #define JLINKARM_EVENT_ERR_INVALID_ADDR_MASK (0x80000020) 173 | #define JLINKARM_EVENT_ERR_INVALID_DATA_MASK (0x80000040) 174 | #define JLINKARM_EVENT_ERR_INVALID_ACCESS_MASK (0x80000080) 175 | 176 | /** 177 | * @bug TODO 值未知 178 | */ 179 | typedef enum { 180 | ARM_REG_R0, 181 | ARM_REG_R1, 182 | ARM_REG_R2, 183 | ARM_REG_R3, 184 | ARM_REG_R4, 185 | ARM_REG_R5, 186 | ARM_REG_R6, 187 | ARM_REG_R7, 188 | ARM_REG_R15, 189 | ARM_REG_CPSR, 190 | ARM_REG_R8_USR, 191 | ARM_REG_R9_USR, 192 | ARM_REG_R10_USR, 193 | ARM_REG_R11_USR, 194 | ARM_REG_R12_USR, 195 | ARM_REG_R13_USR, 196 | ARM_REG_R14_USR, 197 | ARM_REG_R13_SVC, 198 | ARM_REG_R14_SVC, 199 | ARM_REG_SPSR_SVC, 200 | ARM_REG_R13_ABT, 201 | ARM_REG_R14_ABT, 202 | ARM_REG_SPSR_ABT, 203 | ARM_REG_R13_UND, 204 | ARM_REG_R14_UND, 205 | ARM_REG_SPSR_UND, 206 | ARM_REG_R13_IRQ, 207 | ARM_REG_R14_IRQ, 208 | ARM_REG_SPSR_IRQ, 209 | ARM_REG_R8_FIQ, 210 | ARM_REG_R9_FIQ, 211 | ARM_REG_R10_FIQ, 212 | ARM_REG_R11_FIQ, 213 | ARM_REG_R12_FIQ, 214 | ARM_REG_R13_FIQ, 215 | ARM_REG_R14_FIQ, 216 | ARM_REG_SPSR_FIQ, 217 | ARM_NUM_REGS, 218 | } ARM_REG; 219 | 220 | typedef enum JLINK_FUNC_INDEX { 221 | JLINK_IFUNC_SET_HOOK_DIALOG_UNLOCK_IDCODE = 0, 222 | JLINK_IFUNC_SPI_TRANSFER_MULTIPLE, 223 | JLINK_IFUNC_PIN_OVERRIDE, 224 | JLINK_IFUNC_PIN_OVERRIDE_GET_PIN_CAPS, 225 | JLINK_IFUNC_MRU_GETLIST, 226 | JLINK_IFUNC_RESERVED3, 227 | JLINK_IFUNC_RESERVED4, 228 | JLINK_IFUNC_RESERVED5, 229 | JLINK_IFUNC_GET_SESSION_ID, 230 | JLINK_IFUNC_CORESIGHT_TRIGGER_READ_APDP_REG, 231 | JLINK_IFUNC_CAN_ACC_MEM_WHILE_RUNNING, 232 | JLINK_IFUNC_UPDATE_BTL, 233 | JLINK_IFUNC_GET_CURRENT_ENDIANESS, 234 | JLINK_IFUNC_ALGODB_GET_PALGO_INFO, 235 | JLINK_IFUNC_ALGODB_GET_PALGO_INFO_CFI, 236 | JLINK_IFUNC_ALGODB_GET_ALGO_NO, 237 | JLINK_IFUNC_PCODE_SET_ENTRY_FUNC, 238 | JLINK_IFUNC_PCODE_DOWNLOAD, 239 | JLINK_IFUNC_PCODE_EXEC_EX, 240 | JLINK_IFUNC_START_MERGE_COMMANDS, 241 | JLINK_IFUNC_END_MERGE_COMMANDS, 242 | JLINK_IFUNC_RAWTRACE_BIST_STARTSTOP, 243 | JLINK_IFUNC_RAWTRACE_BIST_READ_ERR_STATS, 244 | JLINK_IFUNC_GET_PF_GET_INST_INFO, 245 | JLINK_IFUNC_CORESIGHT_ACC_APDP_REG_MUL, 246 | JLINK_IFUNC_PCODE_DATA_DOWNLOAD, 247 | JLINK_IFUNC_PCODE_EXEC_EX2, 248 | JLINK_IFUNC_PCODE_FREE, 249 | JLINK_IFUNC_EMU_COMMANDLINE_WRITE_READ, 250 | JLINK_IFUNC_GET_PF_DISASSEMBLE_BUFFER, 251 | JLINK_IFUNC_EMU_GET_TARGET_IMG_AREA_INFO, 252 | JLINK_IFUNC_EMU_READ_TARGET_IMG_AREA, 253 | JLINK_IFUNC_EMU_WRITE_TARGET_IMG_AREA, 254 | JLINK_IFUNC_EMU_GET_CURR_CONN_INFO, 255 | JLINK_IFUNC_GET_PF_EXP_DEVICE_LIST_XML, 256 | JLINK_IFUNC_SCRIPTFILE_EXEC_FUNC, 257 | JLINK_IFUNC_EMU_ADD_FW_IMAGES, 258 | JLINK_NUM_FUNC_INDEXES, 259 | } JLINK_FUNC_INDEX; 260 | 261 | typedef struct JLINKARM_BP_INFO { 262 | /** Size of this structure. This element has to be filled in before calling the API function. */ 263 | uint32_t SizeOfStruct; 264 | 265 | /** Breakpoint handle. */ 266 | uint32_t Handle; 267 | 268 | /** Address where breakpoint has been set. */ 269 | uint32_t Addr; 270 | 271 | /** Type flags which has been specified when the breakpoint was set. */ 272 | uint32_t Type; 273 | 274 | /** 275 | * Describes the current implementation of the breakpoint. For more information 276 | * please refer to Implementation flags below. 277 | */ 278 | uint32_t ImpFlags; 279 | 280 | /** Describes how often the breakpoint is set at the same address. */ 281 | uint32_t UseCnt; 282 | } JLINKARM_BP_INFO; 283 | 284 | typedef struct JLINKARM_WP_INFO { 285 | uint32_t SizeOfStruct; //!<@brief Size of the struct 286 | uint32_t Handle; //!<@brief Watchpoint handle. 287 | uint32_t Addr; //!<@brief Contains the address on which watchpoint has been set. 288 | uint32_t AddrMask; //!<@brief Contains the address mask used for comparison. 289 | uint32_t Data; //!<@brief Contains the data on which watchpoint has been set. 290 | uint32_t DataMask; //!<@brief Contains data mask used for comparison. 291 | uint32_t Ctrl; //!<@brief Contains the control data on which breakpoint has been set (e.g. read access). 292 | uint32_t CtrlMask; //!<@brief Contains the control mask used for comparison. 293 | uint8_t WPUnit; //!<@brief Describes the watchpoint index. 294 | } JLINKARM_WP_INFO; 295 | 296 | typedef enum JLINKARM_BP_TYPE { 297 | 298 | /** Specifies a breakpoint in ARM mode. (Can not be used with JLINKARM_BP_TYPE_THUMB). */ 299 | JLINKARM_BP_TYPE_ARM = 1, 300 | 301 | /** Specifies a breakpoint in THUMB mode. (Can not be used with JLINKARM_BP_TYPE_ARM). */ 302 | JLINKARM_BP_TYPE_THUMB = 2, 303 | 304 | /** 305 | * Allows any type of implementation, software or any hardware unit. 306 | * This is the same as specifying JLINKARM_BP_IMP_SW | JLINKARM_BP_IMP_HW and is 307 | * also default if no Implementation flag is given. 308 | */ 309 | JLINKARM_BP_IMP_ANY = -16, 310 | 311 | /** Allows implementation as software breakpoint if the address is located in RAM or Flash. */ 312 | JLINKARM_BP_IMP_SW = 240, 313 | 314 | /** Allows implementation as software breakpoint if the address is located in RAM. */ 315 | JLINKARM_BP_IMP_SW_RAM = 16, 316 | 317 | /** Allows implementation as software breakpoint if the address is located in Flash. */ 318 | JLINKARM_BP_IMP_SW_FLASH = 32, 319 | 320 | /** Allows using of any hardware breakpoint unit. */ 321 | JLINKARM_BP_IMP_HW = -256, 322 | } JLINKARM_BP_TYPE; 323 | 324 | enum { 325 | JLINKARM_HALT_REASON_DBGRQ, //!<@brief CPU has been halted because DBGRQ signal has been asserted. 326 | JLINKARM_HALT_REASON_CODE_BREAKPOINT, //!<@brief CPU has been halted because of code breakpoint match. 327 | JLINKARM_HALT_REASON_DATA_BREAKPOINT, //!<@brief CPU has been halted because of data breakpoint match. 328 | JLINKARM_HALT_REASON_VECTOR_CATCH, //!<@brief CPU has been halted because of vector catch 329 | }; 330 | 331 | typedef struct JLINKARM_MOE_INFO { 332 | int HaltReason; 333 | int Index; 334 | } JLINKARM_MOE_INFO; 335 | 336 | typedef struct JLINKARM_EMU_CONNECT_INFO { 337 | /** 338 | * This is the serial number reported in the 339 | * discovery process. For J-Links which are 340 | * connected via USB this is the USB serial 341 | * number which is 342 | * 343 | * 1. the “true serial number” for newer JLinks 344 | * 345 | * 2. 123456 for older J-Links. 346 | * 347 | * For J-Links which are connected via TCP/IP 348 | * this is always the “true serial number”. 349 | */ 350 | uint32_t SerialNumber; 351 | 352 | /** 353 | * Connection type of the J-Link. Can be 354 | * {@link JLINKARM_HOSTIF_USB} or {@link JLINKARM_HOSTIF_IP}. 355 | */ 356 | uint32_t Connection; 357 | 358 | /** 359 | * USB Addr. Default is 0, values of 0..3 are 360 | * permitted. Only filled if for J-Links connected via USB. For J-Links which are connected via TCP/IP this field is zeroed. 361 | */ 362 | uint32_t USBAddr; 363 | 364 | /** 365 | * IP Addr. of the connected emulator in case 366 | * the emulator is connected via IP. For IP4 367 | * (current version), only the first 4 bytes are 368 | * used. The remaining bytes are zeroed. 369 | */ 370 | uint8_t aIPAddr[16]; 371 | 372 | /** 373 | * J-Link via IP only: Time period [ms] after 374 | * which the UDP discover answer from emulator was received 375 | * (-1 if emulator is connected over USB) 376 | */ 377 | int Time; 378 | 379 | /** 380 | * J-Link via IP only: Time period [us] after 381 | * which the UDP discover answer from emulator was received 382 | * (-1 if emulator is connected over USB) 383 | */ 384 | uint64_t Time_us; 385 | 386 | /** J-Link via IP only: Hardware version of JLink */ 387 | uint32_t HWVersion; 388 | 389 | /** J-Link via IP only: MAC Addr */ 390 | uint8_t abMACAddr; 391 | 392 | /** J-Link via IP only: Product name */ 393 | char acProduct[32]; 394 | 395 | /** J-Link via IP only: Nickname of J-Link */ 396 | char acNickName[32]; 397 | 398 | /** J-Link via IP only: Firmware string of JLink */ 399 | char acFWString[112]; 400 | 401 | /** J-Link via IP only: Is J-Link configured for IP address reception via DHCP? */ 402 | char IsDHCPAssignedIP; 403 | 404 | /** J-Link via IP only */ 405 | char IsDHCPAssignedIPIsValid; 406 | 407 | /** J-Link via IP only: Number of IP connections which are currently established to this J-Link */ 408 | char NumIPConnections; 409 | 410 | /** J-Link via IP only */ 411 | char NumIPConnectionsIsValid; 412 | 413 | /** Dummy bytes to pad the structure size to 264 bytes. Reserved for future use. */ 414 | char aPadding[34]; 415 | } JLINKARM_EMU_CONNECT_INFO; 416 | 417 | 418 | // 弃用结构体,结构未知 419 | //typedef struct JLINKARM_EMU_INFO { 420 | // 421 | //} JLINKARM_EMU_INFO; 422 | 423 | /** 424 | * 425 | */ 426 | typedef struct JLINK_MEM_ZONE_INFO { 427 | uint16_t VTarget; //!<@brief Target supply voltage. 428 | const char *sName; //!<@brief Initials of the memory zone. 429 | const char *sDesc; //!<@brief Name of the memory zone. 430 | uint64_t VirtAddr; //!<@brief Start address of the virtual address space of the memory zone. 431 | uint8_t abDummy[16]; //!<@brief Reserved for future use. 432 | } JLINK_MEM_ZONE_INFO; 433 | 434 | /** 435 | * Refer to the J-Link / J-Trace User Guide, 436 | * section Reset strategies in chapter Working with J-Link and J-Trace for detailed 437 | * information about the different reset 438 | * strategies. Default value is JLINKARM_RESET_TYPE_NORMAL. 439 | * 440 | * Refer to the J-Link / J-Trace User Guide, 441 | * section Reset strategies in chapter Working with J-Link and J-Trace for detailed 442 | * information about the different reset 443 | * strategies. Default value is JLINKARM_CM3_RESET_TYPE_NORMAL. 444 | * 445 | * @bug TODO JLINKARM_RESET_TYPE的值不确定,JLINKARM_CM3_RESET_TYPE已经确定 446 | */ 447 | typedef enum { 448 | // ARM7/ ARM9 449 | JLINKARM_RESET_TYPE_NORMAL, 450 | JLINKARM_RESET_TYPE_BP0, 451 | JLINKARM_RESET_TYPE_ADI, 452 | JLINKARM_RESET_TYPE_NO_RESET, 453 | JLINKARM_RESET_TYPE_HALT_WP, 454 | JLINKARM_RESET_TYPE_HALT_DBGRQ, 455 | JLINKARM_RESET_TYPE_SOFT, 456 | JLINKARM_RESET_TYPE_SAM7, 457 | 458 | // Cortex-M specifics 459 | JLINKARM_CM3_RESET_TYPE_NORMAL = 0, 460 | JLINKARM_CM3_RESET_TYPE_CORE = 1, 461 | JLINKARM_CM3_RESET_TYPE_RESETPIN = 2, 462 | JLINKARM_CM3_RESET_TYPE_CONNECT_UNDER_RESET = 3, 463 | JLINKARM_CM3_RESET_TYPE_HALT_AFTER_BTL = 4, 464 | JLINKARM_CM3_RESET_TYPE_HALT_BEFORE_BTL = 5, 465 | JLINKARM_CM3_RESET_TYPE_KINETIS = 6, 466 | JLINKARM_CM3_RESET_TYPE_ADI_HALT_AFTER_KERNEL = 7, 467 | JLINKARM_CM3_RESET_TYPE_CORE_AND_PERIPHERALS = 8, 468 | JLINKARM_CM3_RESET_TYPE_LPC1200 = 9, 469 | JLINKARM_CM3_RESET_TYPE_S3FN60D = 10, 470 | } JLINKARM_RESET_TYPE; 471 | 472 | typedef struct JLINKARM_JTAG_DEVICE_CONF { 473 | uint32_t SizeofStruct; 474 | uint32_t IRLen; 475 | uint32_t IRPrint; 476 | uint32_t Id; 477 | const char *sName; 478 | } JLINKARM_JTAG_DEVICE_CONF; 479 | 480 | typedef struct JLINKARM_JTAG_DEVICE_INFO { 481 | const char *sName; 482 | uint32_t IRLen; 483 | uint32_t IRPrint; 484 | } JLINKARM_JTAG_DEVICE_INFO; 485 | 486 | /** 487 | * This structure is used to configure SWO when calling the {@link JLINKARM_SWO_Control} function 488 | * with command JLINKARM_SWO_CMD_START. 489 | */ 490 | typedef struct JLINKARM_SWO_START_INFO { 491 | /** 492 | * Size of structure. This value must be filled by the application 493 | * and is used to allow future extension of the structure 494 | */ 495 | uint32_t SizeofStruct; 496 | 497 | /** Specifies the interface type to be used for SWO. */ 498 | uint32_t Interface; 499 | 500 | /** Selects the frequency used for SWO communication in Hz. */ 501 | uint32_t Speed; 502 | } JLINKARM_SWO_START_INFO; 503 | 504 | /** 505 | * This structure is used to retrieve information about the supported SWO speeds. 506 | */ 507 | typedef struct JLINKARM_SWO_SPEED_INFO { 508 | /** 509 | * Size of structure. This value must be filled by the application 510 | * and is used to allow future extension of the structure. 511 | */ 512 | uint32_t SizeofStruct; 513 | 514 | /** 515 | * Specifies the interface type for which the speed information 516 | * should be retrieved. 517 | */ 518 | uint32_t Interface; 519 | 520 | /** Base frequency (in Hz) used to calculate supported SWO speeds. */ 521 | uint32_t BaseFreq; 522 | 523 | /** Minimum divider allowed to divide the base frequency. */ 524 | uint32_t MinDiv; 525 | 526 | /** Maximum divider allowed to divide the base frequency. */ 527 | uint32_t MaxDiv; 528 | 529 | /** Minimum prescaler allowed to adjust the base frequency. */ 530 | uint32_t MinPrescale; 531 | 532 | /** Maximum prescaler allowed to adjust the base frequency. */ 533 | uint32_t MaxPrescale; 534 | } JLINKARM_SWO_SPEED_INFO; 535 | 536 | enum JLINKARM_SWO_IF { 537 | JLINKARM_SWO_IF_UART = 0, //!<@brief Selects UART encoding. 538 | JLINKARM_SWO_IF_MANCHESTER = 1, //!<@warning DO NOT USE 539 | }; 540 | 541 | enum JLINKARM_SWO_CMD { 542 | /** 543 | * Starts collecting SWO data. 544 | * pData is a pointer to a structure of type 545 | * JLINKARM_SWO_START_INFO. For more detailed information please refer to JLINKARM_SWO_START_INFO on page 262. 546 | */ 547 | JLINKARM_SWO_CMD_START = 0, 548 | 549 | /** 550 | * Stops collecting SWO data. 551 | * pData is not used. 552 | */ 553 | JLINKARM_SWO_CMD_STOP = 1, 554 | 555 | /** 556 | * Flushes data from the SWO buffer. After this operation, 557 | * the flushed part of the SWO buffer is empty. 558 | * pData is a pointer to an uint32_t value containing the number of bytes to be flushed. 559 | */ 560 | JLINKARM_SWO_CMD_FLUSH = 2, 561 | 562 | /** 563 | * Retrieves information about the supported SWO speeds. 564 | * pData is a pointer to a structure of type JLINKARM_SWO_SPEED_INFO. 565 | * @see JLINKARM_SWO_SPEED_INFO 566 | */ 567 | JLINKARM_SWO_CMD_GET_SPEED_INFO = 3, 568 | 569 | /** 570 | * Returns the number of bytes in the SWO buffer. 571 | * pData is not used. 572 | */ 573 | JLINKARM_SWO_CMD_GET_NUM_BYTES = 10, 574 | 575 | /** 576 | * Sets the size of buffer used by the host to collect SWO data. 577 | * By default this value is set to 4MB. 578 | * pData is a pointer to an uint32_t value containing the new buffersize. 579 | */ 580 | JLINKARM_SWO_CMD_SET_BUFFERSIZE_HOST = 20, 581 | 582 | /** 583 | * Sets the size of buffer used by the emulator to collect SWO data. 584 | * By default this value is set to 4KB. 585 | * pData is a pointer to an uint32_t value containing the new buffersize. 586 | */ 587 | JLINKARM_SWO_CMD_SET_BUFFERSIZE_EMU = 21, 588 | }; 589 | 590 | typedef struct JLINK_RTTERMINAL_START { 591 | /** Address of RTT block */ 592 | uint32_t ConfigBlockAddress; 593 | uint32_t Dummy0; 594 | uint32_t Dummy1; 595 | uint32_t Dummy2; 596 | } JLINK_RTTERMINAL_START; 597 | 598 | typedef struct JLINK_RTTERMINAL_STOP { 599 | /** If set, RTTCB will be invalidated on target. */ 600 | uint8_t InvalidateTargetCB; 601 | uint8_t acDummy[3]; 602 | uint32_t Dummy0; 603 | uint32_t Dummy1; 604 | uint32_t Dummy2; 605 | } JLINK_RTTERMINAL_STOP; 606 | 607 | typedef struct JLINK_RTTERMINAL_BUFDESC { 608 | int BufferIndex; //!<@brief In: Index of the buffer to get info about. 609 | uint32_t Direction; //!<@brief In: Direction of the buffer. (0 = Up; 1 = Down) 610 | char acName[32]; //!<@brief Out: Array for the 0-terminated name of the buffer. 611 | uint32_t SizeOfBuffer; //!<@brief Out: Size of the buffer on the target. 612 | uint32_t Flags; //!<@brief Out: Flags of the buffer. 613 | } JLINK_RTTERMINAL_BUFDESC; 614 | 615 | enum JLINKARM_RTTERMINAL_CMD { 616 | JLINKARM_RTTERMINAL_CMD_START = 0, //!<@brief Starts RTT processing. This includes background read of RTT data from target. p may be NULL. 617 | JLINKARM_RTTERMINAL_CMD_STOP = 1, //!<@brief Stops RTT on the J-Link and host side. p may be NULL. 618 | JLINKARM_RTTERMINAL_CMD_GETDESC = 2, //!<@brief Get the size, name, and flag of a buffer. 619 | JLINKARM_RTTERMINAL_CMD_GETNUMBUF = 3, //!<@brief After starting RTT, get the current number of up or down buffers. 620 | JLINKARM_RTTERMINAL_CMD_GETSTAT = 4, 621 | }; 622 | 623 | enum JLINKARM_DEV_FAMILY { 624 | JLINKARM_DEV_FAMILY_CM0 = 6, //!<@brief Target CPU/MCU is a Cortex-M0 device. 625 | JLINKARM_DEV_FAMILY_CM1 = 1, //!<@brief Target CPU/MCU is a Cortex-M1 device. 626 | JLINKARM_DEV_FAMILY_CM3 = 3, //!<@brief Target CPU/MCU is a Cortex-M3 device. 627 | JLINKARM_DEV_FAMILY_CORTEX_R4 = 12, //!<@brief Target CPU/MCU is an Cortex-R4 core. 628 | JLINKARM_DEV_FAMILY_SIM = 4, //!<@brief Target CPU/MCU simulator. 629 | JLINKARM_DEV_FAMILY_XSCALE = 5, //!<@brief Target CPU/MCU is a XScale device. 630 | JLINKARM_DEV_FAMILY_ARM7 = 7, //!<@brief Target CPU/MCU is an ARM7 device. 631 | JLINKARM_DEV_FAMILY_ARM9 = 9, //!<@brief Target CPU/MCU is a ARM9 device. 632 | JLINKARM_DEV_FAMILY_ARM10 = 10, //!<@brief Target CPU/MCU is a ARM10 device. 633 | JLINKARM_DEV_FAMILY_ARM11 = 11, //!<@brief Target CPU/MCU is an ARM11 core. 634 | }; 635 | 636 | typedef struct JLINKARM_DEVICE_SELECT_INFO { 637 | /** Size of this structure. This element has to be filled in before calling the API function. */ 638 | uint32_t SizeOfStruct; 639 | 640 | /** Will be set to the core index selected by the user (default 0). */ 641 | uint32_t CoreIndex; 642 | } JLINKARM_DEVICE_SELECT_INFO; 643 | 644 | enum JLINKARM_HW_PIN_STATUS { 645 | /** Measured state of pin is low (logical 0). */ 646 | JLINKARM_HW_PIN_STATUS_LOW = 0, 647 | 648 | /** Measured state of pin is high (logical 1). */ 649 | JLINKARM_HW_PIN_STATUS_HIGH = 1, 650 | 651 | /** Pin state could not be measured. Measuring JTAG pin state is not supported by JLink / J-Trace. */ 652 | JLINKARM_HW_PIN_STATUS_UNKNOWN = 255, 653 | }; 654 | 655 | 656 | typedef struct JLINKARM_HW_STATUS { 657 | /** Target supply voltage. */ 658 | uint16_t VTarget; 659 | 660 | /** Measured state of TCK pin. The valid values for the pin state are described below. */ 661 | uint8_t tck; 662 | 663 | /** Measured state of TDI pin. The valid values for the pin state are described below. */ 664 | uint8_t tdi; 665 | 666 | /** Measured state of TDO pin. The valid values for the pin state are described below. */ 667 | uint8_t tdo; 668 | 669 | /** Measured state of TMS pin. The valid values for the pin state are described below. */ 670 | uint8_t tms; 671 | 672 | /** Measured state of TRES pin. The valid values for the pin state are described below. */ 673 | uint8_t tres; 674 | 675 | /** Measured state of TRST pin. The valid values for the pin state are described below. */ 676 | uint8_t trst; 677 | } JLINKARM_HW_STATUS; 678 | 679 | typedef struct JTAG_ID_DATA { 680 | /** Number of devices in this scan chain */ 681 | int NumDevices; 682 | 683 | /** Total Number of bits in all scan chain select registers */ 684 | uint16_t ScanLen; 685 | 686 | /** JTAG ID of device */ 687 | uint32_t aId[3]; 688 | 689 | /** Number of bits in individual scan chain select registers */ 690 | uint8_t aScanLen[3]; 691 | 692 | /** Data read back from instruction register */ 693 | uint8_t aIrRead[3]; 694 | 695 | /** Data read back from scan chain select register */ 696 | uint8_t aScanRead[3]; 697 | } JTAG_ID_DATA; 698 | 699 | typedef struct JLINKARM_SPEED_INFO { 700 | 701 | /** Size of this structure. This element has to be filled in before calling the API function. */ 702 | uint32_t SizeOfStruct; 703 | 704 | /** Base frequency (in Hz) used to calculate supported target interface speeds. */ 705 | uint32_t BaseFreq; 706 | 707 | /** Minimum divider allowed to divide the base frequency. */ 708 | uint16_t MinDiv; 709 | 710 | /** Indicates whether the emulator supports adaptive clocking or not. */ 711 | uint16_t SupportAdaptive; 712 | } JLINKARM_SPEED_INFO; 713 | 714 | typedef struct JLINK_HSS_MEM_BLOCK_DESC { 715 | /** Address that shall be read from when sampling. */ 716 | uint32_t Addr; 717 | 718 | /** Number of bytes that shall be read when sampling. */ 719 | uint32_t NumBytes; 720 | 721 | /** SBZ. Reserved for future use. */ 722 | uint32_t Flags; 723 | 724 | /** SBZ. Reserved for future use. */ 725 | uint32_t Dummy; 726 | } JLINK_HSS_MEM_BLOCK_DESC; 727 | 728 | enum JLINK_POWERTRACE_CMD { 729 | /** Setup the POWERTRACE functionality. */ 730 | JLINK_POWERTRACE_CMD_SETUP, 731 | 732 | /** Starts capturing measurement data. */ 733 | JLINK_POWERTRACE_CMD_START, 734 | 735 | /** Flush POWERTRACE data buffer. Any data which has not been read is lost. */ 736 | JLINK_POWERTRACE_CMD_FLUSH, 737 | 738 | /** Stops capturing measurement data. */ 739 | JLINK_POWERTRACE_CMD_STOP, 740 | 741 | /** Get POWERTRACE capabilities of the connected emulator. */ 742 | JLINK_POWERTRACE_CMD_GET_CAPS, 743 | 744 | /** Get capabilities of a specific measurement channel. */ 745 | JLINK_POWERTRACE_CMD_GET_CHANNEL_CAPS, 746 | 747 | /** Get the number of POWERTRACE items which are available to read. */ 748 | JLINK_POWERTRACE_CMD_GET_NUM_ITEMS, 749 | }; 750 | 751 | typedef struct JLINK_POWERTRACE_SETUP { 752 | /** 753 | * Size of this structure. Needs to be filled by 754 | * the user. Used for backward-compatibility 755 | * if the structure is enhanced in future versions. 756 | */ 757 | int SizeofStruct; 758 | 759 | /** 760 | * Bitmask to setup which channels shall be 761 | * enabled for capturing data. 762 | * 763 | * - Bits 0-7: Internal channel 0-7 764 | * 765 | * - Bits 8-31: Reserved 766 | * 767 | * If a bit is 1, the corresponding channel is enabled. 768 | * If it is set to 0, the corresponding channel is disabled. 769 | */ 770 | uint32_t ChannelMask; 771 | 772 | /** 773 | * Sampling frequency in Hz. Please note that 774 | * the maximum sample frequency which can 775 | * be used depends on the number of channels which are enabled. 776 | * For more information about how to determine the maximum sampling 777 | * frequency for your configuration 778 | * @see JLINK_POWERTRACE_CMD_GET_CHANNEL_CAPS 779 | */ 780 | uint32_t SampleFreq; 781 | 782 | /** 783 | * Reference value which shall be stored for 784 | * every sampled value. 785 | * 786 | * 0: No reference value is stored 787 | * 788 | * 1: Number of bytes transferred via SWO 789 | * since capturing has been started. Only 790 | * available for ARM Cortex-M devices which 791 | * support SWO. 792 | * 793 | * 2: Number of miliseconds elapsed, since 794 | * powertrace capturing has been started. 795 | */ 796 | int RefSelect; 797 | 798 | /** 799 | * Capturing enable condition. 800 | * 801 | * 0: Data is always captured, even if the CPU is halted. Capturing is only 802 | * stopped when receiving a JLINK_POWERTRACE_CMD_STOP command. 803 | * 804 | * 1: Data is only captured while the CPU is running 805 | */ 806 | int EnableCond; 807 | } JLINK_POWERTRACE_SETUP; 808 | 809 | typedef struct JLINK_POWERTRACE_DATA_ITEM { 810 | /** 811 | * Reference value (can be used to correlate 812 | * the measured value to the time when it 813 | * has been measured), if enabled. For more 814 | * information about how to setup the POWERTRACE functionality to store a reference value, 815 | * @see JLINK_POWERTRACE_CMD_SETUP 816 | */ 817 | uint32_t RefValue; 818 | 819 | /** 820 | * Measured data. 821 | * Reserved for future use. Currently 0. 822 | */ 823 | uint32_t Data; 824 | } JLINK_POWERTRACE_DATA_ITEM; 825 | 826 | enum JLINK_STRACE_CMD { 827 | JLINK_STRACE_CMD_SET_TRACE_EVENT = 0, 828 | JLINK_STRACE_CMD_CLR_TRACE_EVENT = 1, 829 | JLINK_STRACE_CMD_CLR_ALL_TRACE_EVENTS = 2, 830 | JLINK_STRACE_CMD_SET_BUFF_SIZE = 3, 831 | }; 832 | 833 | enum JLINK_STRACE_EVENT_TYPE { 834 | /** 835 | * Specifies code fetch event, meaning the 836 | * trace logic validates the event condition 837 | * (see Op ) when an instruction is fetched. 838 | */ 839 | JLINK_STRACE_EVENT_TYPE_CODE_FETCH, 840 | 841 | /** 842 | * Specifies code fetch event, meaning the 843 | * trace logic validates the event condition 844 | * (see Op ) when a data access (read or 845 | * write) is made. 846 | */ 847 | JLINK_STRACE_EVENT_TYPE_DATA_ACC, 848 | 849 | /** 850 | * Specifies code fetch event, meaning the 851 | * trace logic validates the event condition (see Op ) 852 | * when a data read access is made. 853 | */ 854 | JLINK_STRACE_EVENT_TYPE_DATA_LOAD, 855 | 856 | /** 857 | * Specifies code fetch event, meaning the 858 | * trace logic validates the event condition 859 | * (see Op ) when a data write access is made. 860 | */ 861 | JLINK_STRACE_EVENT_TYPE_DATA_STORE, 862 | }; 863 | 864 | enum JLINK_STRACE_OP_TRACE { 865 | JLINK_STRACE_OP_TRACE_START, 866 | JLINK_STRACE_OP_TRACE_STOP, 867 | JLINK_STRACE_OP_TRACE_INCLUDE_RANGE, 868 | JLINK_STRACE_OP_TRACE_EXCLUDE_RANGE, 869 | }; 870 | 871 | typedef struct JLINK_STRACE_EVENT_INFO { 872 | uint32_t SizeofStruct; 873 | 874 | /** 875 | * Specifies the type of the event. Meaning 876 | * when does the trace logic evaluate the 877 | * event condition. 878 | * @see JLINK_STRACE_EVENT_TYPE 879 | */ 880 | uint8_t Type; 881 | 882 | /** 883 | * Specifies the operation (start/stop/include/exclude trace) 884 | * @see JLINK_STRACE_OP_TRACE 885 | */ 886 | uint8_t Op; 887 | 888 | /** Used for data access trace events only. */ 889 | uint8_t AccessSize; 890 | 891 | /** Reserved for future use and to align following elements. */ 892 | uint8_t Reserved0; 893 | 894 | /** 895 | * For data events this specifies the load/ 896 | * store address of the data. 897 | * For code events this specifies the address 898 | * of the instruction that is fetched/executed. 899 | */ 900 | uint64_t Addr; 901 | 902 | /** 903 | * Specifies the data to be compared to. Used 904 | * for types JLINK_STRACE_EVENT_TYPE_DATA_ACC only 905 | */ 906 | uint64_t Data; 907 | 908 | /** 909 | * Bits set to 1 are masked out, so not taken 910 | * into consideration during comparison. 911 | * Used for Types JLINK_STRACE_EVENT_TYPE_DATA_ACC only 912 | */ 913 | uint64_t DataMask; 914 | 915 | /** 916 | * Specifies the address range for the event. 917 | * Used for operations JLINK_STRACE_OP_TRACE_INCLUDE_RANGE and 918 | * JLINK_STRACE_OP_TRACE_EXCLUDE_RANGE 919 | * only. 920 | * Set to 0 in all other cases. 921 | */ 922 | uint64_t AddrRangeSize; 923 | } JLINK_STRACE_EVENT_INFO; 924 | 925 | enum JLINKARM_TIF { 926 | JLINKARM_TIF_JTAG = 0, 927 | JLINKARM_TIF_SWD = 1, 928 | JLINKARM_TIF_FINE = 3, 929 | JLINKARM_TIF_ICSP = 4, 930 | JLINKARM_TIF_SPI = 5, 931 | JLINKARM_TIF_C2 = 6, 932 | }; 933 | 934 | #ifdef __cplusplus 935 | } 936 | #endif 937 | 938 | #endif //JLINKDLL_JLINK_DEFINE_H 939 | -------------------------------------------------------------------------------- /JLink/JLink_Init.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yaoji on 2022/3/18. 3 | // 4 | 5 | #include "JLink_Init.h" 6 | 7 | #ifdef Linux 8 | #define DL_OPEN(PATH) dlopen() 9 | #define DL_SYM(HANDEL, NAME) dlsym 10 | #define DL_HANDEL void * 11 | //#ifndef JLINK_LIB_PATH 12 | //#if _WIN64 13 | //#define JLINK_LIB_PATH "JLink_x64.dll" 14 | //#else 15 | //#define JLINK_LIB_PATH "JLinkARM.dll" 16 | //#endif 17 | //#endif 18 | #else 19 | #include 20 | #include 21 | #define DL_OPEN(PATH) LoadLibrary(PATH) 22 | #define DL_FREE(HANDEL) FreeLibrary(HANDEL) 23 | #define DL_SYM(HANDEL, NAME) GetProcAddress(HANDEL, NAME) 24 | #define DL_HANDEL HINSTANCE 25 | #ifndef JLINK_LIB_PATH 26 | #if _WIN64 27 | #define JLINK_LIB_PATH "JLink_x64.dll" 28 | #else 29 | #define JLINK_LIB_PATH "JLinkARM.dll" 30 | #endif 31 | #endif 32 | #endif 33 | 34 | 35 | #define INIT_MODULE(MODULE) \ 36 | int JLINK_##MODULE##_Init(); \ 37 | if (!JLINK_##MODULE##_Init()) return 0; 38 | 39 | static DL_HANDEL handel; 40 | static uint32_t fun_num; 41 | static int dbgOut_enable; 42 | 43 | void *JLinkDLL_getSym(const char *sym) { 44 | void *p = DL_SYM(handel, sym); 45 | if (p) { 46 | fun_num++; 47 | if (dbgOut_enable) { 48 | printf("Loaded '%s' at %p, Relative address %llX\n", 49 | sym, p, ((uint64_t) p - (uint64_t) handel)); 50 | } 51 | } else { 52 | printf("Error: load '%s' failed\n", sym); 53 | } 54 | return p; 55 | } 56 | 57 | int JLinkDLL_Init(const char *dl_path) { 58 | if (handel == NULL) { 59 | if (dl_path == NULL) { 60 | dl_path = JLINK_LIB_PATH; 61 | } 62 | handel = DL_OPEN(dl_path); 63 | if (handel == NULL) return 0; 64 | if (dbgOut_enable) { 65 | printf("Loaded DLL '%s' at %p\n", dl_path, handel); 66 | } 67 | INIT_MODULE(RTT) 68 | INIT_MODULE(General) 69 | INIT_MODULE(JTAG) 70 | INIT_MODULE(SWO) 71 | INIT_MODULE(HSS) 72 | INIT_MODULE(SPI) 73 | INIT_MODULE(STRACE) 74 | INIT_MODULE(POWERTRACE) 75 | INIT_MODULE(SWD) 76 | } 77 | if (dbgOut_enable) { 78 | printf("%d functions are loaded\n", fun_num); 79 | } 80 | return 1; 81 | } 82 | 83 | int JLinkDLL_DeInit() { 84 | if (handel) { 85 | int ret = DL_FREE(handel); 86 | handel = NULL; 87 | return ret; 88 | } 89 | return 1; 90 | } 91 | 92 | int JLinkDLL_Error(const char *fun_name, const char *filename, int line) { 93 | fprintf(stderr, "Error: function %s, in %s:%d\n", fun_name, filename, line); 94 | JLinkDLL_DeInit(); 95 | exit(EXIT_FAILURE); 96 | return 0; 97 | } 98 | 99 | void JLinkDLL_SetDebugOutput(int enable) { 100 | dbgOut_enable = enable; 101 | } 102 | -------------------------------------------------------------------------------- /JLink/JLink_Init.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file JLinkDLL_Init.h 3 | * @author yao 4 | */ 5 | 6 | #ifndef JLINKDLL_JLINK_INIT_H 7 | #define JLINKDLL_JLINK_INIT_H 8 | 9 | #include 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #define JLinkDLL_CALLPTR(PTR, ...) ((PTR == NULL) ? \ 15 | (JLinkDLL_Init(NULL) ? PTR(__VA_ARGS__) : (JLinkDLL_Error(__FUNCTION__, __FILE__, __LINE__), PTR(__VA_ARGS__))) : PTR(__VA_ARGS__)) 16 | 17 | /** 18 | * 初始化动态加载库 19 | * @param dl_path JLink共享库路径,传入NULL使用内置共享库 20 | * @retval 0 失败 21 | * @retval 1 成功 22 | */ 23 | int JLinkDLL_Init(const char *dl_path); 24 | 25 | /** 26 | * 获取符号,需要先使用{@link JLinkDLL_Init}加载库 27 | * @param sym 符号名 28 | * @return 符号指针 29 | */ 30 | void *JLinkDLL_getSym(const char *sym); 31 | 32 | /** 33 | * 释放动态库 34 | */ 35 | int JLinkDLL_DeInit(); 36 | 37 | /** 38 | * JLink错误处理函数,该函数会直接退出程序,用户不应调用 39 | * @param fun_name 出错函数名 40 | * @param filename 文件名 41 | * @param line 所在行 42 | * @return 0 43 | */ 44 | int JLinkDLL_Error(const char *fun_name, const char *filename, int line); 45 | 46 | /** 47 | * 设置调试输出,默认关闭 48 | * @param enable 49 | */ 50 | void JLinkDLL_SetDebugOutput(int enable); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif //JLINKDLL_JLINK_INIT_H 57 | -------------------------------------------------------------------------------- /JLink/JTAG/JLink_JTAG.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yaoji on 2022/3/20. 3 | // 4 | 5 | #include "JLink_JTAG.h" 6 | #include 7 | 8 | static void (*P_JLINK_JTAG_ConfigDevices)(uint32_t NumDevices, const JLINKARM_JTAG_DEVICE_CONF *paConf); 9 | static uint32_t (*P_JLINKARM_JTAG_GetDeviceId)(unsigned DeviceIndex); 10 | static int (*P_JLINKARM_JTAG_GetDeviceInfo)(unsigned DeviceIndex, JLINKARM_JTAG_DEVICE_INFO *pDeviceInfo); 11 | static uint32_t (*P_JLINKARM_JTAG_GetU8)(int BitPos); 12 | static uint32_t (*P_JLINKARM_JTAG_GetU16)(int BitPos); 13 | static uint32_t (*P_JLINKARM_JTAG_GetU32)(int BitPos); 14 | static void (*P_JLINKARM_JTAG_GetData)(uint8_t *pDest, int BitPos, int NumBits); 15 | static int (*P_JLINKARM_JTAG_StoreData)(const uint8_t *pTDI, int NumBits); 16 | static void (*P_JLINKARM_JTAG_StoreInst)(const uint8_t *pTDI, int IRLen); 17 | static int (*P_JLINKARM_JTAG_StoreRaw)(const uint8_t *pTDI, const uint8_t *pTMS, uint32_t NumBits); 18 | static void (*P_JLINKARM_JTAG_StoreGetData)(const uint8_t *pTDI, uint8_t *pTDO, int NumBits); 19 | static void (*P_JLINKARM_JTAG_StoreGetRaw)(const uint8_t *pTDI, uint8_t *pTDO, const uint8_t *pTMS, uint32_t NumBits); 20 | static void (*P_JLINKARM_JTAG_SyncBits)(void); 21 | static void (*P_JLINKARM_JTAG_SyncBytes)(void); 22 | 23 | int JLINK_JTAG_Init() { 24 | P_JLINK_JTAG_ConfigDevices = JLinkDLL_getSym("JLINK_JTAG_ConfigDevices"); 25 | if (P_JLINK_JTAG_ConfigDevices == NULL) return 0; 26 | P_JLINKARM_JTAG_GetDeviceId = JLinkDLL_getSym("JLINKARM_JTAG_GetDeviceId"); 27 | if (P_JLINKARM_JTAG_GetDeviceId == NULL) return 0; 28 | P_JLINKARM_JTAG_GetDeviceInfo = JLinkDLL_getSym("JLINKARM_JTAG_GetDeviceInfo"); 29 | if (P_JLINKARM_JTAG_GetDeviceInfo == NULL) return 0; 30 | P_JLINKARM_JTAG_GetU8 = JLinkDLL_getSym("JLINKARM_JTAG_GetU8"); 31 | if (P_JLINKARM_JTAG_GetU8 == NULL) return 0; 32 | P_JLINKARM_JTAG_GetU16 = JLinkDLL_getSym("JLINKARM_JTAG_GetU16"); 33 | if (P_JLINKARM_JTAG_GetU16 == NULL) return 0; 34 | P_JLINKARM_JTAG_GetU32 = JLinkDLL_getSym("JLINKARM_JTAG_GetU32"); 35 | if (P_JLINKARM_JTAG_GetU32 == NULL) return 0; 36 | P_JLINKARM_JTAG_GetData = JLinkDLL_getSym("JLINKARM_JTAG_GetData"); 37 | if (P_JLINKARM_JTAG_GetData == NULL) return 0; 38 | P_JLINKARM_JTAG_StoreData = JLinkDLL_getSym("JLINKARM_JTAG_StoreData"); 39 | if (P_JLINKARM_JTAG_StoreData == NULL) return 0; 40 | P_JLINKARM_JTAG_StoreInst = JLinkDLL_getSym("JLINKARM_JTAG_StoreInst"); 41 | if (P_JLINKARM_JTAG_StoreInst == NULL) return 0; 42 | P_JLINKARM_JTAG_StoreRaw = JLinkDLL_getSym("JLINKARM_JTAG_StoreRaw"); 43 | if (P_JLINKARM_JTAG_StoreRaw == NULL) return 0; 44 | P_JLINKARM_JTAG_StoreGetData = JLinkDLL_getSym("JLINKARM_JTAG_StoreGetData"); 45 | if (P_JLINKARM_JTAG_StoreGetData == NULL) return 0; 46 | P_JLINKARM_JTAG_StoreGetRaw = JLinkDLL_getSym("JLINKARM_JTAG_StoreGetRaw"); 47 | if (P_JLINKARM_JTAG_StoreGetRaw == NULL) return 0; 48 | P_JLINKARM_JTAG_SyncBits = JLinkDLL_getSym("JLINKARM_JTAG_SyncBits"); 49 | if (P_JLINKARM_JTAG_SyncBits == NULL) return 0; 50 | P_JLINKARM_JTAG_SyncBytes = JLinkDLL_getSym("JLINKARM_JTAG_SyncBytes"); 51 | if (P_JLINKARM_JTAG_SyncBytes == NULL) return 0; 52 | return 1; 53 | } 54 | //PYTHON CHECK POINT 55 | void JLINK_JTAG_ConfigDevices(uint32_t NumDevices, const JLINKARM_JTAG_DEVICE_CONF *paConf) { 56 | JLinkDLL_CALLPTR(P_JLINK_JTAG_ConfigDevices, NumDevices, paConf); 57 | } 58 | 59 | uint32_t JLINKARM_JTAG_GetDeviceId(unsigned DeviceIndex) { 60 | return JLinkDLL_CALLPTR(P_JLINKARM_JTAG_GetDeviceId, DeviceIndex); 61 | } 62 | 63 | int JLINKARM_JTAG_GetDeviceInfo(unsigned DeviceIndex, JLINKARM_JTAG_DEVICE_INFO *pDeviceInfo) { 64 | return JLinkDLL_CALLPTR(P_JLINKARM_JTAG_GetDeviceInfo, DeviceIndex, pDeviceInfo); 65 | } 66 | 67 | uint32_t JLINKARM_JTAG_GetU8(int BitPos) { 68 | return JLinkDLL_CALLPTR(P_JLINKARM_JTAG_GetU8, BitPos); 69 | } 70 | 71 | uint32_t JLINKARM_JTAG_GetU16(int BitPos) { 72 | return JLinkDLL_CALLPTR(P_JLINKARM_JTAG_GetU16, BitPos); 73 | } 74 | 75 | uint32_t JLINKARM_JTAG_GetU32(int BitPos) { 76 | return JLinkDLL_CALLPTR(P_JLINKARM_JTAG_GetU32, BitPos); 77 | } 78 | 79 | void JLINKARM_JTAG_GetData(uint8_t *pDest, int BitPos, int NumBits) { 80 | JLinkDLL_CALLPTR(P_JLINKARM_JTAG_GetData, pDest, BitPos, NumBits); 81 | } 82 | 83 | int JLINKARM_JTAG_StoreData(const uint8_t *pTDI, int NumBits) { 84 | return JLinkDLL_CALLPTR(P_JLINKARM_JTAG_StoreData, pTDI, NumBits); 85 | } 86 | 87 | void JLINKARM_JTAG_StoreInst(const uint8_t *pTDI, int IRLen) { 88 | JLinkDLL_CALLPTR(P_JLINKARM_JTAG_StoreInst, pTDI, IRLen); 89 | } 90 | 91 | int JLINKARM_JTAG_StoreRaw(const uint8_t *pTDI, const uint8_t *pTMS, uint32_t NumBits) { 92 | return JLinkDLL_CALLPTR(P_JLINKARM_JTAG_StoreRaw, pTDI, pTMS, NumBits); 93 | } 94 | 95 | void JLINKARM_JTAG_StoreGetData(const uint8_t *pTDI, uint8_t *pTDO, int NumBits) { 96 | JLinkDLL_CALLPTR(P_JLINKARM_JTAG_StoreGetData, pTDI, pTDO, NumBits); 97 | } 98 | 99 | void JLINKARM_JTAG_StoreGetRaw(const uint8_t *pTDI, uint8_t *pTDO, const uint8_t *pTMS, uint32_t NumBits) { 100 | JLinkDLL_CALLPTR(P_JLINKARM_JTAG_StoreGetRaw, pTDI, pTDO, pTMS, NumBits); 101 | } 102 | 103 | void JLINKARM_JTAG_SyncBits(void) { 104 | JLinkDLL_CALLPTR(P_JLINKARM_JTAG_SyncBits); 105 | } 106 | 107 | void JLINKARM_JTAG_SyncBytes(void) { 108 | JLinkDLL_CALLPTR(P_JLINKARM_JTAG_SyncBytes); 109 | } 110 | //PYTHON CHECK POINT 111 | -------------------------------------------------------------------------------- /JLink/JTAG/JLink_JTAG.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file JTAG.h 3 | * @author yao 4 | */ 5 | 6 | #ifndef JLINKDLL_JLINK_JTAG_H 7 | #define JLINKDLL_JLINK_JTAG_H 8 | 9 | #include "JLink/JLink_Define.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | /** 16 | * Allows to setup the actual JTAG scan chain. 17 | * @code 18 | * JLINKARM_JTAG_DEVICE_CONF aDeviceConf[2]; 19 | * // 20 | * // Specify device 0 21 | * // 22 | * aDeviceConf[0].SizeOfStruct = sizeof(JLINKARM_JTAG_DEVICE_CONF); 23 | * aDeviceConf[0].IRLen = 4; 24 | * aDeviceConf[0].IRPrint = 1; 25 | * aDeviceConf[0].Id = 0x4BA00477; 26 | * aDeviceConf[0].sName = "Device0"; 27 | * // 28 | * // Sepcify device 1 29 | * // 30 | * aDeviceConf[1].SizeOfStruct = sizeof(JLINKARM_JTAG_DEVICE_CONF); 31 | * aDeviceConf[1].IRLen = 4; 32 | * aDeviceConf[1].IRPrint = 0; // Unknown / invalid 33 | * aDeviceConf[1].Id = 0; // Unknown / invalid 34 | * aDeviceConf[1].sName = NULL; // Unknown / invalid 35 | * // 36 | * // Configure JTAG scan chain 37 | * // 38 | * JLINK_JTAG_ConfigDevices(COUNTOF(aDeviceConf), &aDeviceConf[0]); 39 | * @endcode 40 | * @param NumDevices NumDevices describes the number of elements the paConf pointer 41 | * Points to. This also specifies how many devices are in the JTAG chain. 42 | * @param paConf Pointer to a list of JTAG devices. The first JTAG device paConf points 43 | * to, is later as position JLINK_ConfigJTAG(0, 0); 44 | */ 45 | void JLINK_JTAG_ConfigDevices(uint32_t NumDevices, const JLINKARM_JTAG_DEVICE_CONF *paConf); 46 | 47 | /** 48 | * Returns the JTAG-Id of one of a connected device. 49 | * @param DeviceIndex Index of the device. E.g. if n devices are connected to the scan chain, 50 | * then is the index between 0 and n-1. 51 | * @return JTAG Id of the device with index n. 52 | */ 53 | uint32_t JLINKARM_JTAG_GetDeviceId(unsigned DeviceIndex); 54 | 55 | /** 56 | * Get additional information about a device, such as device name, IRLen and IRPrint, based 57 | * on the device index. 58 | * @param DeviceIndex Index of the device. E.g. if n devices are connected to the scan chain, 59 | * then is the index between 0 and n-1. 60 | * @param pDeviceInfo Pointer to info variable which is used to hold the device information. 61 | * @retval 0 Additional device information available. All elements of JLINKARM_JTAG_DEVICE_INFO are available 62 | * @retval >0 Unknown device, IRLen information available 63 | * @retval -1 No additional device information 64 | available */ 65 | int JLINKARM_JTAG_GetDeviceInfo(unsigned DeviceIndex, JLINKARM_JTAG_DEVICE_INFO *pDeviceInfo); 66 | 67 | /** 68 | * This function gets a unit of 8 bit from output buffer. 69 | * @param BitPos Startposition of unit to read from input buffer. 70 | * @return 8 Bit data from input buffer. 71 | */ 72 | uint32_t JLINKARM_JTAG_GetU8(int BitPos); 73 | 74 | /** 75 | * This function gets a unit of 16 bit from output buffer. 76 | * @param BitPos Startposition of unit to read from input buffer. 77 | * @return 16 Bit data from input buffer. 78 | */ 79 | uint32_t JLINKARM_JTAG_GetU16(int BitPos); 80 | 81 | /** 82 | * This function gets a unit of 16 bit from output buffer. 83 | * @param BitPos Startposition of unit to read from input buffer. 84 | * @return 32 Bit data from input buffer. 85 | */ 86 | uint32_t JLINKARM_JTAG_GetU32(int BitPos); 87 | 88 | /** 89 | * Retrieves TDO data from input buffer. 90 | * @param pDest Pointer to data destination buffer. 91 | * @param BitPos Startposition of unit to read from input buffer. 92 | * @param NumBits Number of bits to read and write. 93 | */ 94 | void JLINKARM_JTAG_GetData(uint8_t *pDest, int BitPos, int NumBits); 95 | 96 | /** 97 | * This function adds the bits to set the TAP controller into Shift-DR state to the delivered data 98 | * bits and stores the sequence in the output buffers. 99 | * @param pTDI Pointer to output buffer. 100 | * @param NumBits Number of bits to store. 101 | * @return The bit position of data in input buffer after transmission. 102 | */ 103 | int JLINKARM_JTAG_StoreData(const uint8_t *pTDI, int NumBits); 104 | 105 | /** 106 | * This function adds the bits to set the TAP controller into Shift-IR state to the delivered 107 | * command bits and stores the sequence in the output buffers. 108 | * @param pTDI Pointer to output buffer. 109 | * @param IRLen Instruction length in bits. 110 | */ 111 | void JLINKARM_JTAG_StoreInst(const uint8_t *pTDI, int IRLen); 112 | 113 | /** 114 | * This function stores a raw data sequence in the output buffer. 115 | * @param pTDI Pointer to output buffer. 116 | * @param pTMS Pointer to mode select buffer. 117 | * @param NumBits Number of bits to read and write. 118 | * @return The bit position of data in input buffer after transmission. 119 | */ 120 | int JLINKARM_JTAG_StoreRaw(const uint8_t *pTDI, const uint8_t *pTMS, uint32_t NumBits); 121 | 122 | /** 123 | * This function transmits the input buffer to the connected JTAG device and stores the received data in the output buffer. 124 | * @param pTDI Pointer to output buffer. 125 | * @param pTDO Pointer to input buffer. 126 | * @param NumBits Number of bits to read and write. 127 | * @retval If pTDO is set to NULL the transmission is not essential. If the data amount is not beyond 128 | * buffer size the data will only transferred only when necessary. 129 | */ 130 | void JLINKARM_JTAG_StoreGetData(const uint8_t *pTDI, uint8_t *pTDO, int NumBits); 131 | 132 | /** 133 | * This function stores the specified number of bits in the output buffers, transfers the whole 134 | * content of the output buffers to the JTAG device(s) and stores the received data in the input 135 | * buffer. This function writes only the assigned raw data without additions to the JTAG device. 136 | * @param pTDI Pointer to output buffer. 137 | * @param pTDO Pointer to input buffer. 138 | * @param pTMS Pointer to mode select buffer. 139 | * @param NumBits Number of bits to read and write. 140 | */ 141 | void JLINKARM_JTAG_StoreGetRaw(const uint8_t *pTDI, uint8_t *pTDO, const uint8_t *pTMS, uint32_t NumBits); 142 | 143 | /** 144 | * Writes out the data remaining in the output buffers to JTAG device. 145 | */ 146 | void JLINKARM_JTAG_SyncBits(void); 147 | 148 | /** 149 | * This function transmits the content of data in the output buffers to the JTAG device and 150 | * adds if necessary one ore more 0-bits to fill the buffer to bytesize. E.g. if the output buffers 151 | * are filled with 23 bits, {@link JLINKARM_JTAG_SyncBytes} adds one 0-bit to each output buffer 152 | * and transmits 24 bits. 153 | */ 154 | void JLINKARM_JTAG_SyncBytes(void); 155 | 156 | #ifdef __cplusplus 157 | }; 158 | #endif 159 | 160 | #endif //JLINKDLL_JLINK_JTAG_H 161 | -------------------------------------------------------------------------------- /JLink/POWER/JLink_Power.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yaoji on 2022/3/20. 3 | // 4 | 5 | #include "JLink_Power.h" 6 | #include 7 | 8 | static int (*P_JLINK_POWERTRACE_Control)(int Cmd, void *pIn, void *pOut); 9 | static int (*P_JLINK_POWERTRACE_Read)(JLINK_POWERTRACE_DATA_ITEM *paData, uint32_t NumItems); 10 | 11 | int JLINK_POWERTRACE_Init() { 12 | P_JLINK_POWERTRACE_Control = JLinkDLL_getSym("JLINK_POWERTRACE_Control"); 13 | if (P_JLINK_POWERTRACE_Control == NULL) return 0; 14 | P_JLINK_POWERTRACE_Read = JLinkDLL_getSym("JLINK_POWERTRACE_Read"); 15 | if (P_JLINK_POWERTRACE_Read == NULL) return 0; 16 | return 1; 17 | } 18 | //PYTHON CHECK POINT 19 | int JLINK_POWERTRACE_Control(int Cmd, void *pIn, void *pOut) { 20 | return JLinkDLL_CALLPTR(P_JLINK_POWERTRACE_Control, Cmd, pIn, pOut); 21 | } 22 | int JLINK_POWERTRACE_Read(JLINK_POWERTRACE_DATA_ITEM *paData, uint32_t NumItems) { 23 | return JLinkDLL_CALLPTR(P_JLINK_POWERTRACE_Read, paData, NumItems); 24 | } 25 | //PYTHON CHECK POINT -------------------------------------------------------------------------------- /JLink/POWER/JLink_Power.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file JLink_Power.h 3 | * @author yao 4 | */ 5 | 6 | #ifndef JLINKDLL_JLINK_POWER_H 7 | #define JLINKDLL_JLINK_POWER_H 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | int JLINK_POWERTRACE_Control(int Cmd, void *pIn, void *pOut); 16 | int JLINK_POWERTRACE_Read(JLINK_POWERTRACE_DATA_ITEM *paData, uint32_t NumItems); 17 | 18 | #ifdef __cplusplus 19 | }; 20 | #endif 21 | 22 | #endif //JLINKDLL_JLINK_POWER_H 23 | -------------------------------------------------------------------------------- /JLink/RTT/JLink_RTT.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yaoji on 2022/3/18. 3 | // 4 | 5 | #include "JLink_RTT.h" 6 | #include "JLink/JLink_Init.h" 7 | 8 | static int (*P_JLINK_RTTERMINAL_Control)(uint32_t Cmd, void *p); 9 | static int (*P_JLINK_RTTERMINAL_Read)(uint32_t BufferIndex, char *sBuffer, uint32_t BufferSize); 10 | static int (*P_JLINK_RTTERMINAL_Write)(uint32_t BufferIndex, const char *sBuffer, uint32_t BufferSize); 11 | 12 | int JLINK_RTT_Init() { 13 | P_JLINK_RTTERMINAL_Control = JLinkDLL_getSym("JLINK_RTTERMINAL_Control"); 14 | if (P_JLINK_RTTERMINAL_Control == NULL) return 0; 15 | P_JLINK_RTTERMINAL_Read = JLinkDLL_getSym("JLINK_RTTERMINAL_Read"); 16 | if (P_JLINK_RTTERMINAL_Read == NULL) return 0; 17 | P_JLINK_RTTERMINAL_Write = JLinkDLL_getSym("JLINK_RTTERMINAL_Write"); 18 | if (P_JLINK_RTTERMINAL_Write == NULL) return 0; 19 | return 1; 20 | } 21 | //PYTHON CHECK POINT 22 | int JLINK_RTTERMINAL_Control(uint32_t Cmd, void *p) { 23 | return JLinkDLL_CALLPTR(P_JLINK_RTTERMINAL_Control, Cmd, p); 24 | } 25 | 26 | int JLINK_RTTERMINAL_Read(uint32_t BufferIndex, char *sBuffer, uint32_t BufferSize) { 27 | return JLinkDLL_CALLPTR(P_JLINK_RTTERMINAL_Read, BufferIndex, sBuffer, BufferSize); 28 | } 29 | 30 | int JLINK_RTTERMINAL_Write(uint32_t BufferIndex, const char *sBuffer, uint32_t BufferSize) { 31 | return JLinkDLL_CALLPTR(P_JLINK_RTTERMINAL_Write, BufferIndex, sBuffer, BufferSize); 32 | } 33 | //PYTHON CHECK POINT -------------------------------------------------------------------------------- /JLink/RTT/JLink_RTT.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file JLink_RTT.h 3 | * @brief The table below lists the available SEGGER J-Link RTT API routines. All functions are listed 4 | * in alphabetical order. Detailed descriptions of the routines can be found in the sections 5 | * that follow. 6 | */ 7 | 8 | #ifndef JLINKDLL_JLINK_RTT_H 9 | #define JLINKDLL_JLINK_RTT_H 10 | 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | /** 18 | * Calls an internal command to control RTT. 19 | * @param Cmd The Cmd that should be executed 20 | * @see JLINKARM_RTTERMINAL_CMD 21 | * @param p Pointer to structure containing parameters for the command. (See Add. information below). 22 | * JLINK_RTTERMINAL_CMD_GETNUMBUF takes a uint32_t Direction instead of a structure. 23 | * @see JLINK_RTTERMINAL_START 24 | * @see JLINK_RTTERMINAL_STOP 25 | * @see JLINK_RTTERMINAL_BUFDESC 26 | * @retval >= 0 success 27 | * @retval < 0 error 28 | * @retval 0 Cmd = JLINKARM_RTTERMINAL_CMD_STOP: RTT was running and has been stopped r 29 | * @retval 1 Cmd = JLINKARM_RTTERMINAL_CMD_STOP: RTT stopped but was not running before 30 | * @retval -2 If CMD = (JLINKARM_RTTERMINAL_CMD_GETDESC || JLINKARM_RTTERMINAL_CMD_GETNUMBUF): 31 | * RTT Control Block not found yet. 32 | */ 33 | int JLINK_RTTERMINAL_Control(uint32_t Cmd, void *p); 34 | 35 | /** 36 | * Reads bytes from the RTT host-side buffer. 37 | * @param BufferIndex Index of the buffer to read. 38 | * @param sBuffer Pointer to buffer which is used to store the data being read. 39 | * @param BufferSize Size of buffer for read data. 40 | * @retval >= 0 Ok, number of bytes read. 41 | * @retval < 0 Error 42 | */ 43 | int JLINK_RTTERMINAL_Read(uint32_t BufferIndex, char *sBuffer, uint32_t BufferSize); 44 | 45 | /** 46 | * Writes data into the RTT buffer. 47 | * @param BufferIndex IIndex of the buffer to write data to. 48 | * @param sBuffer PPointer to the data that should be stored. 49 | * @param BufferSize Number of bytes to write. 50 | * @retval >= 0 Ok, number of bytes written. 51 | * @retval < 0 Error 52 | */ 53 | int JLINK_RTTERMINAL_Write(uint32_t BufferIndex, const char *sBuffer, uint32_t BufferSize); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif //JLINKDLL_JLINK_RTT_H 60 | -------------------------------------------------------------------------------- /JLink/SPI/JLink_SPI.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yaoji on 2022/3/20. 3 | // 4 | 5 | #include "JLink_SPI.h" 6 | #include 7 | 8 | static int (*P_JLINK_SPI_Transfer)(const uint8_t *pDataDown, uint8_t *pDataUp, uint32_t NumBits, uint32_t Flags); 9 | 10 | int JLINK_SPI_Init() { 11 | P_JLINK_SPI_Transfer = JLinkDLL_getSym("JLINK_SPI_Transfer"); 12 | return P_JLINK_SPI_Transfer != NULL; 13 | } 14 | //PYTHON CHECK POINT 15 | int JLINK_SPI_Transfer(const uint8_t *pDataDown, uint8_t *pDataUp, uint32_t NumBits, uint32_t Flags) { 16 | return JLinkDLL_CALLPTR(P_JLINK_SPI_Transfer, pDataDown, pDataUp, NumBits, Flags); 17 | } 18 | //PYTHON CHECK POINT -------------------------------------------------------------------------------- /JLink/SPI/JLink_SPI.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file JLink_SPI.h 3 | * @author yao 4 | */ 5 | 6 | #ifndef JLINKDLL_JLINK_SPI_H 7 | #define JLINKDLL_JLINK_SPI_H 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | int JLINK_SPI_Transfer(const uint8_t* pDataDown, uint8_t* pDataUp, uint32_t NumBits, uint32_t Flags); 16 | 17 | #ifdef __cplusplus 18 | }; 19 | #endif 20 | 21 | #endif //JLINKDLL_JLINK_SPI_H 22 | -------------------------------------------------------------------------------- /JLink/STRACE/JLink_STRACE.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yaoji on 2022/3/20. 3 | // 4 | 5 | #include "JLink_STRACE.h" 6 | #include 7 | 8 | static int (*P_JLINK_STRACE_Config)(const char *sConfig); 9 | static int (*P_JLINK_STRACE_Control)(uint32_t Cmd, void *pData); 10 | static int (*P_JLINK_STRACE_GetInstStats)(void *paItem, uint32_t Addr, uint32_t NumItems, uint32_t SizeOfStruct, uint32_t Type); 11 | static int (*P_JLINK_STRACE_Read)(uint32_t *paItem, uint32_t NumItems); 12 | static int (*P_JLINK_STRACE_Start)(void); 13 | static int (*P_JLINK_STRACE_Stop)(void); 14 | 15 | int JLINK_STRACE_Init() { 16 | P_JLINK_STRACE_Config = JLinkDLL_getSym("JLINK_STRACE_Config"); 17 | if (P_JLINK_STRACE_Config == NULL) return 0; 18 | P_JLINK_STRACE_Control = JLinkDLL_getSym("JLINK_STRACE_Control"); 19 | if (P_JLINK_STRACE_Control == NULL) return 0; 20 | P_JLINK_STRACE_GetInstStats = JLinkDLL_getSym("JLINK_STRACE_GetInstStats"); 21 | if (P_JLINK_STRACE_GetInstStats == NULL) return 0; 22 | P_JLINK_STRACE_Read = JLinkDLL_getSym("JLINK_STRACE_Read"); 23 | if (P_JLINK_STRACE_Read == NULL) return 0; 24 | P_JLINK_STRACE_Start = JLinkDLL_getSym("JLINK_STRACE_Start"); 25 | if (P_JLINK_STRACE_Start == NULL) return 0; 26 | P_JLINK_STRACE_Stop = JLinkDLL_getSym("JLINK_STRACE_Stop"); 27 | if (P_JLINK_STRACE_Stop == NULL) return 0; 28 | return 1; 29 | } 30 | //PYTHON CHECK POINT 31 | int JLINK_STRACE_Config(const char *sConfig) { 32 | return JLinkDLL_CALLPTR(P_JLINK_STRACE_Config, sConfig); 33 | } 34 | 35 | int JLINK_STRACE_Control(uint32_t Cmd, void *pData) { 36 | return JLinkDLL_CALLPTR(P_JLINK_STRACE_Control, Cmd, pData); 37 | } 38 | 39 | int JLINK_STRACE_GetInstStats(void *paItem, uint32_t Addr, uint32_t NumItems, uint32_t SizeOfStruct, uint32_t Type) { 40 | return JLinkDLL_CALLPTR(P_JLINK_STRACE_GetInstStats, paItem, Addr, NumItems, SizeOfStruct, Type); 41 | } 42 | 43 | int JLINK_STRACE_Read(uint32_t *paItem, uint32_t NumItems) { 44 | return JLinkDLL_CALLPTR(P_JLINK_STRACE_Read, paItem, NumItems); 45 | } 46 | 47 | int JLINK_STRACE_Start(void) { 48 | return JLinkDLL_CALLPTR(P_JLINK_STRACE_Start); 49 | } 50 | 51 | int JLINK_STRACE_Stop(void) { 52 | return JLinkDLL_CALLPTR(P_JLINK_STRACE_Stop); 53 | } 54 | //PYTHON CHECK POINT -------------------------------------------------------------------------------- /JLink/STRACE/JLink_STRACE.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file JLink_STRACE.h 3 | * @author yao 4 | */ 5 | 6 | #ifndef JLINKDLL_JLINK_STRACE_H 7 | #define JLINKDLL_JLINK_STRACE_H 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | /** 16 | * 17 | * @param sConfig 18 | * @return 19 | */ 20 | int JLINK_STRACE_Config(const char* sConfig); 21 | 22 | /** 23 | * @see JLINK_STRACE_CMD 24 | * @param Cmd 25 | * @param pData 26 | * @return 27 | */ 28 | int JLINK_STRACE_Control(uint32_t Cmd, void* pData); 29 | int JLINK_STRACE_GetInstStats(void* paItem, uint32_t Addr, uint32_t NumItems, uint32_t SizeOfStruct, uint32_t Type); 30 | int JLINK_STRACE_Read(uint32_t* paItem, uint32_t NumItems); 31 | int JLINK_STRACE_Start(void); 32 | int JLINK_STRACE_Stop(void); 33 | 34 | #ifdef __cplusplus 35 | }; 36 | #endif 37 | 38 | #endif //JLINKDLL_JLINK_STRACE_H 39 | -------------------------------------------------------------------------------- /JLink/SWD/JLink_SWD.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yaoji on 2022/3/20. 3 | // 4 | 5 | #include "JLink_SWD.h" 6 | #include 7 | 8 | static uint32_t (*P_JLINKARM_SWD_GetU8)(int BitPos); 9 | static uint32_t (*P_JLINKARM_SWD_GetU16)(int BitPos); 10 | static uint32_t (*P_JLINKARM_SWD_GetU32)(int BitPos); 11 | static void (*P_JLINKARM_SWD_GetData)(uint8_t *pDest, int BitPos, int NumBits); 12 | static void (*P_JLINKARM_SWD_StoreRaw)(const uint8_t *pDir, const uint8_t *pin, uint32_t NumBits); 13 | static void (*P_JLINKARM_SWD_StoreGetRaw)(const uint8_t *pDir, uint8_t *pIn, const uint8_t *pOut, uint32_t NumBits); 14 | static void (*P_JLINKARM_SWD_SyncBits)(void); 15 | static void (*P_JLINKARM_SWD_SyncBytes)(void); 16 | 17 | int JLINK_SWD_Init() { 18 | // 文档中函数名前缀是JLINKARM,但DLL中是JLINK 19 | P_JLINKARM_SWD_GetU8 = JLinkDLL_getSym("JLINK_SWD_GetU8"); 20 | if (P_JLINKARM_SWD_GetU8 == NULL) return 0; 21 | P_JLINKARM_SWD_GetU16 = JLinkDLL_getSym("JLINK_SWD_GetU16"); 22 | if (P_JLINKARM_SWD_GetU16 == NULL) return 0; 23 | P_JLINKARM_SWD_GetU32 = JLinkDLL_getSym("JLINK_SWD_GetU32"); 24 | if (P_JLINKARM_SWD_GetU32 == NULL) return 0; 25 | P_JLINKARM_SWD_GetData = JLinkDLL_getSym("JLINK_SWD_GetData"); 26 | if (P_JLINKARM_SWD_GetData == NULL) return 0; 27 | P_JLINKARM_SWD_StoreRaw = JLinkDLL_getSym("JLINK_SWD_StoreRaw"); 28 | if (P_JLINKARM_SWD_StoreRaw == NULL) return 0; 29 | P_JLINKARM_SWD_StoreGetRaw = JLinkDLL_getSym("JLINK_SWD_StoreGetRaw"); 30 | if (P_JLINKARM_SWD_StoreGetRaw == NULL) return 0; 31 | P_JLINKARM_SWD_SyncBits = JLinkDLL_getSym("JLINK_SWD_SyncBits"); 32 | if (P_JLINKARM_SWD_SyncBits == NULL) return 0; 33 | P_JLINKARM_SWD_SyncBytes = JLinkDLL_getSym("JLINK_SWD_SyncBytes"); 34 | if (P_JLINKARM_SWD_SyncBytes == NULL) return 0; 35 | return 1; 36 | } 37 | //PYTHON CHECK POINT 38 | uint32_t JLINKARM_SWD_GetU8(int BitPos) { 39 | return JLinkDLL_CALLPTR(P_JLINKARM_SWD_GetU8, BitPos); 40 | } 41 | 42 | uint32_t JLINKARM_SWD_GetU16(int BitPos) { 43 | return JLinkDLL_CALLPTR(P_JLINKARM_SWD_GetU16, BitPos); 44 | } 45 | 46 | uint32_t JLINKARM_SWD_GetU32(int BitPos) { 47 | return JLinkDLL_CALLPTR(P_JLINKARM_SWD_GetU32, BitPos); 48 | } 49 | 50 | void JLINKARM_SWD_GetData(uint8_t *pDest, int BitPos, int NumBits) { 51 | JLinkDLL_CALLPTR(P_JLINKARM_SWD_GetData, pDest, BitPos, NumBits); 52 | } 53 | 54 | void JLINKARM_SWD_StoreRaw(const uint8_t *pDir, const uint8_t *pin, uint32_t NumBits) { 55 | JLinkDLL_CALLPTR(P_JLINKARM_SWD_StoreRaw, pDir, pin, NumBits); 56 | } 57 | 58 | void JLINKARM_SWD_StoreGetRaw(const uint8_t *pDir, uint8_t *pIn, const uint8_t *pOut, uint32_t NumBits) { 59 | JLinkDLL_CALLPTR(P_JLINKARM_SWD_StoreGetRaw, pDir, pIn, pOut, NumBits); 60 | } 61 | 62 | void JLINKARM_SWD_SyncBits(void) { 63 | JLinkDLL_CALLPTR(P_JLINKARM_SWD_SyncBits); 64 | } 65 | 66 | void JLINKARM_SWD_SyncBytes(void) { 67 | JLinkDLL_CALLPTR(P_JLINKARM_SWD_SyncBytes); 68 | } 69 | //PYTHON CHECK POINT -------------------------------------------------------------------------------- /JLink/SWD/JLink_SWD.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file JLink_SWD.h 3 | * @author yao 4 | */ 5 | 6 | #ifndef JLINKDLL_JLINK_SWD_H 7 | #define JLINKDLL_JLINK_SWD_H 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | uint32_t JLINKARM_SWD_GetU8(int BitPos); 16 | uint32_t JLINKARM_SWD_GetU16(int BitPos); 17 | uint32_t JLINKARM_SWD_GetU32(int BitPos); 18 | void JLINKARM_SWD_GetData(uint8_t * pDest, int BitPos, int NumBits); 19 | void JLINKARM_SWD_StoreRaw(const uint8_t* pDir, const uint8_t* pin, uint32_t NumBits); 20 | void JLINKARM_SWD_StoreGetRaw(const uint8_t* pDir, uint8_t* pIn, const uint8_t* pOut, uint32_t NumBits); 21 | void JLINKARM_SWD_SyncBits(void); 22 | void JLINKARM_SWD_SyncBytes(void); 23 | 24 | #ifdef __cplusplus 25 | }; 26 | #endif 27 | 28 | #endif //JLINKDLL_JLINK_SWD_H 29 | -------------------------------------------------------------------------------- /JLink/SWO/JLink_SWO.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yaoji on 2022/3/20. 3 | // 4 | 5 | #include "JLink_SWO.h" 6 | #include 7 | 8 | static int (*P_JLINKARM_SWO_Control)(uint32_t Cmd, void *pData); 9 | static int (*P_JLINKARM_SWO_DisableTarget)(uint32_t PortMask); 10 | static int (*P_JLINKARM_SWO_EnableTarget)(uint32_t CPUSpeed, uint32_t SWOSpeed, int Mode, uint32_t PortMask); 11 | static int (*P_JLINKARM_SWO_GetCompatibleSpeeds)(uint32_t CPUSpeed, uint32_t MaxSWOSpeed, uint32_t *paSWOSpeed, 12 | uint32_t NumEntries); 13 | static void (*P_JLINKARM_SWO_Read)(uint8_t *pData, uint32_t Offset, uint32_t *pNumBytes); 14 | static void (*P_JLINKARM_SWO_ReadStimulus)(int Port, uint8_t *pData, uint32_t NumBytes); 15 | 16 | int JLINK_SWO_Init() { 17 | P_JLINKARM_SWO_Control = JLinkDLL_getSym("JLINKARM_SWO_Control"); 18 | if (P_JLINKARM_SWO_Control == NULL) return 0; 19 | P_JLINKARM_SWO_DisableTarget = JLinkDLL_getSym("JLINKARM_SWO_DisableTarget"); 20 | if (P_JLINKARM_SWO_DisableTarget == NULL) return 0; 21 | P_JLINKARM_SWO_EnableTarget = JLinkDLL_getSym("JLINKARM_SWO_EnableTarget"); 22 | if (P_JLINKARM_SWO_EnableTarget == NULL) return 0; 23 | P_JLINKARM_SWO_GetCompatibleSpeeds = JLinkDLL_getSym("JLINKARM_SWO_GetCompatibleSpeeds"); 24 | if (P_JLINKARM_SWO_GetCompatibleSpeeds == NULL) return 0; 25 | P_JLINKARM_SWO_Read = JLinkDLL_getSym("JLINKARM_SWO_Read"); 26 | if (P_JLINKARM_SWO_Read == NULL) return 0; 27 | P_JLINKARM_SWO_ReadStimulus = JLinkDLL_getSym("JLINKARM_SWO_ReadStimulus"); 28 | if (P_JLINKARM_SWO_ReadStimulus == NULL) return 0; 29 | return 1; 30 | } 31 | //PYTHON CHECK POINT 32 | int JLINKARM_SWO_Control(uint32_t Cmd, void *pData) { 33 | return JLinkDLL_CALLPTR(P_JLINKARM_SWO_Control, Cmd, pData); 34 | } 35 | 36 | int JLINKARM_SWO_DisableTarget(uint32_t PortMask) { 37 | return JLinkDLL_CALLPTR(P_JLINKARM_SWO_DisableTarget, PortMask); 38 | } 39 | 40 | int JLINKARM_SWO_EnableTarget(uint32_t CPUSpeed, uint32_t SWOSpeed, int Mode, uint32_t PortMask) { 41 | return JLinkDLL_CALLPTR(P_JLINKARM_SWO_EnableTarget, CPUSpeed, SWOSpeed, Mode, PortMask); 42 | } 43 | 44 | int JLINKARM_SWO_GetCompatibleSpeeds(uint32_t CPUSpeed, uint32_t MaxSWOSpeed, 45 | uint32_t *paSWOSpeed, uint32_t NumEntries) { 46 | return JLinkDLL_CALLPTR(P_JLINKARM_SWO_GetCompatibleSpeeds, CPUSpeed, MaxSWOSpeed, paSWOSpeed, NumEntries); 47 | } 48 | 49 | void JLINKARM_SWO_Read(uint8_t *pData, uint32_t Offset, uint32_t *pNumBytes) { 50 | JLinkDLL_CALLPTR(P_JLINKARM_SWO_Read, pData, Offset, pNumBytes); 51 | } 52 | 53 | void JLINKARM_SWO_ReadStimulus(int Port, uint8_t *pData, uint32_t NumBytes) { 54 | JLinkDLL_CALLPTR(P_JLINKARM_SWO_ReadStimulus, Port, pData, NumBytes); 55 | } 56 | //PYTHON CHECK POINT -------------------------------------------------------------------------------- /JLink/SWO/JLink_SWO.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file SWO.h 3 | * @author yao 4 | */ 5 | #ifndef JLINKDLL_JLINK_SWO_H 6 | #define JLINKDLL_JLINK_SWO_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #include 13 | 14 | /** 15 | * This function allows a debug controller to start/stop collecting SWO data, to flush the SWO 16 | * buffer and to read/write various SWO settings. 17 | * @param Cmd Specifies which command should be executed. 18 | * @param pData Pointer to data value or structure. Meaning depends on Cmd. 19 | * @retval 0 on success 20 | * @retval -1 if an error has occurred 21 | */ 22 | int JLINKARM_SWO_Control(uint32_t Cmd, void *pData); 23 | 24 | /** 25 | * Disables SWO output on the target. This mainly means disabling of ITM & stimulus ports. 26 | * SWO data capturing on J-Link side is also stopped when calling this function (equivalent to 27 | * calling {@link JLINKARM_SWO_Control}(JLINKARM_SWO_CMD_STOP)). 28 | * @param PortMask Port mask used to describe which stimulus ports shall be disabled. A 29 | * 1 in the mask disables the corresponding stimulus port. 30 | * @retval 0 O.K. 31 | * @retval <0 Error 32 | */ 33 | int JLINKARM_SWO_DisableTarget(uint32_t PortMask); 34 | 35 | /** 36 | * Enables SWO output on the target. This mainly means configuration of the output protocol (UART / manchester), 37 | * configuration of the SWO output speed and enabling of ITM & 38 | * stimulus ports. SWO data capturing on J-Link side is also started when calling this function 39 | * (equivalent to calling {@link JLINKARM_SWO_Control}(JLINKARM_SWO_CMD_START)). 40 | * @param CPUSpeed Target CPU frequency in Hz. Needed to adjust dividers for SWO frequency accordingly. 41 | * @param SWOSpeed Frequency in Hz that should be used by target to output SWO data and by J-Link to capture SWO data. 42 | * @param Mode SWO mode (UART/manchester). Currently only UART (0) is supported. 43 | * @param PortMask Port mask used to describe which stimulus ports shall be enabled. A 1 44 | * in the mask enables the corresponding stimulus port. 45 | * @retval 0 O.K. 46 | * @retval <0 Error 47 | */ 48 | int JLINKARM_SWO_EnableTarget(uint32_t CPUSpeed, uint32_t SWOSpeed, int Mode, uint32_t PortMask); 49 | 50 | /** 51 | * Returns a list of SWO speeds which are supported by both, the target and the connected 52 | * J-Link. Due to different CPUs on the target side and on the J-Link models, the supported 53 | * speeds may vary. 54 | * @param CPUSpeed Target CPU frequency in Hz. 55 | * @param MaxSWOSpeed Usually 0, so the list returned by this function will start with the highest 56 | * possible SWO speed supported by both sides. Can be used to set 57 | * an upper limit in Hz of the SWO speeds that will be added to the list. 58 | * Example: If MaxSWOSpeed = 3000000 (3 MHz) but highest possible speed would be 6 MHz, 59 | * the list will start with Speeds ≤ 3000000. 60 | * Useful to verify if a manually selected speed is a compatible one or to 61 | * get the closest compatible speed to the defined one 62 | * @param paSWOSpeed Pointer to an array of uint32_t, used to store the list of compatible speeds. 63 | * @param NumEntries Determines number of compatible speeds that shall be stored in the list buffer. 64 | * @retval >=0 O.K., number of entries (compatible speeds) stored in the given list buffer. 65 | * @retval <0 Error 66 | */ 67 | int JLINKARM_SWO_GetCompatibleSpeeds(uint32_t CPUSpeed, uint32_t MaxSWOSpeed, 68 | uint32_t *paSWOSpeed, uint32_t NumEntries); 69 | 70 | /** 71 | * This function reads data from the SWO buffer. The data will not automatically be removed 72 | * from the SWO buffer after reading. The application have to use the {@link JLINKARM_SWO_Control} 73 | * function with JLINKARM_SWO_CMD_FLUSH to remove the data from the buffer. 74 | * @code 75 | * uint8_t abData[0x100]; 76 | * uint32_t NumBytes; 77 | * // 78 | * // Read and flush data 79 | * // 80 | * NumBytes = sizeof(abData); 81 | * JLINKARM_SWO_Read(&abData[0], 0, &NumBytes); 82 | * JLINKARM_SWO_Control(JLINKARM_SWO_CMD_FLUSH, &NumBytes); 83 | * printf("%d bytes read successfully\n", NumBytes); 84 | * @endcode 85 | * @param pData Buffer to be filled with the requested data. 86 | * @param Offset Offset of first byte to be retrieved from the SWO buffer. 87 | * @param pNumBytes Pointer to a uint32_t value containing the number of bytes to be read 88 | * from the SWO buffer. This value will be filled with the number of 89 | * bytes that could be read from the SWO buffer. 90 | */ 91 | void JLINKARM_SWO_Read(uint8_t *pData, uint32_t Offset, uint32_t *pNumBytes); 92 | 93 | /** 94 | * This function reads the data which is output via SWO for one stimulus port, which is the 95 | * printable data. 96 | * @param Port Stimulus port to read data from. May be 0 - 31 97 | * @param pData Buffer to be filled with the requested data. 98 | * @param NumBytes Maximum number of bytes to read. 99 | */ 100 | void JLINKARM_SWO_ReadStimulus(int Port, uint8_t *pData, uint32_t NumBytes); 101 | 102 | #ifdef __cplusplus 103 | }; 104 | #endif 105 | 106 | #endif //JLINKDLL_JLINK_SWO_H 107 | -------------------------------------------------------------------------------- /JLinkARM.dll: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:a82f658d523a62637216b5d91f9abb5fc86f2a941701d3d67c3ca94cce579802 3 | size 15207128 4 | -------------------------------------------------------------------------------- /JLink_x64.dll: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:a2396c7962947616060c960e08792ed9122da32e3aa901076980fb49d558f967 3 | size 16260824 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 许可 2 | 3 | 本项目使用了JLink共享库,并未获得SEGGER授权,适用范围参考SEGGER说明,请勿用于非学习用途 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JLinkDLL 2 | 3 | 通过动态加载DLL调用JLink驱动的函数 4 | 5 | 现在函数基本齐全了 6 | 7 | 部分结构体和枚举等一些常量缺失,希望有好心人帮忙补全 8 | 9 | 编译器目前仅支持MSVC 10 | 11 | 支持Doxygen文档,如果安装了Doxygen能自动生成并安装到系统,但是不会生成快捷方式 12 | 13 | ## 更新日志 14 | 15 | 2022年3月21日 基本完成,待实机验证 16 | 17 | 2022年3月18日 第一次提交 -------------------------------------------------------------------------------- /version.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | JLinkDLL_SetDebugOutput(1); 6 | if (JLinkDLL_Init(nullptr)) { 7 | printf("Load DLL success\n"); 8 | uint32_t version = JLINKARM_GetDLLVersion(); 9 | printf("DLL version %d\n", version); 10 | } else { 11 | fprintf(stderr, "Error\n"); 12 | } 13 | JLinkDLL_DeInit(); 14 | return 0; 15 | } 16 | --------------------------------------------------------------------------------