+/** */
+int stlink_usb_read_mem8(void *handle, uint32_t addr, uint16_t len,
+ uint8_t *buffer)
+{
+ int res;
+ uint16_t read_len = len;
+ 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_READMEM_8BIT;
+ h_u32_to_le(h->txbuf + 2, addr);
+ h_u16_to_le(h->txbuf + 2 + 4, len);
+
+ /* we need to fix read length for single bytes */
+ if (read_len == 1)
+ read_len++;
+
+ res = stlink_usb_recv(handle, h->txbuf, STLINK_CMD_SIZE, h->rxbuf, read_len);
+
+ if (res != ERROR_OK)
+ return res;
+
+ memcpy(buffer, h->rxbuf, len);
+
+ return ERROR_OK;
+}
+
+/** */
+int stlink_usb_write_mem8(void *handle, uint32_t addr, uint16_t len,
+ const uint8_t *buffer)
+{
+ int res;
+ 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_WRITEMEM_8BIT;
+ h_u32_to_le(h->txbuf + 2, addr);
+ h_u16_to_le(h->txbuf + 2 + 4, len);
+
+ res = stlink_usb_recv(handle, h->txbuf, STLINK_CMD_SIZE, 0, 0);
+
+ if (res != ERROR_OK)
+ return res;
+
+ res = stlink_usb_recv(handle, (uint8_t *) buffer, len, 0, 0);
+
+ if (res != ERROR_OK)
+ return res;
+
+ return ERROR_OK;
+}
+