mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Merge pull request #2272 from openmv/tinyusb_debug
misc: Tinyusb debug updates.
This commit is contained in:
commit
9a67079fd6
@ -39,14 +39,24 @@ static volatile bool tinyusb_debug_mode = false;
|
|||||||
ringbuf_t debug_ringbuf = { debug_ringbuf_array, sizeof(debug_ringbuf_array) };
|
ringbuf_t debug_ringbuf = { debug_ringbuf_array, sizeof(debug_ringbuf_array) };
|
||||||
|
|
||||||
uint32_t usb_cdc_buf_len() {
|
uint32_t usb_cdc_buf_len() {
|
||||||
return ringbuf_avail((ringbuf_t *) &debug_ringbuf);
|
return ringbuf_avail(&debug_ringbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t usb_cdc_get_buf(uint8_t *buf, uint32_t len) {
|
uint32_t usb_cdc_get_buf(uint8_t *buf, uint32_t len) {
|
||||||
for (int i = 0; i < len; i++) {
|
// Read all of the request bytes.
|
||||||
buf[i] = ringbuf_get((ringbuf_t *) &debug_ringbuf);
|
if (ringbuf_get_bytes(&debug_ringbuf, buf, len) == 0) {
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
return len;
|
// Try to read as much data as possible.
|
||||||
|
uint32_t bytes = 0;
|
||||||
|
for (; bytes < len; bytes++) {
|
||||||
|
int c = ringbuf_get(&debug_ringbuf);
|
||||||
|
if (c == -1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buf[bytes] = c;
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const *coding) {
|
void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const *coding) {
|
||||||
@ -70,24 +80,44 @@ bool tinyusb_debug_enabled(void) {
|
|||||||
return tinyusb_debug_mode;
|
return tinyusb_debug_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern void __real_mp_usbd_task(void);
|
||||||
|
void __wrap_mp_usbd_task(void) {
|
||||||
|
if (!tinyusb_debug_enabled()) {
|
||||||
|
__real_mp_usbd_task();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extern void __real_tud_cdc_rx_cb(uint8_t itf);
|
extern void __real_tud_cdc_rx_cb(uint8_t itf);
|
||||||
void __wrap_tud_cdc_rx_cb(uint8_t itf) {
|
void __wrap_tud_cdc_rx_cb(uint8_t itf) {
|
||||||
if (tinyusb_debug_enabled()) {
|
if (!tinyusb_debug_enabled()) {
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
__real_tud_cdc_rx_cb(itf);
|
__real_tud_cdc_rx_cb(itf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern uintptr_t __real_mp_hal_stdio_poll(uintptr_t poll_flags);
|
||||||
|
uintptr_t __wrap_mp_hal_stdio_poll(uintptr_t poll_flags) {
|
||||||
|
if (!tinyusb_debug_enabled()) {
|
||||||
|
return __real_mp_hal_stdio_poll(poll_flags);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
extern mp_uint_t __real_mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
|
extern mp_uint_t __real_mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
|
||||||
mp_uint_t __wrap_mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
|
mp_uint_t __wrap_mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
|
||||||
if (tinyusb_debug_enabled()) {
|
if (tinyusb_debug_enabled()) {
|
||||||
if (tud_cdc_connected()) {
|
if (tud_cdc_connected()) {
|
||||||
|
NVIC_DisableIRQ(PendSV_IRQn);
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
NVIC_DisableIRQ(PendSV_IRQn);
|
// The ring buffer overflows occasionally, espcially when using a slow poll
|
||||||
ringbuf_put((ringbuf_t *) &debug_ringbuf, str[i]);
|
// rate and fast print rate. When this happens, reset the buffer and start
|
||||||
NVIC_EnableIRQ(PendSV_IRQn);
|
// over, if this string fits entirely in the buffer. This helps the ring buffer
|
||||||
|
// self-recover from broken strings.
|
||||||
|
if (ringbuf_put(&debug_ringbuf, str[i]) == -1 && len <= debug_ringbuf.size) {
|
||||||
|
debug_ringbuf.iget = 0;
|
||||||
|
debug_ringbuf.iput = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
NVIC_EnableIRQ(PendSV_IRQn);
|
||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -48,7 +48,9 @@ LDFLAGS = -mthumb \
|
|||||||
-mabi=aapcs-linux \
|
-mabi=aapcs-linux \
|
||||||
-Wl,--print-memory-usage \
|
-Wl,--print-memory-usage \
|
||||||
-Wl,--gc-sections \
|
-Wl,--gc-sections \
|
||||||
|
-Wl,--wrap=mp_usbd_task \
|
||||||
-Wl,--wrap=tud_cdc_rx_cb \
|
-Wl,--wrap=tud_cdc_rx_cb \
|
||||||
|
-Wl,--wrap=mp_hal_stdio_poll \
|
||||||
-Wl,--wrap=mp_hal_stdout_tx_strn \
|
-Wl,--wrap=mp_hal_stdout_tx_strn \
|
||||||
-Wl,-T$(BUILD)/$(LDSCRIPT).lds \
|
-Wl,-T$(BUILD)/$(LDSCRIPT).lds \
|
||||||
-Wl,-Map=$(BUILD)/$(FIRMWARE).map
|
-Wl,-Map=$(BUILD)/$(FIRMWARE).map
|
||||||
|
|||||||
@ -63,9 +63,21 @@ OMV_CFLAGS += -I$(TOP_DIR)/$(LIBPDM_DIR)/
|
|||||||
CFLAGS += $(HAL_CFLAGS) $(MPY_CFLAGS) $(OMV_CFLAGS)
|
CFLAGS += $(HAL_CFLAGS) $(MPY_CFLAGS) $(OMV_CFLAGS)
|
||||||
|
|
||||||
# Linker Flags
|
# Linker Flags
|
||||||
LDFLAGS = -mcpu=$(CPU) -mabi=aapcs-linux -mthumb -mfpu=$(FPU) -mfloat-abi=hard\
|
LDFLAGS = -mcpu=$(CPU) \
|
||||||
-nostdlib -Wl,--gc-sections -Wl,-T$(BUILD)/$(LDSCRIPT).lds \
|
-mabi=aapcs-linux \
|
||||||
-Wl,--wrap=tud_cdc_rx_cb -Wl,--wrap=mp_hal_stdout_tx_strn
|
-mthumb \
|
||||||
|
-mfpu=$(FPU) \
|
||||||
|
-mfloat-abi=hard \
|
||||||
|
-nostdlib \
|
||||||
|
-Wl,--gc-sections \
|
||||||
|
-Wl,--print-memory-usage \
|
||||||
|
-Wl,--wrap=mp_usbd_task \
|
||||||
|
-Wl,--wrap=tud_cdc_rx_cb \
|
||||||
|
-Wl,--wrap=mp_hal_stdio_poll \
|
||||||
|
-Wl,--wrap=mp_hal_stdout_tx_strn \
|
||||||
|
-Wl,--no-warn-rwx-segment \
|
||||||
|
-Wl,-Map=$(BUILD)/$(FIRMWARE).map \
|
||||||
|
-Wl,-T$(BUILD)/$(LDSCRIPT).lds
|
||||||
|
|
||||||
#------------- Firmware Objects ----------------#
|
#------------- Firmware Objects ----------------#
|
||||||
FIRM_OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/CommonTables/*.o)
|
FIRM_OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/CommonTables/*.o)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user