From d34a2eae55a581a13e1e99d64542396f5b1f09c5 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sat, 3 Aug 2024 10:41:17 +0300 Subject: [PATCH] ports/wifidbg: Update WiFi debug code. Note this feature will be replaced soon. --- src/omv/ports/stm32/wifidbg.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/omv/ports/stm32/wifidbg.c b/src/omv/ports/stm32/wifidbg.c index 87d06a6de..4c51a3a9b 100644 --- a/src/omv/ports/stm32/wifidbg.c +++ b/src/omv/ports/stm32/wifidbg.c @@ -56,6 +56,7 @@ typedef struct wifidbg { uint8_t ipaddr[WINC_IPV4_ADDR_LEN]; char bcast_packet[WIFIDBG_BCAST_STRING_SIZE]; winc_socket_buf_t sockbuf; + uint8_t *buf; } wifidbg_t; static wifidbg_t wifidbg; @@ -81,6 +82,16 @@ int wifidbg_broadcast(wifidbg_t *wifidbg) { return 0; } +static uint32_t dbg_write(const void *buf, uint32_t len) { + memcpy(wifidbg.buf, buf, len); + return len; +} + +static uint32_t dbg_read(void *buf, uint32_t len) { + memcpy(buf, wifidbg.buf, len); + return len; +} + void wifidbg_pendsv_callback(void) { int ret = 0; uint32_t request = 0; @@ -150,24 +161,25 @@ void wifidbg_pendsv_callback(void) { request = cmdbuf[1]; uint32_t xfer_length = *((uint32_t *) (cmdbuf + 2)); usbdbg_control(NULL, request, xfer_length); + wifidbg.buf = buf; while (xfer_length) { if (request & 0x80) { // Device-to-host data phase int bytes = WIFIDBG_MIN(xfer_length, WIFIDBG_BUFFER_SIZE); xfer_length -= bytes; - usbdbg_data_in(buf, bytes); - if ((ret = winc_socket_send(wifidbg.client_fd, buf, bytes, 500)) < 0) { + usbdbg_data_in(bytes, dbg_write); + if ((ret = winc_socket_send(wifidbg.client_fd, wifidbg.buf, bytes, 500)) < 0) { goto exit_dispatch_error; } } else { // Host-to-device data phase int bytes = WIFIDBG_MIN(xfer_length, WIFIDBG_BUFFER_SIZE); - if ((ret = winc_socket_recv(wifidbg.client_fd, buf, bytes, &wifidbg.sockbuf, 500)) < 0) { + if ((ret = winc_socket_recv(wifidbg.client_fd, wifidbg.buf, bytes, &wifidbg.sockbuf, 500)) < 0) { goto exit_dispatch_error; } xfer_length -= ret; - usbdbg_data_out(buf, ret); + usbdbg_data_out(ret, dbg_read); } } @@ -183,6 +195,7 @@ exit_dispatch: } void wifidbg_systick_callback(uint32_t ticks_ms) { + extern int usb_cdc_debug_mode_enabled(); if (usb_cdc_debug_mode_enabled() == false && (ticks_ms - wifidbg.last_dispatch) > WIFIDBG_POLL_INTERVAL_MS) { pendsv_schedule_dispatch(PENDSV_DISPATCH_WINC, wifidbg_pendsv_callback);