|
楼主 |
发表于 2018-1-2 10:18:20
|
显示全部楼层
可以正确的读取芯片共享的内存的里面的值了,
// ConsoleApplication_jlinkArm.cpp : 定义控制台应用程序的入口点。
//use printf
#pragma comment(linker, "/subsystem:\"CONSOLE\" /entry:\"WinMainCRTStartup\"")
#include "stdafx.h"
#include "windows.h"
#include <iostream>
#pragma comment(lib, "JLinkARM.dll")
using namespace std;
#define DllImport __declspec( dllimport )
#define DllExport __declspec( dllexport )
#define BUF_MAX_SIZE 600
unsigned char buf[BUF_MAX_SIZE];
DWORD WINAPI ThreadProc(LPVOID lpParam)
{
///函数类型定义
typedef void(*pFunc_ReadMem)(unsigned int addr, unsigned int size, unsigned char *buf);
typedef unsigned int(*pFunc_ExecCommand)(char *device, unsigned char *pbuf, unsigned int size);
//加载动态库
HMODULE hMod = LoadLibrary("JLinkARM.dll");
///根据函数名获取函数指针
pFunc_ReadMem preadMem = (pFunc_ReadMem)GetProcAddress(hMod, TEXT("JLINKARM_ReadMem"));
pFunc_ExecCommand pexe = (pFunc_ExecCommand)GetProcAddress(hMod, TEXT("JLINKARM_ExecCommand"));
unsigned int ret = 0;
///选择芯片类型
ret = pexe("Device = Cortex-M3", buf, 64);
while (1)
{
//读取芯片指定内存地址
unsigned int curTick = GetTickCount();
preadMem(0x2000B000, BUF_MAX_SIZE, buf);
curTick = GetTickCount() - curTick;
for (unsigned int i = 0; i < 10; i++)
{
printf("buf[%d] is %02x,use tick %d\r\n",i, buf[i],curTick);
}
Sleep(1000);
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
HINSTANCE hinstanbceLib = LoadLibrary("JLinkARM.dll");
void * fun = GetProcAddress(hinstanbceLib, MAKEINTRESOURCE(219));
DWORD threadID;
HANDLE hThread;
hThread = CreateThread(NULL, 0, ThreadProc, NULL, 0, &threadID); // 创建线程
//必须加上这句话,不然子线程没有创建起来,主程序直接返回掉了
WaitForSingleObject(hThread, INFINITE);
//关闭内核对象
CloseHandle(hThread);
return 0;
}
|
|