Skip to content

Commit

Permalink
ports/stm32: Fix USBD CDC debug.
Browse files Browse the repository at this point in the history
Revert the temporary debug buffer as packets apparently get sent
in IRQs, so they must be copied to a temp buffer.
  • Loading branch information
iabdalkader committed Aug 12, 2024
1 parent 8f6a976 commit f9d41b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions ports/stm32/usbd_cdc_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
#define IDE_BAUDRATE_SLOW (921600)
#define IDE_BAUDRATE_FAST (12000000)

void usb_cdc_reset_buffers();
void usb_cdc_reset_buffers(void);

// Used to control the connect_state variable when USB host opens the serial port
static uint8_t usbd_cdc_connect_tx_timer;
Expand Down Expand Up @@ -157,7 +157,7 @@ int8_t usbd_cdc_control(usbd_cdc_state_t *cdc_in, uint8_t cmd, uint8_t *pbuf, ui
MICROPY_BOARD_ENTER_BOOTLOADER(0, 0);
}
#endif
usb_cdc_reset_buffers(cdc);
usb_cdc_reset_buffers();
break;
}

Expand Down Expand Up @@ -339,7 +339,7 @@ void usbd_cdc_rx_check_resume(usbd_cdc_itf_t *cdc) {
enable_irq(irq_state);
}

uint32_t usb_cdc_buf_len() {
uint32_t usb_cdc_buf_len(void) {
usbd_cdc_itf_t *cdc = usb_vcp_get(0);
cdc->tx_buf_ptr_out = cdc->tx_buf_ptr_out_next;
if (usbd_cdc_tx_buffer_empty(cdc)) {
Expand All @@ -363,11 +363,12 @@ uint32_t usb_cdc_read(void *buf, uint32_t len) {

uint32_t usb_cdc_write(const void *buf, uint32_t len) {
usbd_cdc_itf_t *cdc = usb_vcp_get(0);
USBD_CDC_TransmitPacket(&cdc->base, len, buf);
memcpy(cdc->dbg_xfer_buffer, buf, len);
USBD_CDC_TransmitPacket(&cdc->base, len, cdc->dbg_xfer_buffer);
return len;
}

void usb_cdc_reset_buffers() {
void usb_cdc_reset_buffers(void) {
usbd_cdc_itf_t *cdc = usb_vcp_get(0);

cdc->tx_buf_ptr_in = 0;
Expand Down
1 change: 1 addition & 0 deletions ports/stm32/usbd_cdc_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ typedef struct _usbd_cdc_itf_t {
volatile uint8_t dbg_mode_enabled;
volatile uint32_t dbg_last_packet;
volatile uint32_t dbg_xfer_length;
uint8_t dbg_xfer_buffer[CDC_DATA_MAX_PACKET_SIZE];
} usbd_cdc_itf_t;

// This is implemented in usb.c
Expand Down

0 comments on commit f9d41b1

Please sign in to comment.