Skip to content

Commit 8654988

Browse files
Restructuring of stlink-lib
1 parent 2c92415 commit 8654988

24 files changed

+86
-65
lines changed

CMakeLists.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,41 +169,42 @@ add_subdirectory(inc)
169169

170170
## Define source- and headerfiles for stlink library
171171
set(STLINK_HEADERS
172-
inc/backend.h
173172
inc/stlink.h
173+
inc/stlink_backend.h
174+
inc/stlink_cmd.h
174175
inc/stm32.h
175-
inc/stm32flash.h
176+
inc/stm32_flash.h
176177
src/stlink-lib/calculate.h
177178
src/stlink-lib/chipid.h
178-
src/stlink-lib/commands.h
179179
src/stlink-lib/common_flash.h
180180
src/stlink-lib/flash_loader.h
181181
src/stlink-lib/helper.h
182182
src/stlink-lib/libusb_settings.h
183183
src/stlink-lib/lib_md5.h
184184
src/stlink-lib/logging.h
185+
src/stlink-lib/logging_spdlog_wr.h
185186
src/stlink-lib/map_file.h
186187
src/stlink-lib/md5.h
187188
src/stlink-lib/option_bytes.h
188-
src/stlink-lib/register.h
189-
src/stlink-lib/sg.h
189+
src/stlink-lib/read_write.h
190+
src/stlink-lib/sg_legacy.h
190191
src/stlink-lib/usb.h
191192
)
192193

193194
set(STLINK_SOURCE
194195
src/stlink-lib/calculate.c
195196
src/stlink-lib/chipid.c
196197
src/stlink-lib/common_flash.c
197-
src/stlink-lib/common.c
198+
src/stlink-lib/common_legacy.c
198199
src/stlink-lib/flash_loader.c
199200
src/stlink-lib/helper.c
201+
src/stlink-lib/lib_md5.c
200202
src/stlink-lib/logging.c
201203
src/stlink-lib/map_file.c
202-
src/stlink-lib/lib_md5.c
203204
src/stlink-lib/md5.c
204205
src/stlink-lib/option_bytes.c
205206
src/stlink-lib/read_write.c
206-
src/stlink-lib/sg.c
207+
src/stlink-lib/sg_legacy.c
207208
src/stlink-lib/usb.c
208209
)
209210

doc/flashloaders.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ As SRAM is usually less in size than FLASH, `stlink` only flashes one page (may
99
## The flashing process
1010

1111
1. `st-flash` loads compiled binary of corresponding flashloader to SRAM by calling `stlink_flash_loader_init` in `src/flash_loader.c`
12-
2. `st-flash` erases corresponding flash page by calling `stlink_erase_flash_page` in `common.c`.
12+
2. `st-flash` erases corresponding flash page by calling `stlink_erase_flash_page` in `common_legacy.c`.
1313
3. `st-flash` calls `stlink_flash_loader_run` in `flash_loader.c`. In this function
1414
+ buffer of one flash page is written to SRAM following the flashloader
1515
+ the buffer start address (in SRAM) is written to register `r0`

doc/tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ Check your hardware and try to identify what you have in front of you before ass
115115

116116
Please let us know, if you come across any further websites or tutorials that help to identify STM32 fake chips so we can list them here to help others.
117117

118-
### c) Appearance of the warning message `WARN src/common.c: unknown chip id!`
118+
### c) Appearance of the warning message `WARN src/common_legacy.c: unknown chip id!`
119119

120120
The chip ID is the main identifier for STM32 MCU and their specific type and provides primary information on flash and SRAM architecture.
121121
This so called `DBGMCU_IDCODE` register is allocated either at memory address `0xE0042000` or `0x40015800`.
122122

123-
A failure of chip identification results in the error `WARN src/common.c: unknown chip id!`.
123+
A failure of chip identification results in the error `WARN src/common_legacy.c: unknown chip id!`.
124124
There are different variants of this message that refer to different issues:
125125

126126
- `unknown chip id! 0` --> Target chip (board) is unknown.

inc/stlink.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <stdbool.h>
1313

1414
#include <stm32.h>
15-
#include <stm32flash.h>
15+
#include <stm32_flash.h>
1616

1717
#ifdef __cplusplus
1818
extern "C" {
@@ -184,8 +184,8 @@ enum run_type {
184184

185185
typedef struct _stlink stlink_t;
186186

187-
#include <stm32.h>
188-
#include <backend.h>
187+
#include "stm32.h"
188+
#include "stlink_backend.h"
189189

190190
struct _stlink {
191191
struct _stlink_backend *backend;
@@ -224,7 +224,7 @@ struct _stlink {
224224

225225
// bootloader
226226
// sys_base and sys_size are not used by the tools, but are only there to download the bootloader code
227-
// (see tests/sg.c)
227+
// (see tests/sg_legacy.c)
228228
stm32_addr_t sys_base; // stlink_chipid_params.bootrom_base, set by stlink_load_device_params()
229229
uint32_t sys_size; // stlink_chipid_params.bootrom_size, set by stlink_load_device_params()
230230

@@ -238,7 +238,7 @@ struct _stlink {
238238
uint32_t otp_size;
239239
};
240240

241-
/* Functions defined in common.c */
241+
/* Functions defined in common_legacy.c */
242242

243243
int32_t stlink_enter_swd_mode(stlink_t *sl);
244244
// int32_t stlink_enter_jtag_mode(stlink_t *sl);
@@ -271,13 +271,13 @@ int32_t stlink_fread(stlink_t* sl, const char* path, bool is_ihex, stm32_addr_t
271271
int32_t stlink_load_device_params(stlink_t *sl);
272272
int32_t stlink_target_connect(stlink_t *sl, enum connect_type connect);
273273

274+
#include <stlink_cmd.h>
274275
#include <chipid.h>
275-
#include <commands.h>
276276
#include <flash_loader.h>
277-
#include <sg.h>
277+
#include <logging.h>
278+
#include <sg_legacy.h>
278279
#include <usb.h>
279280
#include <version.h>
280-
#include <logging.h>
281281

282282
#ifdef __cplusplus
283283
}

inc/backend.h renamed to inc/stlink_backend.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
#ifndef BACKEND_H
2-
#define BACKEND_H
1+
/*
2+
* File: stlink_backend.h
3+
*
4+
* stlink backend
5+
*/
6+
7+
#ifndef STLINK_BACKEND_H
8+
#define STLINK_BACKEND_H
39

410
#include <stdint.h>
511

@@ -36,4 +42,4 @@
3642
int32_t (*trace_read) (stlink_t * sl, uint8_t* buf, uint32_t size);
3743
} stlink_backend_t;
3844

39-
#endif // BACKEND_H
45+
#endif // STLINK_BACKEND_H
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* File: commands.h
2+
* File: stlink_cmd.h
33
*
44
* stlink commands
55
*/
66

7-
#ifndef COMMANDS_H
8-
#define COMMANDS_H
7+
#ifndef STLINK_CMD_H
8+
#define STLINK_CMD_H
99

1010
enum stlink_commands {
1111
STLINK_GET_VERSION = 0xF1,
@@ -60,4 +60,4 @@ enum stlink_dfu_commands {
6060
STLINK_DFU_EXIT = 0x07
6161
};
6262

63-
#endif // COMMANDS_H
63+
#endif // STLINK_CMD_H

inc/stm32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ enum stm32_chipids {
169169
#define STM32_G4_OPTION_BYTES_BASE ((uint32_t) 0x1ffff800)
170170

171171
/* ============ */
172-
/* Old defines from common.c are below */
172+
/* Old defines from common_legacy.c are below */
173173
/* ============ */
174174

175175
/* Constant STM32 memory address */

inc/stm32flash.h renamed to inc/stm32_flash.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef STM32FLASH_H
2-
#define STM32FLASH_H
1+
#ifndef STM32_FLASH_H
2+
#define STM32_FLASH_H
33

44
#include <stdint.h>
55

@@ -434,4 +434,4 @@
434434
#define FLASH_WB_SR_PGAERR (5) /* Programming error */
435435
#define FLASH_WB_SR_BSY (16) /* Busy */
436436

437-
#endif // STM32FLASH_H
437+
#endif // STM32_FLASH_H
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* File: register.h
2+
* File: stm32_register.h
33
*
44
* Common STM32 registers
55
*/
66

7-
#ifndef REGISTER_H
8-
#define REGISTER_H
7+
#ifndef STM32_REGISTER_H
8+
#define STM32_REGISTER_H
99

1010
#define STLINK_REG_CM3_CPUID 0xE000ED00
1111

@@ -129,4 +129,4 @@
129129
#define STLINK_REG_CM7_ICIALLU 0xE000EF50
130130
#define STLINK_REG_CM7_CCSIDR 0xE000ED80
131131

132-
#endif // REGISTER_H
132+
#endif // STM32_REGISTER_H

src/st-trace/trace.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
#include <unistd.h>
1212

1313
#include <stlink.h>
14+
#include <stlink_backend.h>
15+
#include <stm32_register.h>
1416

1517
#include <chipid.h>
1618
#include <logging.h>
1719
#include <read_write.h>
18-
#include <register.h>
1920
#include <usb.h>
2021

2122
#define DEFAULT_LOGGING_LEVEL 50

0 commit comments

Comments
 (0)