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 "adapter.h"
16 #include "interface.h"
17 #include "swim.h"
18 #include <helper/command.h>
19 #include <transport/transport.h>
20 
22 {
23  assert(adapter_driver->swim_ops);
24 
25  return adapter_driver->swim_ops->srst();
26 }
27 
28 int swim_read_mem(uint32_t addr, uint32_t size, uint32_t count,
29  uint8_t *buffer)
30 {
31  assert(adapter_driver->swim_ops);
32 
34 }
35 
36 int swim_write_mem(uint32_t addr, uint32_t size, uint32_t count,
37  const uint8_t *buffer)
38 {
39  assert(adapter_driver->swim_ops);
40 
42 }
43 
44 int swim_reconnect(void)
45 {
46  assert(adapter_driver->swim_ops);
47 
49 }
50 
51 COMMAND_HANDLER(handle_swim_newtap_command)
52 {
53  struct jtag_tap *tap;
54 
55  /*
56  * only need "basename" and "tap_type", but for backward compatibility
57  * ignore extra parameters
58  */
59  if (CMD_ARGC < 2)
61 
62  tap = calloc(1, sizeof(*tap));
63  if (!tap) {
64  LOG_ERROR("Out of memory");
65  return ERROR_FAIL;
66  }
67 
68  tap->chip = strdup(CMD_ARGV[0]);
69  tap->tapname = strdup(CMD_ARGV[1]);
70  tap->dotted_name = alloc_printf("%s.%s", CMD_ARGV[0], CMD_ARGV[1]);
71  if (!tap->chip || !tap->tapname || !tap->dotted_name) {
72  LOG_ERROR("Out of memory");
73  free(tap->dotted_name);
74  free(tap->tapname);
75  free(tap->chip);
76  free(tap);
77  return ERROR_FAIL;
78  }
79 
80  LOG_DEBUG("Creating new SWIM \"tap\", Chip: %s, Tap: %s, Dotted: %s",
81  tap->chip, tap->tapname, tap->dotted_name);
82 
83  /* default is enabled-after-reset */
84  tap->enabled = true;
85 
86  jtag_tap_init(tap);
87  return ERROR_OK;
88 }
89 
91  {
92  .name = "newtap",
93  .handler = handle_swim_newtap_command,
94  .mode = COMMAND_CONFIG,
95  .help = "Create a new TAP instance named basename.tap_type, "
96  "and appends it to the scan chain.",
97  .usage = "basename tap_type",
98  },
100 };
101 
103  {
104  .name = "swim",
105  .mode = COMMAND_ANY,
106  .help = "perform swim adapter actions",
107  .usage = "",
109  },
111 };
112 
113 static int swim_transport_select(struct command_context *cmd_ctx)
114 {
115  LOG_DEBUG(__func__);
116 
118 }
119 
120 static int swim_transport_init(struct command_context *cmd_ctx)
121 {
123 
124  LOG_DEBUG(__func__);
125 
129  else
130  LOG_WARNING("\'srst_nogate\' reset_config option is required");
131  } else
133 
134  return ERROR_OK;
135 }
136 
137 static struct transport swim_transport = {
138  .id = TRANSPORT_SWIM,
139  .select = swim_transport_select,
140  .init = swim_transport_init,
141 };
142 
143 static void swim_constructor(void) __attribute__ ((constructor));
144 static void swim_constructor(void)
145 {
147 }
148 
150 {
152 }
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:161
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:405
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:156
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:256
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:277
@ COMMAND_CONFIG
Definition: command.h:41
@ COMMAND_ANY
Definition: command.h:42
uint64_t buffer
Pointer to data buffer to send over SPI.
Definition: dw-spi-helper.h:0
uint32_t size
Size of dw_spi_transaction::buffer.
Definition: dw-spi-helper.h:4
static enum reset_types jtag_reset_config
Definition: jtag/core.c:89
int adapter_deassert_reset(void)
Definition: jtag/core.c:1910
void jtag_tap_init(struct jtag_tap *tap)
Definition: jtag/core.c:1458
enum reset_types jtag_get_reset_config(void)
Definition: jtag/core.c:1745
int adapter_assert_reset(void)
Definition: jtag/core.c:1890
reset_types
Definition: jtag.h:215
@ RESET_SRST_NO_GATING
Definition: jtag.h:224
@ RESET_CNCT_UNDER_SRST
Definition: jtag.h:225
char * alloc_printf(const char *format,...)
Definition: log.c:386
#define LOG_WARNING(expr ...)
Definition: log.h:144
#define ERROR_FAIL
Definition: log.h:188
#define LOG_ERROR(expr ...)
Definition: log.h:147
#define LOG_DEBUG(expr ...)
Definition: log.h:124
#define ERROR_OK
Definition: log.h:182
struct qn908x_flash_bank __attribute__
Definition: armv8.c:1060
target_addr_t addr
Start address to search for the control block.
Definition: rtt/rtt.c:28
Represents a driver for a debugging interface.
Definition: interface.h:208
const struct swim_driver * swim_ops
Definition: interface.h:363
const char * name
Definition: command.h:239
Definition: jtag.h:101
char * chip
Definition: jtag.h:102
char * tapname
Definition: jtag.h:103
bool enabled
Is this TAP currently enabled?
Definition: jtag.h:109
char * dotted_name
Definition: jtag.h:104
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:55
unsigned int id
Each transport has a unique ID, used to select it from among the alternatives.
Definition: transport.h:60
static struct transport swim_transport
Definition: swim.c:137
bool transport_is_swim(void)
Definition: swim.c:149
static int swim_transport_select(struct command_context *cmd_ctx)
Definition: swim.c:113
static int swim_transport_init(struct command_context *cmd_ctx)
Definition: swim.c:120
int swim_read_mem(uint32_t addr, uint32_t size, uint32_t count, uint8_t *buffer)
Definition: swim.c:28
static void swim_constructor(void)
Definition: swim.c:143
int swim_reconnect(void)
Definition: swim.c:44
static const struct command_registration swim_transport_command_handlers[]
Definition: swim.c:102
static const struct command_registration swim_transport_subcommand_handlers[]
Definition: swim.c:90
int swim_system_reset(void)
Definition: swim.c:21
COMMAND_HANDLER(handle_swim_newtap_command)
Definition: swim.c:51
int swim_write_mem(uint32_t addr, uint32_t size, uint32_t count, const uint8_t *buffer)
Definition: swim.c:36
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:252
int transport_register(struct transport *new_transport)
Registers a transport.
Definition: transport.c:211
#define TRANSPORT_SWIM
Definition: transport.h:25
#define NULL
Definition: usb.h:16
uint8_t count[4]
Definition: vdebug.c:22