-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathExample1.cpp
More file actions
173 lines (142 loc) · 5.34 KB
/
Copy pathExample1.cpp
File metadata and controls
173 lines (142 loc) · 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
* \file Example1.cpp
* This example allows to execute some operations to the internal STM32 Flash memory. \n
* 1. Detect connected ST-LINK and display them. \n
* 2. Loop on each ST-LINK probes and execute the following operations: \n
* - Mass erase.
* - Single word edition (-w32).
* - Read 64 bytes from 0x08000000.
* - Sector erase.
* - Read 64 bytes from 0x08000000 .
* - System Reset. \n
*.
*Go to the source code : \ref STLINK_Example1
* \example STLINK_Example1
* This example allows to execute some operations to the internal STM32 Flash memory. \n
* 1. Detect connected ST-LINK and display them. \n
* 2. Loop on each St-LINK probes and execute the following operations: \n
* - Mass erase.
* - Single word edition (-w32).
* - Read 64 bytes from 0x08000000.
* - Sector erase.
* - Read 64 bytes from 0x08000000 .
* - System Reset. \n
* \code{.cpp}
**/
#include <stdio.h>
#include <iostream>
#include "DisplayManager.h"
#include <CubeProgrammer_API.h>
#pragma comment(lib, "CubeProgrammer_API.lib")
// Prerequisites for CubeProgrammer_API compile & link:
// - Include path needs $(ProjectDir)..\api\include or
// - Lib path needs $(ProjectDir)..\api\lib
// Prerequisites for CubeProgrammer_API debug/execution:
// - debuger environment needs: PATH=C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\api\lib;%PATH%
extern unsigned int verbosityLevel;
int Example1(void) {
logMessage(Title, "\n+++ Example 1 +++\n\n");
debugConnectParameters* stLinkList;
debugConnectParameters debugParameters;
generalInf* genInfo;
int getStlinkListNb = getStLinkList(&stLinkList, 0);
if (getStlinkListNb == 0)
{
logMessage(Error, "No STLINK available\n");
return 0;
}
else {
logMessage(Title, "\n-------- Connected ST-LINK Probes List --------");
for (int i = 0; i < getStlinkListNb; i++)
{
logMessage(Normal, "\nST-LINK Probe %d :\n", i);
logMessage(Info, " ST-LINK SN : %s \n", stLinkList[i].serialNumber);
logMessage(Info, " ST-LINK FW : %s \n", stLinkList[i].firmwareVersion);
}
logMessage(Title, "-----------------------------------------------\n\n");
}
for (int index = 0; index < getStlinkListNb; index++) {
logMessage(Title, "\n--------------------- ");
logMessage(Title, "\n ST-LINK Probe : %d ", index);
logMessage(Title, "\n--------------------- \n\n");
debugParameters = stLinkList[index];
debugParameters.connectionMode = HOTPLUG_MODE; // UNDER_RESET_MODE;
debugParameters.shared = 0;
/* Target connect */
int connectStlinkFlag = connectStLink(debugParameters);
if (connectStlinkFlag != 0) {
logMessage(Error, "Establishing connection with the device failed\n");
disconnect();
continue;
}
else {
logMessage(GreenInfo, "\n--- Device %d Connected --- \n", index);
}
/* Display device informations */
genInfo = getDeviceGeneralInf();
logMessage(Normal, "\nDevice name : %s ", genInfo->name);
logMessage(Normal, "\nDevice type : %s ", genInfo->type);
logMessage(Normal, "\nDevice CPU : %s \n", genInfo->cpu);
/* Reading 64 bytes from 0x08000000 */
unsigned char* dataStruct = 0;
int size = 64;
int startAddress = 0x08000000;
int readMemoryFlag = readMemory(startAddress, &dataStruct, size);
if (readMemoryFlag != 0)
{
disconnect();
continue;
}
logMessage(Normal, "\nReading 32-bit memory content\n");
logMessage(Normal, " Size : %d Bytes\n", size);
logMessage(Normal, " Address: : 0x%08X\n", startAddress);
int i = 0, col = 0;
while ((i < size))
{
col = 0;
logMessage(Normal, "\n0x%08X :", startAddress + i);
while ((col < 4) && (i < size))
{
logMessage(Info, " %08X ", *(unsigned int*)(dataStruct + i));
col++;
i += 4;
}
}
logMessage(Normal, "\n");
/* Process successfully Done */
disconnect();
}
deleteInterfaceList();
return 1;
}
int main()
{
int x = checkDeviceConnection();
int ret = 0;
const char* loaderPath = "C:/Program Files/STMicroelectronics/STM32Cube/STM32CubeProgrammer/api/lib/"; // reference directory that has ExternalLoader and FlashLoader.
displayCallBacks vsLogMsg;
/* Set device loaders path that contains FlashLoader and ExternalLoader folders*/
setLoadersPath(loaderPath);
/* Set the progress bar and message display functions callbacks */
vsLogMsg.logMessage = DisplayMessage;
vsLogMsg.initProgressBar = InitPBar;
vsLogMsg.loadBar = lBar;
setDisplayCallbacks(vsLogMsg);
/* Set DLL verbosity level */
//setVerbosityLevel(verbosityLevel = VERBOSITY_LEVEL_1);
ret = Example1();
//ret = Example2();
//ret = Example3();
//ret = Example_WB();
//ret = I2C_Example();
//ret = CAN_Example();
//ret = SPI_Example();
//ret = UART_Example();
//ret = USB_Example();
//ret = USB_Example_WB();
//ret = TSV_Flashing();
std::cout << "\n" << "Press enter to continue...";
std::cin.get();
return ret;
}
/** \endcode **/