JLinkARM.dll部分导出函数定义

JLink未对个人开放软件开发接口(SDK),无法进行二次开发,但通过研究发现,大部分接口都在JLinkARM.dll中实现。

JLinkARM是JLink调试器对ARM系列CPU的JTAG/SWD访问接口。

有了JLinkARM.dll的函数接口,我们就可以利用它进行2次开发,实现一些特定的功能,比如自定义烧录工具等。

以下是导出函数的原型(部分):

//JLINK TIF
#define JLINK_TIF_JTAG          0
#define JLINK_TIF_SWD           1

//RESET TYPE
#define JLINK_RESET_TYPE_NORMAL 0
#define JLINK_RESET_TYPE_CORE   1
#define JLINK_RESET_TYPE_PIN    2

//REGISTER INDEX
/* 
  0 - 15     R0 - R15(SP=R13, PC=R15)
 16          XPSR
 17          MSP
 18          PSP
 19          RAZ
 20          CFBP
 21          APSR
 22          EPSR
 23          IPSR
 24          PRIMASK
 25          BASEPRI
 26          FAULTMASK
 27          CONTROL 
 28          BASEPRI_MAX
 29          IAPSR
 30          EAPSR
 31          IEPSR
 */

void  (WINAPI *JLINK_SetLogFile)(char *file);
DWORD (WINAPI *JLINK_GetDLLVersion)(void);
DWORD (WINAPI *JLINK_GetHardwareVersion)(void);
DWORD (WINAPI *JLINK_GetFirmwareString)(char *buff, int count);
DWORD (WINAPI *JLINK_GetSN)(void);

BOOL  (WINAPI *JLINK_ExecCommand)(char* cmd, int a, int b);
DWORD (WINAPI *JLINK_TIF_Select)(int type);
void  (WINAPI *JLINK_SetSpeed)(int speed);
DWORD (WINAPI *JLINK_GetSpeed)(void);
DWORD (WINAPI *JLINK_GetId)(void);
DWORD (WINAPI *JLINK_GetDeviceFamily)(void);

BOOL  (WINAPI *JLINK_Open)(void);
void  (WINAPI *JLINK_Close)(void);
BOOL  (WINAPI *JLINK_IsOpen)(void);

BOOL  (WINAPI *JLINK_Connect)(void);
BOOL  (WINAPI *JLINK_IsConnected)(void);
int   (WINAPI *JLINK_Halt)(void);
BOOL  (WINAPI *JLINK_IsHalted)(void);
void  (WINAPI *JLINK_SetResetType)(int type);
void  (WINAPI *JLINK_Reset)(void);
void  (WINAPI *JLINK_Go)(void);
void  (WINAPI *JLINK_GoIntDis)(void);
DWORD (WINAPI *JLINK_ReadReg)(int index);
int   (WINAPI *JLINK_WriteReg)(int index, DWORD data);

int   (WINAPI *JLINK_ReadMem)(DWORD addr, int len, void *buf);
int   (WINAPI *JLINK_WriteMem)(DWORD addr, int len, void *buf);
int   (WINAPI *JLINK_WriteU8)(DWORD addr, BYTE data);
int   (WINAPI *JLINK_WriteU16)(DWORD addr, WORD data);
int   (WINAPI *JLINK_WriteU32)(DWORD addr, DWORD data);

int   (WINAPI *JLINK_EraseChip)(void);
int   (WINAPI *JLINK_DownloadFile)(LPCSTR file, DWORD addr);
void  (WINAPI *JLINK_BeginDownload)(int index);
void  (WINAPI *JLINK_EndDownload)(void);

之所以定义成函数指针,是为了使用Windows API函数GetProcAddress来获取该函数的地址。

    JLINK_GetDLLVersion      = (void*)GetProcAddress(hModule, "JLINK_GetDLLVersion");
    JLINK_GetHardwareVersion = (void*)GetProcAddress(hModule, "JLINK_GetHardwareVersion");
    JLINK_GetFirmwareString  = (void*)GetProcAddress(hModule, "JLINK_GetFirmwareString");
    JLINK_GetSN              = (void*)GetProcAddress(hModule, "JLINK_GetSN");
    JLINK_GetId              = (void*)GetProcAddress(hModule, "JLINK_GetId");
    JLINK_GetDeviceFamily    = (void*)GetProcAddress(hModule, "JLINK_GetDeviceFamily");
    
    JLINK_SetLogFile         = (void*)GetProcAddress(hModule, "JLINK_SetLogFile");
    JLINK_ExecCommand        = (void*)GetProcAddress(hModule, "JLINK_ExecCommand");
    
    JLINK_GetSpeed           = (void*)GetProcAddress(hModule, "JLINK_GetSpeed");
    JLINK_SetSpeed           = (void*)GetProcAddress(hModule, "JLINK_SetSpeed");
    JLINK_TIF_Select         = (void*)GetProcAddress(hModule, "JLINK_TIF_Select");
    
    JLINK_Open               = (void*)GetProcAddress(hModule, "JLINK_Open");
    JLINK_Close              = (void*)GetProcAddress(hModule, "JLINK_Close");
    JLINK_IsOpen             = (void*)GetProcAddress(hModule, "JLINK_IsOpen");
    
    JLINK_Connect            = (void*)GetProcAddress(hModule, "JLINK_Connect");
    JLINK_IsConnected        = (void*)GetProcAddress(hModule, "JLINK_IsConnected");
    JLINK_SetResetType       = (void*)GetProcAddress(hModule, "JLINK_SetResetType");
    JLINK_Reset              = (void*)GetProcAddress(hModule, "JLINK_Reset");
    JLINK_Halt               = (void*)GetProcAddress(hModule, "JLINK_Halt");
    JLINK_IsHalted           = (void*)GetProcAddress(hModule, "JLINK_IsHalted");
    JLINK_Go                 = (void*)GetProcAddress(hModule, "JLINK_Go");
    JLINK_GoIntDis           = (void*)GetProcAddress(hModule, "JLINK_GoIntDis");

    JLINK_ReadReg            = (void*)GetProcAddress(hModule, "JLINK_ReadReg");
    JLINK_WriteReg           = (void*)GetProcAddress(hModule, "JLINK_WriteReg");
    
    JLINK_ReadMem            = (void*)GetProcAddress(hModule, "JLINK_ReadMem");
    JLINK_WriteMem           = (void*)GetProcAddress(hModule, "JLINK_WriteMem");
    JLINK_WriteU8            = (void*)GetProcAddress(hModule, "JLINK_WriteU8");
    JLINK_WriteU16           = (void*)GetProcAddress(hModule, "JLINK_WriteU16");
    JLINK_WriteU32           = (void*)GetProcAddress(hModule, "JLINK_WriteU32");
    
    JLINK_EraseChip          = (void*)GetProcAddress(hModule, "JLINK_EraseChip");
    JLINK_DownloadFile       = (void*)GetProcAddress(hModule, "JLINK_DownloadFile");
    JLINK_BeginDownload      = (void*)GetProcAddress(hModule, "JLINK_BeginDownload");
    JLINK_EndDownload        = (void*)GetProcAddress(hModule, "JLINK_EndDownload");

 

测试代码:

    JLINK_SetLogFile("jlink.log");
    JLINK_Open();
    printf("Load driver OK.\n");
    printf("-----------------------------\n");
    printf("DLL Version:  %u\n", JLINK_GetDLLVersion());
    printf("HW Version:   %u\n", JLINK_GetHardwareVersion());
    printf("SerialNumber: %u\n", JLINK_GetSN());
    printf("-----------------------------\n");
    JLINK_ExecCommand("device = NRF51822_XXAC", 0, 0);
    JLINK_TIF_Select(JLINK_TIF_SWD);
    JLINK_SetSpeed(10000);
    printf("CPU ID:       0x%08X\n", JLINK_GetId());
    JLINK_Connect();
    JLINK_Halt();

 

    原文作者:星沉地动
    原文地址: https://blog.csdn.net/qq446252221/article/details/89878996
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞