/** */
static int stlink_usb_xfer_v1_get_status(void *handle)
{
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
/* read status */
memset(h->cmdbuf, 0, STLINK_SG_SIZE);
/** */
static int stlink_usb_xfer_rw(void *handle, int cmdsize, const uint8_t *buf, int size)
{
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
if (jtag_libusb_bulk_write(h->fd, STLINK_TX_EP, (char *)h->cmdbuf, cmdsize,
STLINK_WRITE_TIMEOUT) != cmdsize) {
return ERROR_FAIL;
static int stlink_usb_xfer_v1_get_sense(void *handle)
{
int res;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
stlink_usb_init_buffer(handle, STLINK_RX_EP, 16);
h->cmdbuf[h->cmdidx++] = REQUEST_SENSE;
static int stlink_usb_xfer(void *handle, const uint8_t *buf, int size)
{
int err, cmdsize = STLINK_CMD_SIZE_V2;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
if (h->version.stlink == 1)
cmdsize = STLINK_SG_SIZE;
/** */
static int stlink_usb_read_trace(void *handle, const uint8_t *buf, int size)
{
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
assert(h->version.stlink >= 2);
if (jtag_libusb_bulk_read(h->fd, STLINK_TRACE_EP, (char *)buf,
/** */
static void stlink_usb_xfer_v1_create_cmd(void *handle, uint8_t direction, uint32_t size)
{
- struct stlink_usb_handle_s *h;
-
- h = (struct stlink_usb_handle_s *)handle;
+ struct stlink_usb_handle_s *h = handle;
/* fill the send buffer */
strcpy((char *)h->cmdbuf, "USBC");
/** */
static void stlink_usb_init_buffer(void *handle, uint8_t direction, uint32_t size)
{
- struct stlink_usb_handle_s *h;
-
- h = (struct stlink_usb_handle_s *)handle;
+ struct stlink_usb_handle_s *h = handle;
h->direction = direction;
{
int res;
const char *err_msg = 0;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
/* TODO: no error checking yet on api V1 */
if (h->jtag_api == STLINK_JTAG_API_V1)
h->databuf[0] = STLINK_DEBUG_ERR_OK;
{
int res;
uint16_t v;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
stlink_usb_init_buffer(handle, STLINK_RX_EP, 6);
h->cmdbuf[h->cmdidx++] = STLINK_GET_VERSION;
static int stlink_usb_check_voltage(void *handle, float *target_voltage)
{
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
uint32_t adc_results[2];
- h = (struct stlink_usb_handle_s *)handle;
-
/* only supported by stlink/v2 and for firmware >= 13 */
if (h->version.stlink == 1 || h->version.jtag < 13)
return ERROR_COMMAND_NOTFOUND;
static int stlink_usb_current_mode(void *handle, uint8_t *mode)
{
int res;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
stlink_usb_init_buffer(handle, STLINK_RX_EP, 2);
h->cmdbuf[h->cmdidx++] = STLINK_GET_CURRENT_MODE;
{
int res;
int rx_size = 0;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
/* on api V2 we are able the read the latest command
* status
* TODO: we need the test on api V1 too
static int stlink_usb_mode_leave(void *handle, enum stlink_mode type)
{
int res;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
stlink_usb_init_buffer(handle, STLINK_NULL_EP, 0);
switch (type) {
int res;
uint8_t mode;
enum stlink_mode emode;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
res = stlink_usb_current_mode(handle, &mode);
if (res != ERROR_OK)
static int stlink_usb_idcode(void *handle, uint32_t *idcode)
{
int res;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
stlink_usb_init_buffer(handle, STLINK_RX_EP, 4);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
static int stlink_usb_v2_read_debug_reg(void *handle, uint32_t addr, uint32_t *val)
{
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
int res;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
stlink_usb_init_buffer(handle, STLINK_RX_EP, 8);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
static int stlink_usb_write_debug_reg(void *handle, uint32_t addr, uint32_t val)
{
int res;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
stlink_usb_init_buffer(handle, STLINK_RX_EP, 2);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
/** */
static void stlink_usb_trace_read(void *handle)
{
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
if (h->trace.enabled && h->version.jtag >= STLINK_TRACE_MIN_VERSION) {
int res;
static enum target_state stlink_usb_state(void *handle)
{
int res;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
if (h->jtag_api == STLINK_JTAG_API_V2)
return stlink_usb_v2_get_status(handle);
static int stlink_usb_reset(void *handle)
{
int res;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
stlink_usb_init_buffer(handle, STLINK_RX_EP, 2);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
static int stlink_usb_assert_srst(void *handle, int srst)
{
int res;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
if (h->jtag_api == STLINK_JTAG_API_V1)
return ERROR_COMMAND_NOTFOUND;
{
int res;
uint32_t reg;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
/* configure the TPI */
/* enable the trace subsystem */
static void stlink_usb_trace_disable(void *handle)
{
int res = ERROR_OK;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
assert(h->version.jtag >= STLINK_TRACE_MIN_VERSION);
LOG_DEBUG("Tracing: disable\n");
static int stlink_usb_trace_enable(void *handle)
{
int res;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
if (h->version.jtag >= STLINK_TRACE_MIN_VERSION) {
uint32_t trace_hz;
static int stlink_usb_run(void *handle)
{
int res;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
if (h->jtag_api == STLINK_JTAG_API_V2) {
res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_DEBUGEN);
static int stlink_usb_halt(void *handle)
{
int res;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
if (h->jtag_api == STLINK_JTAG_API_V2) {
res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_HALT|C_DEBUGEN);
static int stlink_usb_step(void *handle)
{
int res;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
if (h->jtag_api == STLINK_JTAG_API_V2) {
/* TODO: this emulates the v1 api, it should really use a similar auto mask isr
* that the cortex-m3 currently does. */
static int stlink_usb_read_regs(void *handle)
{
int res;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
stlink_usb_init_buffer(handle, STLINK_RX_EP, 84);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
static int stlink_usb_read_reg(void *handle, int num, uint32_t *val)
{
int res;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
stlink_usb_init_buffer(handle, STLINK_RX_EP, h->jtag_api == STLINK_JTAG_API_V1 ? 4 : 8);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
static int stlink_usb_write_reg(void *handle, int num, uint32_t val)
{
int res;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
stlink_usb_init_buffer(handle, STLINK_RX_EP, 2);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
static int stlink_usb_get_rw_status(void *handle)
{
int res;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
- h = (struct stlink_usb_handle_s *)handle;
-
if (h->jtag_api == STLINK_JTAG_API_V1)
return ERROR_OK;
{
int res;
uint16_t read_len = len;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
return ERROR_FAIL;
}
- h = (struct stlink_usb_handle_s *)handle;
-
stlink_usb_init_buffer(handle, STLINK_RX_EP, read_len);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
const uint8_t *buffer)
{
int res;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
return ERROR_FAIL;
}
- h = (struct stlink_usb_handle_s *)handle;
-
stlink_usb_init_buffer(handle, STLINK_TX_EP, len);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
uint8_t *buffer)
{
int res;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
return ERROR_TARGET_UNALIGNED_ACCESS;
}
- h = (struct stlink_usb_handle_s *)handle;
-
stlink_usb_init_buffer(handle, STLINK_RX_EP, len);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
const uint8_t *buffer)
{
int res;
- struct stlink_usb_handle_s *h;
+ struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
return ERROR_TARGET_UNALIGNED_ACCESS;
}
- h = (struct stlink_usb_handle_s *)handle;
-
stlink_usb_init_buffer(handle, STLINK_TX_EP, len);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
{
int retval = ERROR_OK;
uint32_t bytes_remaining;
- struct stlink_usb_handle_s *h = (struct stlink_usb_handle_s *)handle;
+ struct stlink_usb_handle_s *h = handle;
/* calculate byte count */
count *= size;
{
int retval = ERROR_OK;
uint32_t bytes_remaining;
- struct stlink_usb_handle_s *h = (struct stlink_usb_handle_s *)handle;
+ struct stlink_usb_handle_s *h = handle;
/* calculate byte count */
count *= size;
/** */
static int stlink_usb_close(void *fd)
{
- struct stlink_usb_handle_s *h;
-
- h = (struct stlink_usb_handle_s *)fd;
+ struct stlink_usb_handle_s *h = fd;
if (h->fd)
jtag_libusb_close(h->fd);