This is an automated email from Gerrit. Mathias K?ster ([email protected]) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/394
-- gerrit commit 7fb0109960b4f86bcd6fa5dab7eb8ea1e77703b4 Author: Mathias K <[email protected]> Date: Fri Jan 20 20:45:52 2012 +0100 Add stlink jtag support This patch add jtag support to the stlink driver and prepared the code for swim support. Change-Id: I20292a471b089dc9aba473b96cdec7c333e9377d Signed-off-by: Mathias K <[email protected]> diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c index cae468f..107f579 100644 --- a/src/jtag/drivers/stlink_usb.c +++ b/src/jtag/drivers/stlink_usb.c @@ -28,6 +28,7 @@ #include <helper/binarybuffer.h> #include <jtag/interface.h> #include <jtag/stlink/stlink_layout.h> +#include <jtag/stlink/stlink_transport.h> #include <jtag/stlink/stlink_interface.h> #include <target/target.h> @@ -52,6 +53,8 @@ struct stlink_usb_handle_s { uint8_t txbuf[STLINK_TX_SIZE]; /** */ uint8_t rxbuf[STLINK_RX_SIZE]; + /** */ + enum eSTLinkTransports transport; }; #define STLINK_OK 0x80 @@ -60,22 +63,24 @@ struct stlink_usb_handle_s { #define STLINK_CORE_HALTED 0x81 #define STLINK_CORE_STAT_UNKNOWN -1 -#define STLINK_GET_VERSION 0xf1 -#define STLINK_GET_CURRENT_MODE 0xf5 - +#define STLINK_GET_VERSION 0xF1 #define STLINK_DEBUG_COMMAND 0xF2 #define STLINK_DFU_COMMAND 0xF3 -#define STLINK_DFU_EXIT 0x07 +#define STLINK_SWIM_COMMAND 0xF4 +#define STLINK_GET_CURRENT_MODE 0xF5 #define STLINK_DEV_DFU_MODE 0x00 #define STLINK_DEV_MASS_MODE 0x01 #define STLINK_DEV_DEBUG_MODE 0x02 +#define STLINK_DEV_SWIM_MODE 0x03 #define STLINK_DEV_UNKNOWN_MODE -1 -#define STLINK_DEBUG_ENTER 0x20 -#define STLINK_DEBUG_EXIT 0x21 -#define STLINK_DEBUG_READCOREID 0x22 +#define STLINK_DFU_EXIT 0x07 + +#define STLINK_SWIM_ENTER 0x00 +#define STLINK_SWIM_EXIT 0x01 +#define STLINK_DEBUG_ENTER_JTAG 0x00 #define STLINK_DEBUG_GETSTATUS 0x01 #define STLINK_DEBUG_FORCEDEBUG 0x02 #define STLINK_DEBUG_RESETSYS 0x03 @@ -91,14 +96,26 @@ struct stlink_usb_handle_s { #define STLINK_DEBUG_WRITEMEM_8BIT 0x0d #define STLINK_DEBUG_CLEARFP 0x0e #define STLINK_DEBUG_WRITEDEBUGREG 0x0f -#define STLINK_DEBUG_ENTER_SWD 0xa3 + #define STLINK_DEBUG_ENTER_JTAG 0x00 +#define STLINK_DEBUG_ENTER_SWD 0xa3 -#define STLINK_SWD_ENTER 0x30 -#define STLINK_SWD_READCOREID 0x32 +#define STLINK_DEBUG_ENTER 0x20 +#define STLINK_DEBUG_EXIT 0x21 +#define STLINK_DEBUG_READCOREID 0x22 /** */ -int stlink_usb_recv(void *handle, const uint8_t *txbuf, int txsize, uint8_t *rxbuf, +enum eSTLinkMode { + eSTLinkModeUNKNOWN=0, + eSTLinkModeDFU, + eSTLinkModeMASS, + eSTLinkModeDebugJTAG, + eSTLinkModeDebugSWD, + eSTLinkModeDebugSWIM +}; + +/** */ +static int stlink_usb_recv(void *handle, const uint8_t *txbuf, int txsize, uint8_t *rxbuf, int rxsize) { struct stlink_usb_handle_s *h; @@ -121,7 +138,7 @@ int stlink_usb_recv(void *handle, const uint8_t *txbuf, int txsize, uint8_t *rxb } /** */ -void stlink_usb_init_buffer(void *handle) +static void stlink_usb_init_buffer(void *handle) { struct stlink_usb_handle_s *h; @@ -133,7 +150,7 @@ void stlink_usb_init_buffer(void *handle) } /** */ -int stlink_usb_version(void *handle) +static int stlink_usb_version(void *handle) { int res; uint16_t v; @@ -164,7 +181,7 @@ int stlink_usb_version(void *handle) } /** */ -int stlink_usb_current_mode(void *handle, uint8_t *mode) +static int stlink_usb_current_mode(void *handle, uint8_t *mode) { int res; struct stlink_usb_handle_s *h; @@ -188,7 +205,7 @@ int stlink_usb_current_mode(void *handle, uint8_t *mode) } /** */ -int stlink_usb_dfu_mode_leave(void *handle) +static int stlink_usb_mode_enter(void *handle, enum eSTLinkMode type) { int res; struct stlink_usb_handle_s *h; @@ -199,11 +216,29 @@ int stlink_usb_dfu_mode_leave(void *handle) stlink_usb_init_buffer(handle); - h->txbuf[0] = STLINK_DFU_COMMAND; - h->txbuf[1] = STLINK_DFU_EXIT; + switch(type) + { + case eSTLinkModeDebugJTAG: + h->txbuf[0] = STLINK_DEBUG_COMMAND; + h->txbuf[1] = STLINK_DEBUG_ENTER; + h->txbuf[2] = STLINK_DEBUG_ENTER_JTAG; + break; + case eSTLinkModeDebugSWD: + h->txbuf[0] = STLINK_DEBUG_COMMAND; + h->txbuf[1] = STLINK_DEBUG_ENTER; + h->txbuf[2] = STLINK_DEBUG_ENTER_SWD; + break; + case eSTLinkModeDebugSWIM: + h->txbuf[0] = STLINK_SWIM_COMMAND; + h->txbuf[1] = STLINK_SWIM_ENTER; + break; + case eSTLinkModeDFU: + case eSTLinkModeMASS: + default: + return ERROR_FAIL; + } res = stlink_usb_recv(handle, h->txbuf, STLINK_CMD_SIZE, 0, 0); - if (res != ERROR_OK) return res; @@ -211,7 +246,7 @@ int stlink_usb_dfu_mode_leave(void *handle) } /** */ -int stlink_usb_swd_mode_enter(void *handle) +static int stlink_usb_mode_leave(void *handle, enum eSTLinkMode type) { int res; struct stlink_usb_handle_s *h; @@ -222,9 +257,25 @@ int stlink_usb_swd_mode_enter(void *handle) stlink_usb_init_buffer(handle); - h->txbuf[0] = STLINK_DEBUG_COMMAND; - h->txbuf[1] = STLINK_DEBUG_ENTER; - h->txbuf[2] = STLINK_DEBUG_ENTER_SWD; + switch(type) + { + case eSTLinkModeDebugJTAG: + case eSTLinkModeDebugSWD: + h->txbuf[0] = STLINK_DEBUG_COMMAND; + h->txbuf[1] = STLINK_DEBUG_EXIT; + break; + case eSTLinkModeDebugSWIM: + h->txbuf[0] = STLINK_SWIM_COMMAND; + h->txbuf[1] = STLINK_SWIM_EXIT; + break; + case eSTLinkModeDFU: + h->txbuf[0] = STLINK_DFU_COMMAND; + h->txbuf[1] = STLINK_DFU_EXIT; + break; + case eSTLinkModeMASS: + default: + return ERROR_FAIL; + } res = stlink_usb_recv(handle, h->txbuf, STLINK_CMD_SIZE, 0, 0); if (res != ERROR_OK) @@ -234,35 +285,17 @@ int stlink_usb_swd_mode_enter(void *handle) } /** */ -int stlink_usb_debug_mode_leave(void *handle) +static int stlink_usb_init_mode(void *handle) { int res; + uint8_t mode; + enum eSTLinkMode emode; struct stlink_usb_handle_s *h; assert(handle != NULL); h = (struct stlink_usb_handle_s *)handle; - stlink_usb_init_buffer(handle); - - h->txbuf[0] = STLINK_DEBUG_COMMAND; - h->txbuf[1] = STLINK_DEBUG_EXIT; - - res = stlink_usb_recv(handle, h->txbuf, STLINK_CMD_SIZE, 0, 0); - if (res != ERROR_OK) - return res; - - return ERROR_OK; -} - -/** */ -int stlink_usb_init_mode(void *handle) -{ - int res; - uint8_t mode; - - assert(handle != NULL); - res = stlink_usb_current_mode(handle, &mode); if (res != ERROR_OK) @@ -270,8 +303,24 @@ int stlink_usb_init_mode(void *handle) LOG_DEBUG("MODE: %02X", mode); - if (mode == STLINK_DEV_DFU_MODE) { - res = stlink_usb_dfu_mode_leave(handle); + /* try to exit current mode */ + switch(mode) + { + case STLINK_DEV_DFU_MODE: + emode = eSTLinkModeDFU; + break; + case STLINK_DEV_DEBUG_MODE: + emode = eSTLinkModeDebugSWD; + break; + case STLINK_DEV_SWIM_MODE: + emode = eSTLinkModeDebugSWIM; + default: + emode = eSTLinkModeUNKNOWN; + break; + } + + if (emode != eSTLinkModeUNKNOWN) { + res = stlink_usb_mode_leave(handle,emode); if (res != ERROR_OK) return res; @@ -284,13 +333,30 @@ int stlink_usb_init_mode(void *handle) LOG_DEBUG("MODE: %02X", mode); - if (mode != STLINK_DEV_DEBUG_MODE) { - res = stlink_usb_swd_mode_enter(handle); + /* set selected mode */ + switch(h->transport) + { + case eSTLinkTransportSWD: + emode = eSTLinkModeDebugSWD; + break; + case eSTLinkTransportJTAG: + emode = eSTLinkModeDebugJTAG; + break; + case eSTLinkTransportSWIM: + default: + break; + } - if (res != ERROR_OK) - return res; + if (emode == eSTLinkModeUNKNOWN) { + LOG_ERROR("selected mode (transport) not supported"); + return ERROR_FAIL; } + res = stlink_usb_mode_enter(handle,emode); + + if (res != ERROR_OK) + return res; + res = stlink_usb_current_mode(handle, &mode); if (res != ERROR_OK) @@ -302,7 +368,7 @@ int stlink_usb_init_mode(void *handle) } /** */ -int stlink_usb_idcode(void *handle, uint32_t *idcode) +static int stlink_usb_idcode(void *handle, uint32_t *idcode) { int res; struct stlink_usb_handle_s *h; @@ -329,7 +395,7 @@ int stlink_usb_idcode(void *handle, uint32_t *idcode) } /** */ -enum target_state stlink_usb_state(void *handle) +static enum target_state stlink_usb_state(void *handle) { int res; struct stlink_usb_handle_s *h; @@ -357,7 +423,7 @@ enum target_state stlink_usb_state(void *handle) } /** */ -int stlink_usb_reset(void *handle) +static int stlink_usb_reset(void *handle) { int res; struct stlink_usb_handle_s *h; @@ -382,7 +448,7 @@ int stlink_usb_reset(void *handle) } /** */ -int stlink_usb_run(void *handle) +static int stlink_usb_run(void *handle) { int res; struct stlink_usb_handle_s *h; @@ -405,7 +471,7 @@ int stlink_usb_run(void *handle) } /** */ -int stlink_usb_halt(void *handle) +static int stlink_usb_halt(void *handle) { int res; struct stlink_usb_handle_s *h; @@ -428,7 +494,7 @@ int stlink_usb_halt(void *handle) } /** */ -int stlink_usb_step(void *handle) +static int stlink_usb_step(void *handle) { int res; struct stlink_usb_handle_s *h; @@ -451,7 +517,7 @@ int stlink_usb_step(void *handle) } /** */ -int stlink_usb_read_regs(void *handle) +static int stlink_usb_read_regs(void *handle) { int res; struct stlink_usb_handle_s *h; @@ -474,7 +540,7 @@ int stlink_usb_read_regs(void *handle) } /** */ -int stlink_usb_read_reg(void *handle, int num, uint32_t *val) +static int stlink_usb_read_reg(void *handle, int num, uint32_t *val) { int res; struct stlink_usb_handle_s *h; @@ -500,7 +566,7 @@ int stlink_usb_read_reg(void *handle, int num, uint32_t *val) } /** */ -int stlink_usb_write_reg(void *handle, int num, uint32_t val) +static int stlink_usb_write_reg(void *handle, int num, uint32_t val) { int res; struct stlink_usb_handle_s *h; @@ -525,7 +591,7 @@ int stlink_usb_write_reg(void *handle, int num, uint32_t val) } /** */ -int stlink_usb_read_mem8(void *handle, uint32_t addr, uint16_t len, +static int stlink_usb_read_mem8(void *handle, uint32_t addr, uint16_t len, uint8_t *buffer) { int res; @@ -558,7 +624,7 @@ int stlink_usb_read_mem8(void *handle, uint32_t addr, uint16_t len, } /** */ -int stlink_usb_write_mem8(void *handle, uint32_t addr, uint16_t len, +static int stlink_usb_write_mem8(void *handle, uint32_t addr, uint16_t len, const uint8_t *buffer) { int res; @@ -589,7 +655,7 @@ int stlink_usb_write_mem8(void *handle, uint32_t addr, uint16_t len, } /** */ -int stlink_usb_read_mem32(void *handle, uint32_t addr, uint16_t len, +static int stlink_usb_read_mem32(void *handle, uint32_t addr, uint16_t len, uint32_t *buffer) { int res; @@ -619,7 +685,7 @@ int stlink_usb_read_mem32(void *handle, uint32_t addr, uint16_t len, } /** */ -int stlink_usb_write_mem32(void *handle, uint32_t addr, uint16_t len, +static int stlink_usb_write_mem32(void *handle, uint32_t addr, uint16_t len, const uint32_t *buffer) { int res; @@ -652,8 +718,9 @@ int stlink_usb_write_mem32(void *handle, uint32_t addr, uint16_t len, } /** */ -int stlink_usb_open(struct stlink_interface_param_s *param, void **fd) +static int stlink_usb_open(struct stlink_interface_param_s *param, void **fd) { + int err; struct stlink_usb_handle_s *h; LOG_DEBUG("stlink_usb_open"); @@ -665,6 +732,8 @@ int stlink_usb_open(struct stlink_interface_param_s *param, void **fd) return ERROR_FAIL; } + h->transport = param->transport; + const uint16_t vids[] = { param->vid, 0 }; const uint16_t pids[] = { param->pid, 0 }; @@ -683,7 +752,13 @@ int stlink_usb_open(struct stlink_interface_param_s *param, void **fd) return ERROR_FAIL; } - stlink_usb_init_mode(h); + err = stlink_usb_init_mode(h); + + if (err != ERROR_OK) { + jtag_libusb_close(h->fd); + free(h); + return err; + } stlink_usb_version(h); @@ -693,10 +768,18 @@ int stlink_usb_open(struct stlink_interface_param_s *param, void **fd) } /** */ -struct stlink_layout_api_s stlink_layout_api = { +static int stlink_usb_close(void *fd) +{ + return ERROR_OK; +} + +/** */ +struct stlink_layout_api_s stlink_usb_layout_api = { /** */ .open = stlink_usb_open, /** */ + .close = stlink_usb_close, + /** */ .idcode = stlink_usb_idcode, /** */ .state = stlink_usb_state, diff --git a/src/jtag/stlink/stlink_interface.c b/src/jtag/stlink/stlink_interface.c index fc5edc6..3d573e5 100644 --- a/src/jtag/stlink/stlink_interface.c +++ b/src/jtag/stlink/stlink_interface.c @@ -28,16 +28,20 @@ #include <jtag/stlink/stlink_tcl.h> #include <jtag/stlink/stlink_layout.h> +#include <jtag/stlink/stlink_transport.h> #include <jtag/stlink/stlink_interface.h> #include <target/target.h> -static struct stlink_interface_s stlink_if = { {0, 0, 0, 0}, 0, 0 }; +static struct stlink_interface_s stlink_if = { {0, 0, 0, 0, 0}, 0, 0 }; -int stlink_interface_open(void) +int stlink_interface_open(enum eSTLinkTransports tr) { LOG_DEBUG("stlink_interface_open"); + /* set transport mode */ + stlink_if.param.transport = tr; + return stlink_if.layout->open(&stlink_if); } @@ -45,6 +49,8 @@ int stlink_interface_init_target(struct target *t) { int res; + LOG_DEBUG("stlink_interface_init_target"); + /* this is the interface for the current target and we * can setup the private pointer in the tap structure * if the interface match the tap idcode diff --git a/src/jtag/stlink/stlink_interface.h b/src/jtag/stlink/stlink_interface.h index 9b3f791..a80fb2c 100644 --- a/src/jtag/stlink/stlink_interface.h +++ b/src/jtag/stlink/stlink_interface.h @@ -22,6 +22,7 @@ /** */ struct target; +enum eSTLinkTransports; /** */ extern const char *stlink_transports[]; @@ -34,6 +35,8 @@ struct stlink_interface_param_s { uint16_t vid; /** */ uint16_t pid; + /** */ + enum eSTLinkTransports transport; }; struct stlink_interface_s { @@ -46,7 +49,7 @@ struct stlink_interface_s { }; /** */ -int stlink_interface_open(void); +int stlink_interface_open(enum eSTLinkTransports tr); /** */ int stlink_interface_init_target(struct target *t); diff --git a/src/jtag/stlink/stlink_layout.c b/src/jtag/stlink/stlink_layout.c index 4d510bb..0681d2a 100644 --- a/src/jtag/stlink/stlink_layout.c +++ b/src/jtag/stlink/stlink_layout.c @@ -29,6 +29,7 @@ #include <jtag/stlink/stlink_layout.h> #include <jtag/stlink/stlink_tcl.h> +#include <jtag/stlink/stlink_transport.h> #include <jtag/stlink/stlink_interface.h> #define STLINK_LAYOUT_UNKNOWN 0 @@ -46,7 +47,7 @@ static int stlink_layout_open(struct stlink_interface_s *stlink_if) res = stlink_if->layout->api->open(&stlink_if->param, &stlink_if->fd); if (res != ERROR_OK) { - LOG_DEBUG("stlink_layout_open: failed"); + LOG_DEBUG("failed"); return res; } @@ -64,7 +65,7 @@ static const struct stlink_layout stlink_layouts[] = { .type = STLINK_LAYOUT_USB, .open = stlink_layout_open, .close = stlink_layout_close, - .api = &stlink_layout_api, + .api = &stlink_usb_layout_api, }, {.name = NULL, /* END OF TABLE */ }, }; diff --git a/src/jtag/stlink/stlink_layout.h b/src/jtag/stlink/stlink_layout.h index bf1e2c6..caae828 100644 --- a/src/jtag/stlink/stlink_layout.h +++ b/src/jtag/stlink/stlink_layout.h @@ -25,7 +25,7 @@ struct stlink_interface_s; struct stlink_interface_param_s; /** */ -extern struct stlink_layout_api_s stlink_layout_api; +extern struct stlink_layout_api_s stlink_usb_layout_api; /** */ struct stlink_layout_api_s { diff --git a/src/jtag/stlink/stlink_transport.c b/src/jtag/stlink/stlink_transport.c index 6943ed2..6c427df 100644 --- a/src/jtag/stlink/stlink_transport.c +++ b/src/jtag/stlink/stlink_transport.c @@ -166,7 +166,7 @@ static int stlink_transport_init(struct command_context *cmd_ctx) else if (strcmp(transport->name, "stlink_swim") == 0) tr = eSTLinkTransportSWIM; - int retval = stlink_interface_open(); + int retval = stlink_interface_open(tr); if (retval != ERROR_OK) return retval; diff --git a/src/target/stm32_stlink.c b/src/target/stm32_stlink.c index dec2b24..fee6153 100644 --- a/src/target/stm32_stlink.c +++ b/src/target/stm32_stlink.c @@ -22,6 +22,7 @@ #endif #include "jtag/jtag.h" +#include "jtag/stlink/stlink_transport.h" #include "jtag/stlink/stlink_interface.h" #include "jtag/stlink/stlink_layout.h" #include "register.h" -- ------------------------------------------------------------------------------ Keep Your Developer Skills Current with LearnDevNow! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-d2d _______________________________________________ OpenOCD-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openocd-devel
