diff options
author | Antonio Borneo <borneo.antonio@gmail.com> | 2020-01-26 17:00:55 +0100 |
---|---|---|
committer | Antonio Borneo <borneo.antonio@gmail.com> | 2020-05-24 21:29:42 +0100 |
commit | ac18e960ce79f06b22e71a17415be0feb741a482 (patch) | |
tree | 1f235cf901ec48a3d09cce24a5674ccea8b01df2 /src/jtag/swim.h | |
parent | 93c4c0fcbec1ebcb2ce19b37c39b63f10a91b9e8 (diff) | |
download | riscv-openocd-ac18e960ce79f06b22e71a17415be0feb741a482.zip riscv-openocd-ac18e960ce79f06b22e71a17415be0feb741a482.tar.gz riscv-openocd-ac18e960ce79f06b22e71a17415be0feb741a482.tar.bz2 |
swim: abstract the transport in stm8 target
SWIM is implemented by (ab)using the HLA API. This was acceptable
when OpenOCD code did not provided a clear separation between
transports and related APIs. Still today SWIM in OpenOCD is only
supported by STLink, so the decision to re-use the HLA API was the
simpler way to implement it.
After commit efd1d642220a ("adapter: switch from struct
jtag_interface to adapter_driver") the transports API are better
split and SWIM can be implemented as a separate set of API. This
would open the possibility to extend OpenOCD for other adapters
that provide SWIM, e.g. versaloon, or through SPI emulation [1].
Introduce a new set of files swim.[ch] to handle the SWIM API.
Beside the API that almost match the transport low-level data
communication (system_reset, read_mem, write_mem), add a further
API reconnect. Today, inside HLA STLink code, the reconnect is
implemented by hacking the HLA API state(). Please notice that
due to this hack the return type is incorrect; stlink_usb_state()
returns ERROR_OK in SWIM mode, while its return type is enum
target_state. Ignore the type mismatch and still call the HLA API
state in the new SWIM API reconnect. Further commit will fix it.
[1] http://kuku.eu.org/?projects/stm8spi/stm8spi
Change-Id: I52018e1e2200cbd41af8e5031f7b35dc761b61d6
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5528
Tested-by: jenkins
Diffstat (limited to 'src/jtag/swim.h')
-rw-r--r-- | src/jtag/swim.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/jtag/swim.h b/src/jtag/swim.h new file mode 100644 index 0000000..d0ae18e --- /dev/null +++ b/src/jtag/swim.h @@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/* + * Copyright (C) 2020 by Antonio Borneo <borneo.antonio@gmail.com + */ + +/** + * @file + * This file implements support for STMicroelectronics debug protocol SWIM + * (Single Wire Interface Module). + */ + +#ifndef OPENOCD_JTAG_SWIM_H +#define OPENOCD_JTAG_SWIM_H + +struct swim_driver { + /** + * Send SRST (system reset) command to target. + * + * @return ERROR_OK on success, else a fault code. + */ + int (*srst)(void); + + /** + * Read target memory through ROTF (read on-the-fly) command. + * + * @param addr Start address to read data from target memory. + * @param size Size in bytes of data units, 1, 2 or 4. + * @param count Number of units (size units, not bytes) to read. + * @param buffer Data buffer to receive data. + * @return ERROR_OK on success, else a fault code. + */ + int (*read_mem)(uint32_t addr, uint32_t size, uint32_t count, + uint8_t *buffer); + + /** + * Write target memory through WOTF (write on-the-fly) command. + * + * @param addr Start address to write data to target memory. + * @param size Size in bytes of data units, 1, 2 or 4. + * @param count Number of units (size units, not bytes) to write. + * @param buffer Data buffer to write. + * @return ERROR_OK on success, else a fault code. + */ + int (*write_mem)(uint32_t addr, uint32_t size, uint32_t count, + const uint8_t *buffer); + + /** + * Reconnect to the target. + * Should be reworked to be more generic and not linked to current + * implementation in stlink driver. + * + * @return ERROR_OK on success, else a fault code. + */ + int (*reconnect)(void); +}; + +int swim_system_reset(void); +int swim_read_mem(uint32_t addr, uint32_t size, uint32_t count, + uint8_t *buffer); +int swim_write_mem(uint32_t addr, uint32_t size, uint32_t count, + const uint8_t *buffer); +int swim_reconnect(void); + +#endif /* OPENOCD_JTAG_SWIM_H */ |