Skip to content

Commit

Permalink
Restructuring of stlink-lib
Browse files Browse the repository at this point in the history
- Sourcefiles for STLINK programmer handling
- Clean-up for stlink functions
  • Loading branch information
Nightwalker-87 committed Jan 12, 2025
1 parent ed5ea0d commit f2ad364
Show file tree
Hide file tree
Showing 6 changed files with 895 additions and 869 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ set(STLINK_HEADERS
src/stlink-lib/map_file.h
src/stlink-lib/md5.h
src/stlink-lib/option_bytes.h
src/stlink-lib/programmer.h
src/stlink-lib/read_write.h
src/stlink-lib/sg_legacy.h
src/stlink-lib/usb.h
Expand All @@ -203,6 +204,7 @@ set(STLINK_SOURCE
src/stlink-lib/map_file.c
src/stlink-lib/md5.c
src/stlink-lib/option_bytes.c
src/stlink-lib/programmer.c
src/stlink-lib/read_write.c
src/stlink-lib/sg_legacy.c
src/stlink-lib/usb.c
Expand Down
28 changes: 21 additions & 7 deletions inc/stlink.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*
* File: stlink.h
*
* All common top level stlink interfaces, regardless of how the backend does the work....
* All common top level stlink interfaces, regardless of how the backend does the work...
*/

#ifndef STLINK_H
#define STLINK_H

#include <stdint.h>
#include <stdio.h>
#include <stddef.h>
#include <stdbool.h>

Expand All @@ -21,7 +22,7 @@ extern "C" {
#define STLINK_ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))

/* Max data transfer size */
// 6kB = max mem32_read block, 8kB sram
// 6 kB = max mem32_read block, 8 kB sram
// #define Q_BUF_LEN 96
#define Q_BUF_LEN (1024 * 100)

Expand Down Expand Up @@ -238,16 +239,17 @@ struct _stlink {
uint32_t otp_size;
};

/* Functions defined in common_legacy.c */

/* === Declaration of functions defined in common_legacy.c === */

int32_t stlink_enter_swd_mode(stlink_t *sl);
// int32_t stlink_enter_jtag_mode(stlink_t *sl);
int32_t stlink_exit_debug_mode(stlink_t *sl);
int32_t stlink_exit_dfu_mode(stlink_t *sl);
void stlink_close(stlink_t *sl);
int32_t stlink_core_id(stlink_t *sl);
int32_t stlink_reset(stlink_t *sl, enum reset_type type);
int32_t stlink_run(stlink_t *sl, enum run_type type);
// void stlink_core_stat(stlink_t *sl);
int32_t stlink_status(stlink_t *sl);
int32_t stlink_version(stlink_t *sl);
int32_t stlink_step(stlink_t *sl);
Expand All @@ -261,16 +263,28 @@ int32_t stlink_mwrite_sram(stlink_t *sl, uint8_t* data, uint32_t length, stm32_a
int32_t stlink_fwrite_sram(stlink_t *sl, const char* path, stm32_addr_t addr);
int32_t stlink_cpu_id(stlink_t *sl, cortex_m3_cpuid_t *cpuid);
uint32_t stlink_calculate_pagesize(stlink_t *sl, uint32_t flashaddr);
//void stlink_core_stat(stlink_t *sl);
void stlink_print_data(stlink_t *sl);
uint32_t is_bigendian(void);
bool stlink_is_core_halted(stlink_t *sl);
int32_t write_buffer_to_sram(stlink_t *sl, flash_loader_t* fl, const uint8_t* buf, uint16_t size);
// int32_t write_loader_to_sram(stlink_t *sl, stm32_addr_t* addr, uint16_t* size);
int32_t stlink_fread(stlink_t* sl, const char* path, bool is_ihex, stm32_addr_t addr, uint32_t size);
// int32_t stlink_chip_id(stlink_t *sl, uint32_t *chip_id);
int32_t stlink_load_device_params(stlink_t *sl);
int32_t stlink_target_connect(stlink_t *sl, enum connect_type connect);

// ==================================================

void stlink_run_at(stlink_t *sl, stm32_addr_t addr);

// --------------------------------------------------

/* Deprecated functions */

// uint32_t is_bigendian(void);
// int32_t stlink_enter_jtag_mode(stlink_t *sl);
// int32_t write_loader_to_sram(stlink_t *sl, stm32_addr_t* addr, uint16_t* size);

// --------------------------------------------------

#include <stlink_cmd.h>
#include <chipid.h>
#include <flash_loader.h>
Expand Down
11 changes: 11 additions & 0 deletions inc/stlink_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,44 @@ enum stlink_commands {
STLINK_DFU_COMMAND = 0xF3,
STLINK_GET_CURRENT_MODE = 0xF5,
STLINK_GET_TARGET_VOLTAGE = 0xF7,

STLINK_GET_VERSION_APIV3 = 0xFB
};

enum stlink_debug_commands {
STLINK_DEBUG_ENTER_JTAG_RESET = 0x00,
STLINK_DEBUG_GETSTATUS = 0x01,
STLINK_DEBUG_FORCEDEBUG = 0x02,

STLINK_DEBUG_APIV1_RESETSYS = 0x03,
STLINK_DEBUG_APIV1_READALLREGS = 0x04,
STLINK_DEBUG_APIV1_READREG = 0x05,
STLINK_DEBUG_APIV1_WRITEREG = 0x06,

STLINK_DEBUG_READMEM_32BIT = 0x07,
STLINK_DEBUG_WRITEMEM_32BIT = 0x08,
STLINK_DEBUG_RUNCORE = 0x09,
STLINK_DEBUG_STEPCORE = 0x0a,

STLINK_DEBUG_APIV1_SETFP = 0x0b,

STLINK_DEBUG_WRITEMEM_8BIT = 0x0d,

STLINK_DEBUG_APIV1_CLEARFP = 0x0e,
STLINK_DEBUG_APIV1_WRITEDEBUGREG = 0x0f,
STLINK_DEBUG_APIV1_ENTER = 0x20,

STLINK_DEBUG_EXIT = 0x21,
STLINK_DEBUG_READCOREID = 0x22,

STLINK_DEBUG_APIV2_ENTER = 0x30,
STLINK_DEBUG_APIV2_READ_IDCODES = 0x31,
STLINK_DEBUG_APIV2_RESETSYS = 0x32,
STLINK_DEBUG_APIV2_READREG = 0x33,
STLINK_DEBUG_APIV2_WRITEREG = 0x34,
STLINK_DEBUG_APIV2_WRITEDEBUGREG = 0x35,
STLINK_DEBUG_APIV2_READDEBUGREG = 0x36,

STLINK_DEBUG_APIV2_READALLREGS = 0x3A,
STLINK_DEBUG_APIV2_GETLASTRWSTATUS = 0x3B,
STLINK_DEBUG_APIV2_DRIVE_NRST = 0x3C,
Expand All @@ -50,8 +59,10 @@ enum stlink_debug_commands {
STLINK_DEBUG_APIV2_STOP_TRACE_RX = 0x41,
STLINK_DEBUG_APIV2_GET_TRACE_NB = 0x42,
STLINK_DEBUG_APIV2_SWD_SET_FREQ = 0x43,

STLINK_DEBUG_APIV3_SET_COM_FREQ = 0x61,
STLINK_DEBUG_APIV3_GET_COM_FREQ = 0x62,

STLINK_DEBUG_ENTER_SWD = 0xa3,
STLINK_DEBUG_ENTER_JTAG_NO_RESET = 0xa4,
};
Expand Down
Loading

0 comments on commit f2ad364

Please sign in to comment.