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 efd1d64222 ("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
This commit is contained in:
Antonio Borneo
2020-01-26 17:00:55 +01:00
parent 93c4c0fcbe
commit ac18e960ce
4 changed files with 134 additions and 53 deletions

51
src/jtag/swim.c Normal file
View File

@@ -0,0 +1,51 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2020 by Antonio Borneo <borneo.antonio@gmail.com
*
* SWIM (Single Wire Interface Module) is a low-pin-count debug protocol
* used by STMicroelectronics MCU family STM8 and documented in UM470
* https://www.st.com/resource/en/user_manual/cd00173911.pdf
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "interface.h"
#include "swim.h"
#include "jtag/hla/hla_transport.h"
#include "jtag/hla/hla_interface.h"
#include "jtag/hla/hla_layout.h"
extern struct adapter_driver *adapter_driver;
int swim_system_reset(void)
{
assert(adapter_driver->hla_if);
return adapter_driver->hla_if->layout->api->reset(adapter_driver->hla_if->handle);
}
int swim_read_mem(uint32_t addr, uint32_t size, uint32_t count,
uint8_t *buffer)
{
assert(adapter_driver->hla_if);
return adapter_driver->hla_if->layout->api->read_mem(adapter_driver->hla_if->handle, addr, size, count, buffer);
}
int swim_write_mem(uint32_t addr, uint32_t size, uint32_t count,
const uint8_t *buffer)
{
assert(adapter_driver->hla_if);
return adapter_driver->hla_if->layout->api->write_mem(adapter_driver->hla_if->handle, addr, size, count, buffer);
}
int swim_reconnect(void)
{
assert(adapter_driver->hla_if);
return adapter_driver->hla_if->layout->api->state(adapter_driver->hla_if->handle);
}