OpenOCD
swim.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /*
4  * Copyright (C) 2020 by Antonio Borneo <borneo.antonio@gmail.com
5  *
6  * SWIM (Single Wire Interface Module) is a low-pin-count debug protocol
7  * used by STMicroelectronics MCU family STM8 and documented in UM470
8  * https://www.st.com/resource/en/user_manual/cd00173911.pdf
9  */
10 
11 #ifdef HAVE_CONFIG_H
12 #include "config.h"
13 #endif
14 
15 #include "interface.h"
16 #include "swim.h"
17 #include <helper/command.h>
18 #include <transport/transport.h>
19 
20 extern struct adapter_driver *adapter_driver;
21 
23 {
24  assert(adapter_driver->swim_ops);
25 
26  return adapter_driver->swim_ops->srst();
27 }
28 
29 int swim_read_mem(uint32_t addr, uint32_t size, uint32_t count,
30  uint8_t *buffer)
31 {
32  assert(adapter_driver->swim_ops);
33 
35 }
36 
37 int swim_write_mem(uint32_t addr, uint32_t size, uint32_t count,
38  const uint8_t *buffer)
39 {
40  assert(adapter_driver->swim_ops);
41 
43 }
44 
45 int swim_reconnect(void)
46 {
47  assert(adapter_driver->swim_ops);
48 
50 }
51 
52 COMMAND_HANDLER(handle_swim_newtap_command)
53 {
54  struct jtag_tap *tap;
55 
56  /*
57  * only need "basename" and "tap_type", but for backward compatibility
58  * ignore extra parameters
59  */
60  if (CMD_ARGC < 2)
62 
63  tap = calloc(1, sizeof(*tap));
64  if (!tap) {
65  LOG_ERROR("Out of memory");
66  return ERROR_FAIL;
67  }
68 
69  tap->chip = strdup(CMD_ARGV[0]);
70  tap->tapname = strdup(CMD_ARGV[1]);
71  tap->dotted_name = alloc_printf("%s.%s", CMD_ARGV[0], CMD_ARGV[1]);
72  if (!tap->chip || !tap->tapname || !tap->dotted_name) {
73  LOG_ERROR("Out of memory");
74  free(tap->dotted_name);
75  free(tap->tapname);
76  free(tap->chip);
77  free(tap);
78  return ERROR_FAIL;
79  }
80 
81  LOG_DEBUG("Creating new SWIM \"tap\", Chip: %s, Tap: %s, Dotted: %s",
82  tap->chip, tap->tapname, tap->dotted_name);
83 
84  /* default is enabled-after-reset */
85  tap->enabled = true;
86 
87  jtag_tap_init(tap);
88  return ERROR_OK;
89 }
90 
92  {
93  .name = "newtap",
94  .handler = handle_swim_newtap_command,
95  .mode = COMMAND_CONFIG,
96  .help = "Create a new TAP instance named basename.tap_type, "
97  "and appends it to the scan chain.",
98  .usage = "basename tap_type",
99  },
101 };
102 
104  {
105  .name = "swim",
106  .mode = COMMAND_ANY,
107  .help = "perform swim adapter actions",
108  .usage = "",
110  },
112 };
113 
114 static int swim_transport_select(struct command_context *cmd_ctx)
115 {
116  LOG_DEBUG(__func__);
117 
119 }
120 
121 static int swim_transport_init(struct command_context *cmd_ctx)
122 {
124 
125  LOG_DEBUG(__func__);
126 
130  else
131  LOG_WARNING("\'srst_nogate\' reset_config option is required");
132  } else
134 
135  return ERROR_OK;
136 }
137 
138 static struct transport swim_transport = {
139  .name = "swim",
140  .select = swim_transport_select,
141  .init = swim_transport_init,
142 };
143 
144 static void swim_constructor(void) __attribute__ ((constructor));
145 static void swim_constructor(void)
146 {
148 }
149 
151 {
153 }
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:155
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:385
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:150
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:247
static int register_commands(struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds)
Register one or more commands in the specified context, as children of parent (or top-level commends,...
Definition: command.h:268
@ COMMAND_CONFIG
Definition: command.h:41
@ COMMAND_ANY
Definition: command.h:42
struct esp_usb_jtag __attribute__
Definition: armv8.c:804
static enum reset_types jtag_reset_config
Definition: jtag/core.c:87
int adapter_deassert_reset(void)
Definition: jtag/core.c:1900
void jtag_tap_init(struct jtag_tap *tap)
Definition: jtag/core.c:1446
enum reset_types jtag_get_reset_config(void)
Definition: jtag/core.c:1734
int adapter_assert_reset(void)
Definition: jtag/core.c:1880
reset_types
Definition: jtag.h:212
@ RESET_SRST_NO_GATING
Definition: jtag.h:221
@ RESET_CNCT_UNDER_SRST
Definition: jtag.h:222
char * alloc_printf(const char *format,...)
Definition: log.c:366
#define LOG_WARNING(expr ...)
Definition: log.h:120
#define ERROR_FAIL
Definition: log.h:161
#define LOG_ERROR(expr ...)
Definition: log.h:123
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:155
uint32_t addr
Definition: nuttx.c:65
size_t size
Size of the control block search area.
Definition: rtt/rtt.c:30
Represents a driver for a debugging interface.
Definition: interface.h:207
const struct swim_driver * swim_ops
Definition: interface.h:354
const char * name
Definition: command.h:229
Definition: jtag.h:100
char * chip
Definition: jtag.h:101
char * tapname
Definition: jtag.h:102
bool enabled
Is this TAP currently enabled?
Definition: jtag.h:108
char * dotted_name
Definition: jtag.h:103
int(* read_mem)(uint32_t addr, uint32_t size, uint32_t count, uint8_t *buffer)
Read target memory through ROTF (read on-the-fly) command.
Definition: swim.h:36
int(* reconnect)(void)
Reconnect to the target.
Definition: swim.h:58
int(* write_mem)(uint32_t addr, uint32_t size, uint32_t count, const uint8_t *buffer)
Write target memory through WOTF (write on-the-fly) command.
Definition: swim.h:48
int(* srst)(void)
Send SRST (system reset) command to target.
Definition: swim.h:25
Wrapper for transport lifecycle operations.
Definition: transport.h:35
const char * name
Each transport has a unique name, used to select it from among the alternatives.
Definition: transport.h:41
static struct transport swim_transport
Definition: swim.c:138
bool transport_is_swim(void)
Definition: swim.c:150
static int swim_transport_select(struct command_context *cmd_ctx)
Definition: swim.c:114
static int swim_transport_init(struct command_context *cmd_ctx)
Definition: swim.c:121
int swim_read_mem(uint32_t addr, uint32_t size, uint32_t count, uint8_t *buffer)
Definition: swim.c:29
static void swim_constructor(void)
Definition: swim.c:144
int swim_reconnect(void)
Definition: swim.c:45
static const struct command_registration swim_transport_command_handlers[]
Definition: swim.c:103
static const struct command_registration swim_transport_subcommand_handlers[]
Definition: swim.c:91
int swim_system_reset(void)
Definition: swim.c:22
COMMAND_HANDLER(handle_swim_newtap_command)
Definition: swim.c:52
struct adapter_driver * adapter_driver
Definition: adapter.c:30
int swim_write_mem(uint32_t addr, uint32_t size, uint32_t count, const uint8_t *buffer)
Definition: swim.c:37
This file implements support for STMicroelectronics debug protocol SWIM (Single Wire Interface Module...
struct transport * get_current_transport(void)
Returns the transport currently being used by this debug or programming session.
Definition: transport.c:157
int transport_register(struct transport *new_transport)
Registers a transport.
Definition: transport.c:129
#define NULL
Definition: usb.h:16
uint8_t count[4]
Definition: vdebug.c:22