Merge pull request #2104 from openmv/tinyusb_debug_fixes

misc: Use LD wrap for redirecting serial data to TinyUSB debug code.
This commit is contained in:
Ibrahim Abdelkader 2024-01-19 20:37:12 +02:00 committed by GitHub
commit c546a8996e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 31 additions and 10 deletions

@ -1 +1 @@
Subproject commit 6e252c7edec9393a7b2f07a35997e19690a5d173 Subproject commit 9fceba6be6add8874fc409c93a23b4653b756205

View File

@ -70,14 +70,28 @@ bool tinyusb_debug_enabled(void) {
return tinyusb_debug_mode; return tinyusb_debug_mode;
} }
void tinyusb_debug_tx_strn(const char *str, mp_uint_t len) { extern void __real_tud_cdc_rx_cb(uint8_t itf);
// TODO can be faster. void __wrap_tud_cdc_rx_cb(uint8_t itf) {
if (tinyusb_debug_enabled() && tud_cdc_connected()) { if (tinyusb_debug_enabled()) {
for (int i = 0; i < len; i++) { return;
NVIC_DisableIRQ(PendSV_IRQn); } else {
ringbuf_put((ringbuf_t *) &debug_ringbuf, str[i]); __real_tud_cdc_rx_cb(itf);
NVIC_EnableIRQ(PendSV_IRQn); }
}
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) {
if (tinyusb_debug_enabled()) {
if (tud_cdc_connected()) {
for (int i = 0; i < len; i++) {
NVIC_DisableIRQ(PendSV_IRQn);
ringbuf_put((ringbuf_t *) &debug_ringbuf, str[i]);
NVIC_EnableIRQ(PendSV_IRQn);
}
} }
return len;
} else {
return __real_mp_hal_stdout_tx_strn(str, len);
} }
} }

View File

@ -90,7 +90,8 @@ endif
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 -nostdlib \ LDFLAGS = -mcpu=$(CPU) -mabi=aapcs-linux -mthumb -mfpu=$(FPU) -mfloat-abi=hard -nostdlib \
-Wl,--print-memory-usage -Wl,--gc-sections -Wl,-T$(BUILD)/$(LDSCRIPT).lds -Wl,--print-memory-usage -Wl,--gc-sections -Wl,-T$(BUILD)/$(LDSCRIPT).lds \
-Wl,--wrap=tud_cdc_rx_cb -Wl,--wrap=mp_hal_stdout_tx_strn
#------------- Libraries ----------------# #------------- Libraries ----------------#
LIBS += $(TOP_DIR)/$(TENSORFLOW_DIR)/$(CPU)/libtf*.a LIBS += $(TOP_DIR)/$(TENSORFLOW_DIR)/$(CPU)/libtf*.a

View File

@ -64,7 +64,8 @@ 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) -mabi=aapcs-linux -mthumb -mfpu=$(FPU) -mfloat-abi=hard\
-nostdlib -Wl,--gc-sections -Wl,-T$(BUILD)/$(LDSCRIPT).lds -nostdlib -Wl,--gc-sections -Wl,-T$(BUILD)/$(LDSCRIPT).lds \
-Wl,--wrap=tud_cdc_rx_cb -Wl,--wrap=mp_hal_stdout_tx_strn
#------------- Libraries ----------------# #------------- Libraries ----------------#
LIBS += $(TOP_DIR)/$(TENSORFLOW_DIR)/$(CPU)/libtf*.a LIBS += $(TOP_DIR)/$(TENSORFLOW_DIR)/$(CPU)/libtf*.a

View File

@ -25,6 +25,11 @@ set(MICROPY_MANIFEST_OMV_LIB_DIR ${TOP_DIR}/../scripts/libraries)
# Include board cmake fragment # Include board cmake fragment
include(${OMV_BOARD_CONFIG_DIR}/omv_boardconfig.cmake) include(${OMV_BOARD_CONFIG_DIR}/omv_boardconfig.cmake)
target_link_options(${MICROPY_TARGET} PRIVATE
-Wl,--wrap=tud_cdc_rx_cb
-Wl,--wrap=mp_hal_stdout_tx_strn
)
target_compile_definitions(${MICROPY_TARGET} PRIVATE target_compile_definitions(${MICROPY_TARGET} PRIVATE
ARM_MATH_CM0PLUS ARM_MATH_CM0PLUS
${OMV_BOARD_MODULES_DEFINITIONS} ${OMV_BOARD_MODULES_DEFINITIONS}