Skip to content

Commit 5e85fd0

Browse files
Replace data types with fixed width typedefs (C99)
- Unified variable types (Closes #909) short --> int16_t unsigned short --> uint16_t int --> int32_t unsigned int --> uint32_t long --> int32_t unsigned long --> uint32_t long long --> int64_t unsigned long long --> uint64_t - Added missing header includes
1 parent a9c2139 commit 5e85fd0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+908
-836
lines changed

inc/backend.h

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
#ifndef BACKEND_H
22
#define BACKEND_H
33

4+
#include <stdint.h>
5+
46
typedef struct _stlink_backend {
57
void (*close) (stlink_t * sl);
6-
int (*exit_debug_mode) (stlink_t * sl);
7-
int (*enter_swd_mode) (stlink_t * sl);
8-
int (*enter_jtag_mode) (stlink_t * stl);
9-
int (*exit_dfu_mode) (stlink_t * stl);
10-
int (*core_id) (stlink_t * stl);
11-
int (*reset) (stlink_t * stl);
12-
int (*jtag_reset) (stlink_t * stl, int value);
13-
int (*run) (stlink_t * stl, enum run_type type);
14-
int (*status) (stlink_t * stl);
15-
int (*version) (stlink_t *sl);
16-
int (*read_debug32) (stlink_t *sl, uint32_t addr, uint32_t *data);
17-
int (*read_mem32) (stlink_t *sl, uint32_t addr, uint16_t len);
18-
int (*write_debug32) (stlink_t *sl, uint32_t addr, uint32_t data);
19-
int (*write_mem32) (stlink_t *sl, uint32_t addr, uint16_t len);
20-
int (*write_mem8) (stlink_t *sl, uint32_t addr, uint16_t len);
21-
int (*read_all_regs) (stlink_t *sl, struct stlink_reg * regp);
22-
int (*read_reg) (stlink_t *sl, int r_idx, struct stlink_reg * regp);
23-
int (*read_all_unsupported_regs) (stlink_t *sl, struct stlink_reg *regp);
24-
int (*read_unsupported_reg) (stlink_t *sl, int r_idx, struct stlink_reg *regp);
25-
int (*write_unsupported_reg) (stlink_t *sl, uint32_t value, int idx, struct stlink_reg *regp);
26-
int (*write_reg) (stlink_t *sl, uint32_t reg, int idx);
27-
int (*step) (stlink_t * stl);
28-
int (*current_mode) (stlink_t * stl);
29-
int (*force_debug) (stlink_t *sl);
8+
int32_t (*exit_debug_mode) (stlink_t * sl);
9+
int32_t (*enter_swd_mode) (stlink_t * sl);
10+
int32_t (*enter_jtag_mode) (stlink_t * stl);
11+
int32_t (*exit_dfu_mode) (stlink_t * stl);
12+
int32_t (*core_id) (stlink_t * stl);
13+
int32_t (*reset) (stlink_t * stl);
14+
int32_t (*jtag_reset) (stlink_t * stl, int32_t value);
15+
int32_t (*run) (stlink_t * stl, enum run_type type);
16+
int32_t (*status) (stlink_t * stl);
17+
int32_t (*version) (stlink_t *sl);
18+
int32_t (*read_debug32) (stlink_t *sl, uint32_t addr, uint32_t *data);
19+
int32_t (*read_mem32) (stlink_t *sl, uint32_t addr, uint16_t len);
20+
int32_t (*write_debug32) (stlink_t *sl, uint32_t addr, uint32_t data);
21+
int32_t (*write_mem32) (stlink_t *sl, uint32_t addr, uint16_t len);
22+
int32_t (*write_mem8) (stlink_t *sl, uint32_t addr, uint16_t len);
23+
int32_t (*read_all_regs) (stlink_t *sl, struct stlink_reg * regp);
24+
int32_t (*read_reg) (stlink_t *sl, int32_t r_idx, struct stlink_reg * regp);
25+
int32_t (*read_all_unsupported_regs) (stlink_t *sl, struct stlink_reg *regp);
26+
int32_t (*read_unsupported_reg) (stlink_t *sl, int32_t r_idx, struct stlink_reg *regp);
27+
int32_t (*write_unsupported_reg) (stlink_t *sl, uint32_t value, int32_t idx, struct stlink_reg *regp);
28+
int32_t (*write_reg) (stlink_t *sl, uint32_t reg, int32_t idx);
29+
int32_t (*step) (stlink_t * stl);
30+
int32_t (*current_mode) (stlink_t * stl);
31+
int32_t (*force_debug) (stlink_t *sl);
3032
int32_t (*target_voltage) (stlink_t *sl);
31-
int (*set_swdclk) (stlink_t * stl, int freq_khz);
32-
int (*trace_enable) (stlink_t * sl, uint32_t frequency);
33-
int (*trace_disable) (stlink_t * sl);
34-
int (*trace_read) (stlink_t * sl, uint8_t* buf, size_t size);
33+
int32_t (*set_swdclk) (stlink_t * stl, int32_t freq_khz);
34+
int32_t (*trace_enable) (stlink_t * sl, uint32_t frequency);
35+
int32_t (*trace_disable) (stlink_t * sl);
36+
int32_t (*trace_read) (stlink_t * sl, uint8_t* buf, size_t size);
3537
} stlink_backend_t;
3638

3739
#endif // BACKEND_H

inc/stlink.h

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,17 @@ struct _stlink {
196196
unsigned char c_buf[C_BUF_LEN];
197197
// data transferred from or to device
198198
unsigned char q_buf[Q_BUF_LEN];
199-
int q_len;
199+
int32_t q_len;
200200

201201
// transport layer verboseness: 0 for no debug info, 10 for lots
202-
int verbose;
203-
int opt;
202+
int32_t verbose;
203+
int32_t opt;
204204
uint32_t core_id; // set by stlink_core_id(), result from STLINK_DEBUGREADCOREID
205205
uint32_t chip_id; // set by stlink_load_device_params(), used to identify flash and sram
206206
enum target_state core_stat; // set by stlink_status()
207207

208208
char serial[STLINK_SERIAL_BUFFER_SIZE];
209-
int freq; // set by stlink_open_usb(), values: STLINK_SWDCLK_xxx_DIVISOR
209+
int32_t freq; // set by stlink_open_usb(), values: STLINK_SWDCLK_xxx_DIVISOR
210210

211211
enum stm32_flash_type flash_type;
212212
// stlink_chipid_params.flash_type, set by stlink_load_device_params(), values: STM32_FLASH_TYPE_xx
@@ -236,67 +236,67 @@ struct _stlink {
236236
uint32_t max_trace_freq; // set by stlink_open_usb()
237237
};
238238

239-
int stlink_enter_swd_mode(stlink_t *sl);
240-
int stlink_enter_jtag_mode(stlink_t *sl);
241-
int stlink_exit_debug_mode(stlink_t *sl);
242-
int stlink_exit_dfu_mode(stlink_t *sl);
239+
int32_t stlink_enter_swd_mode(stlink_t *sl);
240+
int32_t stlink_enter_jtag_mode(stlink_t *sl);
241+
int32_t stlink_exit_debug_mode(stlink_t *sl);
242+
int32_t stlink_exit_dfu_mode(stlink_t *sl);
243243
void stlink_close(stlink_t *sl);
244-
int stlink_core_id(stlink_t *sl);
245-
int stlink_reset(stlink_t *sl, enum reset_type type);
246-
int stlink_run(stlink_t *sl, enum run_type type);
247-
int stlink_status(stlink_t *sl);
248-
int stlink_version(stlink_t *sl);
249-
int stlink_read_debug32(stlink_t *sl, uint32_t addr, uint32_t *data);
250-
int stlink_read_mem32(stlink_t *sl, uint32_t addr, uint16_t len);
251-
int stlink_write_debug32(stlink_t *sl, uint32_t addr, uint32_t data);
252-
int stlink_write_mem32(stlink_t *sl, uint32_t addr, uint16_t len);
253-
int stlink_write_mem8(stlink_t *sl, uint32_t addr, uint16_t len);
254-
int stlink_read_all_regs(stlink_t *sl, struct stlink_reg *regp);
255-
int stlink_read_all_unsupported_regs(stlink_t *sl, struct stlink_reg *regp);
256-
int stlink_read_reg(stlink_t *sl, int r_idx, struct stlink_reg *regp);
257-
int stlink_read_unsupported_reg(stlink_t *sl, int r_idx, struct stlink_reg *regp);
258-
int stlink_write_unsupported_reg(stlink_t *sl, uint32_t value, int r_idx, struct stlink_reg *regp);
259-
int stlink_write_reg(stlink_t *sl, uint32_t reg, int idx);
260-
int stlink_step(stlink_t *sl);
261-
int stlink_current_mode(stlink_t *sl);
262-
int stlink_force_debug(stlink_t *sl);
263-
int stlink_target_voltage(stlink_t *sl);
264-
int stlink_set_swdclk(stlink_t *sl, int freq_khz);
265-
int stlink_trace_enable(stlink_t* sl, uint32_t frequency);
266-
int stlink_trace_disable(stlink_t* sl);
267-
int stlink_trace_read(stlink_t* sl, uint8_t* buf, size_t size);
268-
int stlink_erase_flash_mass(stlink_t* sl);
269-
int stlink_erase_flash_section(stlink_t *sl, stm32_addr_t base_addr, size_t size, bool align_size);
270-
int stlink_write_flash(stlink_t* sl, stm32_addr_t address, uint8_t* data, uint32_t length, uint8_t eraseonly);
271-
int stlink_parse_ihex(const char* path, uint8_t erased_pattern, uint8_t * * mem, size_t * size, uint32_t * begin);
244+
int32_t stlink_core_id(stlink_t *sl);
245+
int32_t stlink_reset(stlink_t *sl, enum reset_type type);
246+
int32_t stlink_run(stlink_t *sl, enum run_type type);
247+
int32_t stlink_status(stlink_t *sl);
248+
int32_t stlink_version(stlink_t *sl);
249+
int32_t stlink_read_debug32(stlink_t *sl, uint32_t addr, uint32_t *data);
250+
int32_t stlink_read_mem32(stlink_t *sl, uint32_t addr, uint16_t len);
251+
int32_t stlink_write_debug32(stlink_t *sl, uint32_t addr, uint32_t data);
252+
int32_t stlink_write_mem32(stlink_t *sl, uint32_t addr, uint16_t len);
253+
int32_t stlink_write_mem8(stlink_t *sl, uint32_t addr, uint16_t len);
254+
int32_t stlink_read_all_regs(stlink_t *sl, struct stlink_reg *regp);
255+
int32_t stlink_read_all_unsupported_regs(stlink_t *sl, struct stlink_reg *regp);
256+
int32_t stlink_read_reg(stlink_t *sl, int32_t r_idx, struct stlink_reg *regp);
257+
int32_t stlink_read_unsupported_reg(stlink_t *sl, int32_t r_idx, struct stlink_reg *regp);
258+
int32_t stlink_write_unsupported_reg(stlink_t *sl, uint32_t value, int32_t r_idx, struct stlink_reg *regp);
259+
int32_t stlink_write_reg(stlink_t *sl, uint32_t reg, int32_t idx);
260+
int32_t stlink_step(stlink_t *sl);
261+
int32_t stlink_current_mode(stlink_t *sl);
262+
int32_t stlink_force_debug(stlink_t *sl);
263+
int32_t stlink_target_voltage(stlink_t *sl);
264+
int32_t stlink_set_swdclk(stlink_t *sl, int32_t freq_khz);
265+
int32_t stlink_trace_enable(stlink_t* sl, uint32_t frequency);
266+
int32_t stlink_trace_disable(stlink_t* sl);
267+
int32_t stlink_trace_read(stlink_t* sl, uint8_t* buf, size_t size);
268+
int32_t stlink_erase_flash_mass(stlink_t* sl);
269+
int32_t stlink_erase_flash_section(stlink_t *sl, stm32_addr_t base_addr, size_t size, bool align_size);
270+
int32_t stlink_write_flash(stlink_t* sl, stm32_addr_t address, uint8_t* data, uint32_t length, uint8_t eraseonly);
271+
int32_t stlink_parse_ihex(const char* path, uint8_t erased_pattern, uint8_t * * mem, size_t * size, uint32_t * begin);
272272
uint8_t stlink_get_erased_pattern(stlink_t *sl);
273-
int stlink_mwrite_flash(stlink_t *sl, uint8_t* data, uint32_t length, stm32_addr_t addr);
274-
int stlink_fwrite_flash(stlink_t *sl, const char* path, stm32_addr_t addr);
275-
int stlink_mwrite_sram(stlink_t *sl, uint8_t* data, uint32_t length, stm32_addr_t addr);
276-
int stlink_fwrite_sram(stlink_t *sl, const char* path, stm32_addr_t addr);
277-
int stlink_verify_write_flash(stlink_t *sl, stm32_addr_t address, uint8_t *data, uint32_t length);
273+
int32_t stlink_mwrite_flash(stlink_t *sl, uint8_t* data, uint32_t length, stm32_addr_t addr);
274+
int32_t stlink_fwrite_flash(stlink_t *sl, const char* path, stm32_addr_t addr);
275+
int32_t stlink_mwrite_sram(stlink_t *sl, uint8_t* data, uint32_t length, stm32_addr_t addr);
276+
int32_t stlink_fwrite_sram(stlink_t *sl, const char* path, stm32_addr_t addr);
277+
int32_t stlink_verify_write_flash(stlink_t *sl, stm32_addr_t address, uint8_t *data, uint32_t length);
278278

279-
//int stlink_chip_id(stlink_t *sl, uint32_t *chip_id);
280-
int stlink_cpu_id(stlink_t *sl, cortex_m3_cpuid_t *cpuid);
279+
//int32_t stlink_chip_id(stlink_t *sl, uint32_t *chip_id);
280+
int32_t stlink_cpu_id(stlink_t *sl, cortex_m3_cpuid_t *cpuid);
281281

282-
int stlink_erase_flash_page(stlink_t* sl, stm32_addr_t flashaddr);
282+
int32_t stlink_erase_flash_page(stlink_t* sl, stm32_addr_t flashaddr);
283283
uint32_t stlink_calculate_pagesize(stlink_t *sl, uint32_t flashaddr);
284-
int stlink_check_address_range_validity(stlink_t *sl, stm32_addr_t addr, size_t size);
285-
int stlink_check_address_alignment(stlink_t *sl, stm32_addr_t addr);
286-
uint16_t read_uint16(const unsigned char *c, const int pt);
284+
int32_t stlink_check_address_range_validity(stlink_t *sl, stm32_addr_t addr, size_t size);
285+
int32_t stlink_check_address_alignment(stlink_t *sl, stm32_addr_t addr);
286+
uint16_t read_uint16(const unsigned char *c, const int32_t pt);
287287
//void stlink_core_stat(stlink_t *sl);
288288
void stlink_print_data(stlink_t *sl);
289-
unsigned int is_bigendian(void);
290-
uint32_t read_uint32(const unsigned char *c, const int pt);
289+
uint32_t is_bigendian(void);
290+
uint32_t read_uint32(const unsigned char *c, const int32_t pt);
291291
void write_uint32(unsigned char* buf, uint32_t ui);
292292
void write_uint16(unsigned char* buf, uint16_t ui);
293293
bool stlink_is_core_halted(stlink_t *sl);
294-
int write_buffer_to_sram(stlink_t *sl, flash_loader_t* fl, const uint8_t* buf, size_t size);
295-
int write_loader_to_sram(stlink_t *sl, stm32_addr_t* addr, size_t* size);
296-
int stlink_fread(stlink_t* sl, const char* path, bool is_ihex, stm32_addr_t addr, size_t size);
297-
int stlink_load_device_params(stlink_t *sl);
294+
int32_t write_buffer_to_sram(stlink_t *sl, flash_loader_t* fl, const uint8_t* buf, size_t size);
295+
int32_t write_loader_to_sram(stlink_t *sl, stm32_addr_t* addr, size_t* size);
296+
int32_t stlink_fread(stlink_t* sl, const char* path, bool is_ihex, stm32_addr_t addr, size_t size);
297+
int32_t stlink_load_device_params(stlink_t *sl);
298298

299-
int stlink_target_connect(stlink_t *sl, enum connect_type connect);
299+
int32_t stlink_target_connect(stlink_t *sl, enum connect_type connect);
300300

301301
#include <sg.h>
302302
#include <usb.h>

inc/stm32.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#ifndef STM32_H
88
#define STM32_H
99

10+
#include <stdint.h>
11+
1012
/* STM32 Cortex-M core ids (CPUTAPID) */
1113
enum stm32_core_id {
1214
STM32_CORE_ID_M0_SWD = 0x0bb11477, // (RM0091 Section 32.5.3) F0 SW-DP

inc/stm32flash.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef STM32FLASH_H
22
#define STM32FLASH_H
33

4+
#include <stdint.h>
5+
46
/* STM32Fx FPEC flash controller interface, PM0063 manual */
57
// STM32F05x is identical, based on RM0091 (DM00031936, Doc ID 018940 Rev.2, Aug 2012)
68
#define FLASH_REGS_ADDR 0x40022000

src/st-flash/flash.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* Simple wrapper around the stlink_flash_write function */
22

33
#include <stdio.h>
4+
#include <stdint.h>
45
#include <stdlib.h>
56
#include <string.h>
67

@@ -20,7 +21,7 @@
2021

2122
static stlink_t *connected_stlink = NULL;
2223

23-
static void cleanup(int signum) {
24+
static void cleanup(int32_t signum) {
2425
(void)signum;
2526

2627
if (connected_stlink) { // switch back to mass storage mode before closing
@@ -52,10 +53,10 @@ static void usage(void) {
5253
puts("example write option control register1 byte: ./st-flash --area=optcr1 write 0xXXXXXXXX");
5354
}
5455

55-
int main(int ac, char** av) {
56+
int32_t main(int32_t ac, char** av) {
5657
stlink_t* sl = NULL;
5758
struct flash_opts o;
58-
int err = -1;
59+
int32_t err = -1;
5960
uint8_t * mem = NULL;
6061

6162
o.size = 0;
@@ -82,7 +83,7 @@ int main(int ac, char** av) {
8283

8384
if ( o.flash_size != 0u && o.flash_size != sl->flash_size ) {
8485
sl->flash_size = o.flash_size;
85-
printf("Forcing flash size: --flash=0x%08X\n", (unsigned int)sl->flash_size);
86+
printf("Forcing flash size: --flash=0x%08X\n", (uint32_t)sl->flash_size);
8687
}
8788

8889
sl->verbose = o.log_level;
@@ -222,8 +223,8 @@ int main(int ac, char** av) {
222223
} else if (o.area == FLASH_OPTION_BYTES) {
223224
size_t remaining_option_length = sl->option_size / 4;
224225
DLOG("@@@@ Read %u (%#x) option bytes from %#10x\n",
225-
(unsigned)remaining_option_length,
226-
(unsigned)remaining_option_length,
226+
(uint32_t)remaining_option_length,
227+
(uint32_t)remaining_option_length,
227228
sl->option_base);
228229

229230
uint32_t option_byte = 0;
@@ -232,7 +233,7 @@ int main(int ac, char** av) {
232233
printf("could not read option bytes (%d)\n", err);
233234
goto on_error;
234235
} else if (NULL != o.filename) {
235-
int fd = open(o.filename, O_RDWR | O_TRUNC | O_CREAT | O_BINARY, 00700);
236+
int32_t fd = open(o.filename, O_RDWR | O_TRUNC | O_CREAT | O_BINARY, 00700);
236237
if (fd == -1) {
237238
fprintf(stderr, "open(%s) == -1\n", o.filename);
238239
goto on_error;

src/st-flash/flash.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ struct flash_opts {
1818
const char* filename;
1919
stm32_addr_t addr;
2020
size_t size;
21-
int reset;
22-
int log_level;
21+
int32_t reset;
22+
int32_t log_level;
2323
enum flash_format format;
2424
enum flash_area area;
2525
uint32_t val;
2626
size_t flash_size; // --flash=n[k, M]
27-
int opt; // enable empty tail data drop optimization
28-
int freq; // --freq=n[k, M] frequency of JTAG/SWD
27+
int32_t opt; // enable empty tail data drop optimization
28+
int32_t freq; // --freq=n[k, M] frequency of JTAG/SWD
2929
enum connect_type connect;
3030
};
3131

3232
#define FLASH_OPTS_INITIALIZER {0, { 0 }, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
3333

34-
int flash_get_opts(struct flash_opts* o, int ac, char** av);
34+
int32_t flash_get_opts(struct flash_opts* o, int32_t ac, char** av);
3535

3636
#endif // FLASH_H

src/st-flash/flash_opts.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <stdint.h>
12
#include <stdlib.h>
23
#include <stdio.h>
34
#include <string.h>
@@ -18,7 +19,7 @@ static bool starts_with(const char * str, const char * prefix) {
1819
// support decimal, hexadecimal, octal, binary format like 0xff 12 1k 1M, 0b1001
1920
// negative numbers are not supported
2021
// return 0 if success else return -1
21-
static int get_long_integer_from_char_array (const char *const str, uint64_t *read_value) {
22+
static int32_t get_long_integer_from_char_array (const char *const str, uint64_t *read_value) {
2223
uint64_t value;
2324
char *tail;
2425

@@ -50,9 +51,9 @@ static int get_long_integer_from_char_array (const char *const str, uint64_t *re
5051
// support decimal, hexadecimal, octal, binary format like 0xff 12 1k 1M, 0b1001
5152
// negative numbers are not supported
5253
// return 0 if success else return -1
53-
static int get_integer_from_char_array (const char *const str, uint32_t *read_value) {
54+
static int32_t get_integer_from_char_array (const char *const str, uint32_t *read_value) {
5455
uint64_t value;
55-
int result = get_long_integer_from_char_array (str, &value);
56+
int32_t result = get_long_integer_from_char_array (str, &value);
5657

5758
if (result != 0) {
5859
return(result);
@@ -65,24 +66,24 @@ static int get_integer_from_char_array (const char *const str, uint32_t *read_va
6566
}
6667
}
6768

68-
static int invalid_args(const char *expected) {
69+
static int32_t invalid_args(const char *expected) {
6970
fprintf(stderr, "*** Error: Expected args for this command: %s\n", expected);
7071
return(-1);
7172
}
7273

73-
static int bad_arg(const char *arg) {
74+
static int32_t bad_arg(const char *arg) {
7475
fprintf(stderr, "*** Error: Invalid value for %s\n", arg);
7576
return(-1);
7677
}
7778

78-
int flash_get_opts(struct flash_opts* o, int ac, char** av) {
79+
int32_t flash_get_opts(struct flash_opts* o, int32_t ac, char** av) {
7980

8081
// defaults
8182
memset(o, 0, sizeof(*o));
8283
o->log_level = STND_LOG_LEVEL;
8384

8485
// options
85-
int result;
86+
int32_t result;
8687

8788
while (ac >= 1) {
8889
if (strcmp(av[0], "--version") == 0) {

0 commit comments

Comments
 (0)