From 2765811bbbd9a41d3de86234303be4679d60b096 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Wed, 15 Jun 2022 22:13:00 -0400 Subject: [PATCH] hosted/stlink: Naming consistency for 'stlink' global object --- src/platforms/hosted/stlinkv2.c | 107 ++++++++++++++++---------------- 1 file changed, 53 insertions(+), 54 deletions(-) diff --git a/src/platforms/hosted/stlinkv2.c b/src/platforms/hosted/stlinkv2.c index 62a8c45..dd97070 100644 --- a/src/platforms/hosted/stlinkv2.c +++ b/src/platforms/hosted/stlinkv2.c @@ -204,7 +204,7 @@ typedef struct { bool ap_error; } stlink_t; -stlink_t Stlink; +stlink_t stlink; static int stlink_usb_get_rw_status(bool verbose); @@ -271,7 +271,7 @@ static int stlink_usb_error_check(uint8_t *data, bool verbose) * Change in error status when reading outside RAM. * This fix allows CDT plugin to visualize memory. */ - Stlink.ap_error = true; + stlink.ap_error = true; if (verbose) DEBUG_WARN("STLINK_SWD_AP_FAULT\n"); return STLINK_ERROR_AP_FAULT; @@ -303,7 +303,7 @@ static int stlink_usb_error_check(uint8_t *data, bool verbose) case STLINK_SWD_AP_STICKY_ERROR: if (verbose) DEBUG_WARN("STLINK_SWD_AP_STICKY_ERROR\n"); - Stlink.ap_error = true; + stlink.ap_error = true; return STLINK_ERROR_FAIL; case STLINK_SWD_AP_STICKYORUN_ERROR: if (verbose) @@ -344,7 +344,7 @@ static int stlink_send_recv_retry(uint8_t *txbuf, size_t txsize, * with AP_FAULT and finally with ERROR_OK and the pending result. * Interpret AP_FAULT as AP_WAIT in this case. */ - Stlink.ap_error = false; + stlink.ap_error = false; res = STLINK_ERROR_WAIT; } if (first_res == STLINK_ERROR_OK) @@ -405,21 +405,21 @@ static int write_retry(uint8_t *cmdbuf, size_t cmdsize, */ static void stlink_version(bmp_info_t *info) { - if (Stlink.ver_hw == 30) { + if (stlink.ver_hw == 30) { uint8_t cmd[16] = {STLINK_APIV3_GET_VERSION_EX}; uint8_t data[12]; int size = send_recv(info->usb_link, cmd, 16, data, 12); if (size == -1) { DEBUG_WARN("[!] stlink_send_recv STLINK_APIV3_GET_VERSION_EX\n"); } - Stlink.ver_stlink = data[0]; - Stlink.ver_swim = data[1]; - Stlink.ver_jtag = data[2]; - Stlink.ver_mass = data[3]; - Stlink.ver_bridge = data[4]; - Stlink.block_size = 512; - Stlink.vid = data[3] << 9 | data[8]; - Stlink.pid = data[5] << 11 | data[10]; + stlink.ver_stlink = data[0]; + stlink.ver_swim = data[1]; + stlink.ver_jtag = data[2]; + stlink.ver_mass = data[3]; + stlink.ver_bridge = data[4]; + stlink.block_size = 512; + stlink.vid = data[3] << 9 | data[8]; + stlink.pid = data[5] << 11 | data[10]; } else { uint8_t cmd[16] = {STLINK_GET_VERSION}; uint8_t data[6]; @@ -427,27 +427,26 @@ static void stlink_version(bmp_info_t *info) if (size == -1) { DEBUG_WARN("[!] stlink_send_recv STLINK_GET_VERSION_EX\n"); } - Stlink.vid = data[3] << 8 | data[2]; - Stlink.pid = data[5] << 8 | data[4]; + stlink.vid = data[3] << 8 | data[2]; + stlink.pid = data[5] << 8 | data[4]; int version = data[0] << 8 | data[1]; /* Big endian here!*/ - Stlink.block_size = 64; - Stlink.ver_stlink = (version >> 12) & 0x0f; - Stlink.ver_jtag = (version >> 6) & 0x3f; - if ((Stlink.pid == PRODUCT_ID_STLINKV21_MSD) || - (Stlink.pid == PRODUCT_ID_STLINKV21)) { - Stlink.ver_mass = (version >> 0) & 0x3f; + stlink.block_size = 64; + stlink.ver_stlink = (version >> 12) & 0x0f; + stlink.ver_jtag = (version >> 6) & 0x3f; + if ((stlink.pid == PRODUCT_ID_STLINKV21_MSD) || + (stlink.pid == PRODUCT_ID_STLINKV21)) { + stlink.ver_mass = (version >> 0) & 0x3f; } else { - Stlink.ver_swim = (version >> 0) & 0x3f; + stlink.ver_swim = (version >> 0) & 0x3f; } } - DEBUG_INFO("STLink firmware version: V%dJ%d",Stlink.ver_stlink, - Stlink.ver_jtag); - if (Stlink.ver_hw == 30) { - DEBUG_INFO("M%dB%dS%d", Stlink.ver_mass, Stlink.ver_bridge, Stlink.ver_swim); - } else if (Stlink.ver_hw == 20) { - DEBUG_INFO("S%d", Stlink.ver_swim); - } else if (Stlink.ver_hw == 21) { - DEBUG_INFO("M%d", Stlink.ver_mass); + DEBUG_INFO("ST-Link firmware version: V%dJ%d",stlink.ver_stlink, stlink.ver_jtag); + if (stlink.ver_hw == 30) { + DEBUG_INFO("M%dB%dS%d", stlink.ver_mass, stlink.ver_bridge, stlink.ver_swim); + } else if (stlink.ver_hw == 20) { + DEBUG_INFO("S%d", stlink.ver_swim); + } else if (stlink.ver_hw == 21) { + DEBUG_INFO("M%d", stlink.ver_mass); } DEBUG_INFO("\n"); } @@ -567,23 +566,23 @@ int stlink_init(bmp_info_t *info) return 0; switch (info->pid) { case PRODUCT_ID_STLINKV2: - Stlink.ver_hw = 20; + stlink.ver_hw = 20; info->usb_link->ep_tx = 2; - Stlink.ep_tx = 2; + stlink.ep_tx = 2; break; case PRODUCT_ID_STLINKV21 : case PRODUCT_ID_STLINKV21_MSD: - Stlink.ver_hw = 21; + stlink.ver_hw = 21; info->usb_link->ep_tx = 1; - Stlink.ep_tx = 1; + stlink.ep_tx = 1; break; case PRODUCT_ID_STLINKV3_BL: case PRODUCT_ID_STLINKV3: case PRODUCT_ID_STLINKV3E: case PRODUCT_ID_STLINKV3_NO_MSD: - Stlink.ver_hw = 30; + stlink.ver_hw = 30; info->usb_link->ep_tx = 1; - Stlink.ep_tx = 1; + stlink.ep_tx = 1; break; default: DEBUG_INFO("Unhandled STM32 device\n"); @@ -613,8 +612,8 @@ int stlink_init(bmp_info_t *info) sl->req_trans = libusb_alloc_transfer(0); sl->rep_trans = libusb_alloc_transfer(0); stlink_version(info); - if ((Stlink.ver_stlink < 3 && Stlink.ver_jtag < 32) || - (Stlink.ver_stlink == 3 && Stlink.ver_jtag < 3)) { + if ((stlink.ver_stlink < 3 && stlink.ver_jtag < 32) || + (stlink.ver_stlink == 3 && stlink.ver_jtag < 3)) { /* Maybe the adapter is in some strange state. Try to reset */ int result = libusb_reset_device(sl->ul_libusb_device_handle); DEBUG_WARN("INFO: Trying Stlink reset\n"); @@ -628,8 +627,8 @@ int stlink_init(bmp_info_t *info) } stlink_version(info); } - if ((Stlink.ver_stlink < 3 && Stlink.ver_jtag < 32) || - (Stlink.ver_stlink == 3 && Stlink.ver_jtag < 3)) { + if ((stlink.ver_stlink < 3 && stlink.ver_jtag < 32) || + (stlink.ver_stlink == 3 && stlink.ver_jtag < 3)) { DEBUG_WARN("Please update Firmware\n"); return -1; } @@ -648,19 +647,19 @@ void stlink_nrst_set_val(bmp_info_t *info, bool assert) (assert)? STLINK_DEBUG_APIV2_DRIVE_NRST_LOW : STLINK_DEBUG_APIV2_DRIVE_NRST_HIGH}; uint8_t data[2]; - Stlink.nrst = assert; + stlink.nrst = assert; send_recv(info->usb_link, cmd, 16, data, 2); stlink_usb_error_check(data, true); } bool stlink_nrst_get_val(void) { - return Stlink.nrst; + return stlink.nrst; } int stlink_hwversion(void) { - return Stlink.ver_stlink; + return stlink.ver_stlink; } static int stlink_enter_debug_jtag(bmp_info_t *info) @@ -734,8 +733,8 @@ uint32_t stlink_dp_error(ADIv5_DP_t *dp) dp->fault = 0; if (err) DEBUG_WARN("stlink_dp_error %d\n", err); - err |= Stlink.ap_error; - Stlink.ap_error = false; + err |= stlink.ap_error; + stlink.ap_error = false; return err; } @@ -750,8 +749,8 @@ static int stlink_read_dp_register(uint16_t port, uint16_t addr, uint32_t *reg) STLINK_DEBUG_APIV2_READ_DAP_REG, port & 0xff, port >> 8, addr & 0xff, addr >> 8}; - if (port == STLINK_DEBUG_PORT_ACCESS && Stlink.dap_select) - cmd[4] = ((Stlink.dap_select & 0xf) << 4) | (addr & 0xf); + if (port == STLINK_DEBUG_PORT_ACCESS && stlink.dap_select) + cmd[4] = ((stlink.dap_select & 0xf) << 4) | (addr & 0xf); else cmd[4] = addr & 0xff; uint8_t data[8]; @@ -768,7 +767,7 @@ static int stlink_read_dp_register(uint16_t port, uint16_t addr, uint32_t *reg) static int stlink_write_dp_register(uint16_t port, uint16_t addr, uint32_t val) { if (port == STLINK_DEBUG_PORT_ACCESS && addr == 8) { - Stlink.dap_select = val; + stlink.dap_select = val; DEBUG_PROBE("Caching SELECT 0x%02" PRIx32 "\n", val); return STLINK_ERROR_OK; } else { @@ -823,7 +822,7 @@ static bool stlink_ap_setup(int ap) stlink_send_recv_retry(cmd, 16, data, 2); int res = stlink_usb_error_check(data, true); if (res) { - if (Stlink.ver_hw == 30) { + if (stlink.ver_hw == 30) { DEBUG_WARN("STLINKV3 only connects to STM8/32!\n"); } return false; @@ -862,7 +861,7 @@ static void stlink_readmem(ADIv5_AP_t *ap, void *dest, uint32_t src, size_t len) uint8_t type; if (src & 1 || len & 1) { type = STLINK_DEBUG_READMEM_8BIT; - if (len > Stlink.block_size) { + if (len > stlink.block_size) { DEBUG_WARN(" Too large!\n"); return; } @@ -902,8 +901,8 @@ static void stlink_writemem8(usb_link_t *link, ADIv5_AP_t *ap, uint32_t addr, while (len) { size_t length; /* OpenOCD has some note about writemem8*/ - if (len > Stlink.block_size) - length = Stlink.block_size; + if (len > stlink.block_size) + length = stlink.block_size; else length = len; uint8_t cmd[16] = { @@ -1115,7 +1114,7 @@ static int divisor; static unsigned int v3_freq[2]; void stlink_max_frequency_set(bmp_info_t *info, uint32_t freq) { - if (Stlink.ver_hw == 30) { + if (stlink.ver_hw == 30) { uint8_t cmd[16] = {STLINK_DEBUG_COMMAND, STLINK_APIV3_GET_COM_FREQ, info->is_jtag ? STLINK_MODE_JTAG : STLINK_MODE_SWD}; @@ -1188,7 +1187,7 @@ void stlink_max_frequency_set(bmp_info_t *info, uint32_t freq) uint32_t stlink_max_frequency_get(bmp_info_t *info) { uint32_t ret = 0; - if (Stlink.ver_hw == 30) { + if (stlink.ver_hw == 30) { ret = v3_freq[(info->is_jtag) ? STLINK_MODE_JTAG : STLINK_MODE_SWD]; } else { ret = V2_CLOCK_RATE;