Skip to content

Commit

Permalink
common/swo: Cleaned up the ITM decoder a touch to reduce duplication …
Browse files Browse the repository at this point in the history
…with the aux serial interface code, making use of `debug_serial_send_stdout()`
  • Loading branch information
dragonmux committed Oct 3, 2024
1 parent e9629d0 commit b022cdb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
7 changes: 3 additions & 4 deletions src/platforms/common/stm32/swo.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,11 @@ void swo_send_buffer(usbd_device *const dev, const uint8_t ep)
if (swo_itm_decoding) {
/* If we're in UART mode, hand as much as we can all at once */
if (swo_current_mode == swo_nrz_uart)
result = swo_itm_decode(dev, CDCACM_UART_ENDPOINT, swo_buffer + swo_buffer_read_index,
MIN(bytes_available, SWO_BUFFER_SIZE - swo_buffer_read_index));
result = swo_itm_decode(
swo_buffer + swo_buffer_read_index, MIN(bytes_available, SWO_BUFFER_SIZE - swo_buffer_read_index));
/* Otherwise, if we're in Manchester mode, manage the amount moved the same as we do USB */
else
result = swo_itm_decode(dev, CDCACM_UART_ENDPOINT, swo_buffer + swo_buffer_read_index,
MIN(bytes_available, SWO_ENDPOINT_SIZE));
result = swo_itm_decode(swo_buffer + swo_buffer_read_index, MIN(bytes_available, SWO_ENDPOINT_SIZE));
} else
/* Otherwise, queue the new data to the SWO data endpoint */
result = usbd_ep_write_packet(
Expand Down
9 changes: 2 additions & 7 deletions src/platforms/common/stm32/swo_itm_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@ static uint32_t itm_decode_mask = 0; /* bitmask of channels to print */
static uint8_t itm_packet_length = 0; /* decoder state */
static bool itm_decode_packet = false;

uint16_t swo_itm_decode(usbd_device *usbd_dev, uint8_t ep, const uint8_t *data, uint16_t len)
uint16_t swo_itm_decode(const uint8_t *data, uint16_t len)
{
/* Check if we've got a valid USB device */
/* XXX: Can this ever actually be false?! */
if (usbd_dev == NULL)
return 0U;

/* Step through each byte in the SWO data buffer */
for (uint16_t idx = 0; idx < len; ++idx) {
/* If we're waiting for a new ITM packet, start decoding the new byte as a header */
Expand All @@ -63,7 +58,7 @@ uint16_t swo_itm_decode(usbd_device *usbd_dev, uint8_t ep, const uint8_t *data,
if (itm_decoded_buffer_index == sizeof(itm_decoded_buffer)) {
/* However, if the link is not yet up, drop the packet data silently */
if (usb_get_config() && gdb_serial_get_dtr())
usbd_ep_write_packet(usbd_dev, ep, itm_decoded_buffer, itm_decoded_buffer_index);
debug_serial_send_stdout(itm_decoded_buffer, itm_decoded_buffer_index);
itm_decoded_buffer_index = 0U;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/common/swo.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void swo_send_buffer(usbd_device *dev, uint8_t ep);
void swo_itm_decode_set_mask(uint32_t mask);

/* Decode a new block of ITM data from SWO */
uint16_t swo_itm_decode(usbd_device *usbd_dev, uint8_t ep, const uint8_t *data, uint16_t len);
uint16_t swo_itm_decode(const uint8_t *data, uint16_t len);

#endif /* !NO_LIBOPENCM3 */

Expand Down

0 comments on commit b022cdb

Please sign in to comment.