{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (h->version.flags & STLINK_F_HAS_RW8_512BYTES)
return STLINKV3_MAX_RW8;
{
int r, *completed = transfer->user_data;
- /* Assuming a single libusb context exists. There no existing interface into this
- * module to pass a libusb context.
- */
- struct libusb_context *ctx = NULL;
-
while (!*completed) {
- r = libusb_handle_events_completed(ctx, completed);
+ r = jtag_libusb_handle_events_completed(completed);
if (r < 0) {
if (r == LIBUSB_ERROR_INTERRUPTED)
continue;
transfers[i].transfer_size = 0;
transfers[i].transfer = libusb_alloc_transfer(0);
- if (transfers[i].transfer == NULL) {
+ if (!transfers[i].transfer) {
for (size_t j = 0; j < i; ++j)
libusb_free_transfer(transfers[j].transfer);
struct stlink_usb_handle_s *h = handle;
int tr, ret;
- assert(handle != NULL);
+ assert(handle);
/* read status */
memset(h->cmdbuf, 0, STLINK_SG_SIZE);
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
size_t n_transfers = 0;
struct jtag_xfer transfers[2];
struct stlink_usb_handle_s *h = handle;
int tr, ret;
- assert(handle != NULL);
+ assert(handle);
ret = jtag_libusb_bulk_write(h->usb_backend_priv.fd, h->tx_ep, (char *)h->cmdbuf,
cmdsize, STLINK_WRITE_TIMEOUT, &tr);
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 16);
int err, cmdsize = STLINK_CMD_SIZE_V2;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (h->version.stlink == 1) {
cmdsize = STLINK_SG_SIZE;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
/* send the TCP command */
int sent_size = send(h->tcp_backend_priv.fd, (void *)h->tcp_backend_priv.send_buf, send_size, 0);
int send_size = STLINK_TCP_USB_CMD_SIZE;
int recv_size = STLINK_TCP_SS_SIZE;
- assert(handle != NULL);
+ assert(handle);
/* prepare the TCP command */
h->tcp_backend_priv.send_buf[0] = STLINK_TCP_CMD_SEND_USB_CMD;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (h->st_mode == STLINK_MODE_DEBUG_SWIM) {
switch (h->databuf[0]) {
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
assert(h->version.flags & STLINK_F_HAS_TRACE);
char *p;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 6);
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (!(h->version.flags & STLINK_F_HAS_SWD_SET_FREQ))
return ERROR_COMMAND_NOTFOUND;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (!(h->version.flags & STLINK_F_HAS_JTAG_SET_FREQ))
return ERROR_COMMAND_NOTFOUND;
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 2);
int rx_size = 0;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
/* on api V2 we are able the read the latest command
* status
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
/* command with no reply, use a valid endpoint but zero size */
stlink_usb_init_buffer(handle, h->rx_ep, 0);
uint8_t mode;
enum stlink_mode emode;
- assert(handle != NULL);
+ assert(handle);
res = stlink_usb_current_mode(handle, &mode);
enum stlink_mode emode;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
res = stlink_usb_exit_mode(handle);
if (res != ERROR_OK)
}
}
- if (h->version.jtag_api == STLINK_JTAG_API_V3) {
+ if (h->version.jtag_api == STLINK_JTAG_API_V3 &&
+ (emode == STLINK_MODE_DEBUG_JTAG || emode == STLINK_MODE_DEBUG_SWD)) {
struct speed_map map[STLINK_V3_MAX_FREQ_NB];
stlink_get_com_freq(h, (emode == STLINK_MODE_DEBUG_JTAG), map);
int res, offset;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
/* there is no swim read core id cmd */
if (h->st_mode == STLINK_MODE_DEBUG_SWIM) {
struct stlink_usb_handle_s *h = handle;
int res;
- assert(handle != NULL);
+ assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 8);
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 2);
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (h->trace.enabled && (h->version.flags & STLINK_F_HAS_TRACE)) {
int res;
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (h->reconnect_pending) {
LOG_INFO("Previous state query failed, trying to reconnect");
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (h->st_mode == STLINK_MODE_DEBUG_SWIM)
return stlink_swim_assert_reset(handle, srst);
int res = ERROR_OK;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
assert(h->version.flags & STLINK_F_HAS_TRACE);
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (h->version.flags & STLINK_F_HAS_TRACE) {
stlink_usb_init_buffer(handle, h->rx_ep, 10);
struct stlink_usb_handle_s *h = handle;
int retval;
- assert(handle != NULL);
+ assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 2);
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (h->version.jtag_api != STLINK_JTAG_API_V1) {
res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_DEBUGEN);
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (h->version.jtag_api != STLINK_JTAG_API_V1) {
res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_HALT|C_DEBUGEN);
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (h->version.jtag_api != STLINK_JTAG_API_V1) {
/* TODO: this emulates the v1 api, it should really use a similar auto mask isr
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 88);
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (STLINK_REGSEL_IS_FPU(regsel) && !(h->version.flags & STLINK_F_HAS_FPU_REG)) {
res = stlink_usb_write_debug_reg(h, DCB_DCRSR, regsel & 0x7f);
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (STLINK_REGSEL_IS_FPU(regsel) && !(h->version.flags & STLINK_F_HAS_FPU_REG)) {
int res = stlink_usb_write_debug_reg(h, DCB_DCRDR, val);
if (res != ERROR_OK)
return res;
- return stlink_usb_write_debug_reg(h, DCB_DCRSR, DCRSR_WnR | (regsel & 0x7f));
+ return stlink_usb_write_debug_reg(h, DCB_DCRSR, DCRSR_WNR | (regsel & 0x7f));
/* FIXME: poll DHCSR.S_REGRDY after write DCRSR */
}
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (h->version.jtag_api == STLINK_JTAG_API_V1)
return ERROR_OK;
uint16_t read_len = len;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
/* max 8 bit read/write is 64 bytes or 512 bytes for v3 */
if (len > stlink_usb_block(h)) {
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
/* max 8 bit read/write is 64 bytes or 512 bytes for v3 */
if (len > stlink_usb_block(h)) {
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (!(h->version.flags & STLINK_F_HAS_MEM_16BIT))
return ERROR_COMMAND_NOTFOUND;
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (!(h->version.flags & STLINK_F_HAS_MEM_16BIT))
return ERROR_COMMAND_NOTFOUND;
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
/* data must be a multiple of 4 and word aligned */
if (len % 4 || addr % 4) {
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
/* data must be a multiple of 4 and word aligned */
if (len % 4 || addr % 4) {
/** */
static int stlink_close(void *handle)
{
- if (handle != NULL) {
+ if (handle) {
struct stlink_usb_handle_s *h = handle;
stlink_usb_close(handle);
/* else (len == 26) => buggy ST-Link */
char *alternate_serial = malloc((STLINK_SERIAL_LEN + 1) * sizeof(char));
- if (alternate_serial == NULL)
+ if (!alternate_serial)
return NULL;
for (unsigned int i = 0; i < STLINK_SERIAL_LEN; i += 2)
h->cmdbuf = malloc(STLINK_SG_SIZE);
h->databuf = malloc(STLINK_DATA_SIZE);
- if (h->cmdbuf == NULL || h->databuf == NULL)
+ if (!h->cmdbuf || !h->databuf)
return ERROR_FAIL;
/*
h->tcp_backend_priv.send_buf = malloc(STLINK_TCP_SEND_BUFFER_SIZE);
h->tcp_backend_priv.recv_buf = malloc(STLINK_TCP_RECV_BUFFER_SIZE);
- if (h->tcp_backend_priv.send_buf == NULL || h->tcp_backend_priv.recv_buf == NULL)
+ if (!h->tcp_backend_priv.send_buf || !h->tcp_backend_priv.recv_buf)
return ERROR_FAIL;
h->cmdbuf = &h->tcp_backend_priv.send_buf[8];
char serial[STLINK_TCP_SERIAL_SIZE + 1] = {0};
uint8_t stlink_used;
bool stlink_id_matched = false;
- bool stlink_serial_matched = (param->serial == NULL);
+ bool stlink_serial_matched = (!param->serial);
for (uint32_t stlink_id = 0; stlink_id < connected_stlinks; stlink_id++) {
/* get the stlink info */
return ERROR_OK;
}
- assert(trace_freq != NULL);
- assert(prescaler != NULL);
+ assert(trace_freq);
+ assert(prescaler);
if (pin_protocol != TPIU_PIN_PROTOCOL_ASYNC_UART) {
LOG_ERROR("The attached ST-LINK version doesn't support this trace mode");
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (!(h->version.flags & STLINK_F_HAS_AP_INIT))
return ERROR_COMMAND_NOTFOUND;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (!(h->version.flags & STLINK_F_HAS_AP_INIT))
return ERROR_COMMAND_NOTFOUND;
struct stlink_usb_handle_s *h = handle;
int retval;
- assert(handle != NULL);
+ assert(handle);
if (!(h->version.flags & STLINK_F_HAS_DAP_REG))
return ERROR_COMMAND_NOTFOUND;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
+ assert(handle);
if (!(h->version.flags & STLINK_F_HAS_DAP_REG))
return ERROR_COMMAND_NOTFOUND;