From eeb076454b8e9b91654f0de3ce565e4f1c1967af Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 8 May 2020 12:56:32 +0700 Subject: add CFG_TUSB_DEBUG_PRINTF() for log retargeting --- src/common/tusb_common.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/common') diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index 052caef21..2389bfcd4 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -215,8 +215,11 @@ static inline bool tu_bit_test (uint32_t value, uint8_t pos) { return (value void tu_print_mem(void const *buf, uint16_t count, uint8_t indent); -#ifndef tu_printf - #define tu_printf printf +#ifdef CFG_TUSB_DEBUG_PRINTF + extern int CFG_TUSB_DEBUG_PRINTF(const char *format, ...); + #define tu_printf CFG_TUSB_DEBUG_PRINTF +#else + #define tu_printf printf #endif static inline -- cgit v1.3.1 From f02ad1d0dcbbad57ccb8308d09843b8f688bcceb Mon Sep 17 00:00:00 2001 From: Mengsk Date: Fri, 8 May 2020 13:29:33 +0200 Subject: Add IAR compiler attribute and endian support. --- src/common/tusb_compiler.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/common') diff --git a/src/common/tusb_compiler.h b/src/common/tusb_compiler.h index e403c749b..6f6aa3c39 100644 --- a/src/common/tusb_compiler.h +++ b/src/common/tusb_compiler.h @@ -99,7 +99,26 @@ #define TU_BSWAP16(u16) (__builtin_bswap16(u16)) #define TU_BSWAP32(u32) (__builtin_bswap32(u32)) -#else +#elif defined(__ICCARM__) + #define TU_ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes))) + #define TU_ATTR_SECTION(sec_name) __attribute__ ((section(#sec_name))) + #define TU_ATTR_PACKED __attribute__ ((packed)) + #define TU_ATTR_PREPACKED + #define TU_ATTR_WEAK __attribute__ ((weak)) + #define TU_ATTR_DEPRECATED(mess) __attribute__ ((deprecated(mess))) // warn if function with this attribute is used + #define TU_ATTR_UNUSED __attribute__ ((unused)) // Function/Variable is meant to be possibly unused + #define TU_ATTR_USED __attribute__ ((used)) // Function/Variable is meant to be used + + // Endian conversion use well-known host to network (big endian) naming + #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + #define TU_BYTE_ORDER TU_LITTLE_ENDIAN + #else + #define TU_BYTE_ORDER TU_BIG_ENDIAN + #endif + + #define TU_BSWAP16(u16) (__iar_builtin_REV16(u16)) + #define TU_BSWAP32(u32) (__iar_builtin_REV(u32)) +#else #error "Compiler attribute porting is required" #endif -- cgit v1.3.1 From 46875a3912cd1fddeef7e6c67744d5bf7cce2155 Mon Sep 17 00:00:00 2001 From: Mengsk Date: Tue, 12 May 2020 18:50:26 +0200 Subject: Optimize FIFO for byte transfer. Signed-off-by: Mengsk --- src/common/tusb_fifo.c | 80 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 27 deletions(-) (limited to 'src/common') diff --git a/src/common/tusb_fifo.c b/src/common/tusb_fifo.c index 01e990311..3ed610021 100644 --- a/src/common/tusb_fifo.c +++ b/src/common/tusb_fifo.c @@ -103,9 +103,9 @@ static void _tu_ff_push(tu_fifo_t* f, void const * data) /******************************************************************************/ /*! - @brief Read one byte out of the RX buffer. + @brief Read one element out of the RX buffer. - This function will return the byte located at the array index of the + This function will return the element located at the array index of the read pointer, and then increment the read pointer index. If the read pointer exceeds the maximum buffer size, it will roll over to zero. @@ -132,8 +132,8 @@ bool tu_fifo_read(tu_fifo_t* f, void * buffer) /******************************************************************************/ /*! - @brief This function will read n elements into the array index specified by - the write pointer and increment the write index. If the write index + @brief This function will read n elements from the array index specified by + the read pointer and increment the read index. If the read index exceeds the max buffer size, then it will roll over to zero. @param[in] f @@ -148,32 +148,39 @@ bool tu_fifo_read(tu_fifo_t* f, void * buffer) /******************************************************************************/ uint16_t tu_fifo_read_n (tu_fifo_t* f, void * buffer, uint16_t count) { - if( tu_fifo_empty(f) ) return 0; + if(tu_fifo_empty(f)) return 0; tu_fifo_lock(f); /* Limit up to fifo's count */ - if ( count > f->count ) count = f->count; - - uint8_t* buf8 = (uint8_t*) buffer; - uint16_t len = 0; + if(count > f->count) + count = f->count; - while (len < count) + if(count + f->rd_idx <= f->depth) { - _tu_ff_pull(f, buf8); - - len++; - buf8 += f->item_size; + memcpy(buffer, f->buffer + f->rd_idx * f->item_size, count * f->item_size); } + else + { + uint16_t part1 = (f->depth - f->rd_idx) * f->item_size; + memcpy(buffer, f->buffer + f->rd_idx * f->item_size, part1); + memcpy((uint8_t*)buffer + part1, f->buffer, count * f->item_size - part1); + } + + f->rd_idx += count; + if (f->rd_idx >= f->depth) + f->rd_idx -= f->depth; + + f->count -= count; tu_fifo_unlock(f); - return len; + return count; } /******************************************************************************/ /*! - @brief Reads one item without removing it from the FIFO + @brief Read one item without removing it from the FIFO @param[in] f Pointer to the FIFO buffer to manipulate @@ -249,23 +256,42 @@ uint16_t tu_fifo_write_n (tu_fifo_t* f, const void * data, uint16_t count) tu_fifo_lock(f); - // Not overwritable limit up to full - if (!f->overwritable) count = tu_min16(count, tu_fifo_remaining(f)); - uint8_t const* buf8 = (uint8_t const*) data; - uint16_t len = 0; - - while (len < count) + // Not overwritable limit up to full + if (!f->overwritable) { - _tu_ff_push(f, buf8); - - len++; - buf8 += f->item_size; + count = tu_min16(count, tu_fifo_remaining(f)); + } + // Only copy last part + else if (count > f->depth) + { + buf8 = buf8 + (count - f->depth) * f->item_size; + count = f->depth; + f->wr_idx = 0; + f->rd_idx = 0; + f->count = 0; } + if (count + f->wr_idx <= f->depth ) + { + memcpy(f->buffer + f->wr_idx * f->item_size, buf8, count * f->item_size); + } + else + { + uint16_t part1 = (f->depth - f->wr_idx) * f->item_size; + memcpy(f->buffer + f->wr_idx * f->item_size, buf8, part1); + memcpy(f->buffer, buf8 + part1, count * f->item_size - part1); + } + + f->wr_idx += count; + if (f->wr_idx >= f->depth) + f->wr_idx -= f->depth; + + f->count += count; + tu_fifo_unlock(f); - return len; + return count; } /******************************************************************************/ -- cgit v1.3.1 From b0d49e55de8a9359f76750b6f8cc6517d10a913e Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 14 May 2020 14:24:55 +0700 Subject: refactor copy to and from fifo --- src/common/tusb_fifo.c | 85 +++++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 39 deletions(-) (limited to 'src/common') diff --git a/src/common/tusb_fifo.c b/src/common/tusb_fifo.c index 3ed610021..6ab158cca 100644 --- a/src/common/tusb_fifo.c +++ b/src/common/tusb_fifo.c @@ -71,33 +71,38 @@ bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_si return true; } +static inline uint16_t _ff_mod(uint16_t idx, uint16_t depth) +{ + return (idx < depth) ? idx : (idx-depth); +} + // retrieve data from fifo -static void _tu_ff_pull(tu_fifo_t* f, void * buffer) +static inline void _ff_pull(tu_fifo_t* f, void * buffer, uint16_t n) { memcpy(buffer, f->buffer + (f->rd_idx * f->item_size), - f->item_size); + f->item_size*n); - f->rd_idx = (f->rd_idx + 1) % f->depth; - f->count--; + f->rd_idx = _ff_mod(f->rd_idx + n, f->depth); + f->count -= n; } // send data to fifo -static void _tu_ff_push(tu_fifo_t* f, void const * data) +static inline void _ff_push(tu_fifo_t* f, void const * data, uint16_t n) { - memcpy( f->buffer + (f->wr_idx * f->item_size), - data, - f->item_size); + memcpy(f->buffer + (f->wr_idx * f->item_size), + data, + f->item_size*n); - f->wr_idx = (f->wr_idx + 1) % f->depth; + f->wr_idx = _ff_mod(f->wr_idx + n, f->depth); if (tu_fifo_full(f)) { - f->rd_idx = f->wr_idx; // keep the full state (rd == wr && len = size) + f->rd_idx = f->wr_idx; // keep the full state (rd == wr && count = depth) } else { - f->count++; + f->count += n; } } @@ -123,7 +128,7 @@ bool tu_fifo_read(tu_fifo_t* f, void * buffer) tu_fifo_lock(f); - _tu_ff_pull(f, buffer); + _ff_pull(f, buffer, 1); tu_fifo_unlock(f); @@ -152,26 +157,24 @@ uint16_t tu_fifo_read_n (tu_fifo_t* f, void * buffer, uint16_t count) tu_fifo_lock(f); - /* Limit up to fifo's count */ - if(count > f->count) - count = f->count; + // Limit up to fifo's count + if(count > f->count) count = f->count; if(count + f->rd_idx <= f->depth) { - memcpy(buffer, f->buffer + f->rd_idx * f->item_size, count * f->item_size); + _ff_pull(f, buffer, count); } else { - uint16_t part1 = (f->depth - f->rd_idx) * f->item_size; - memcpy(buffer, f->buffer + f->rd_idx * f->item_size, part1); - memcpy((uint8_t*)buffer + part1, f->buffer, count * f->item_size - part1); + uint16_t const part1 = f->depth - f->rd_idx; + + // Part 1: from rd_idx to end + _ff_pull(f, buffer, part1); + buffer = ((uint8_t*) buffer) + part1*f->item_size; + + // Part 2: start to remaining + _ff_pull(f, buffer, count-part1); } - - f->rd_idx += count; - if (f->rd_idx >= f->depth) - f->rd_idx -= f->depth; - - f->count -= count; tu_fifo_unlock(f); @@ -196,12 +199,16 @@ bool tu_fifo_peek_at(tu_fifo_t* f, uint16_t pos, void * p_buffer) { if ( pos >= f->count ) return false; + tu_fifo_lock(f); + // rd_idx is pos=0 - uint16_t index = (f->rd_idx + pos) % f->depth; + uint16_t index = _ff_mod(f->rd_idx + pos, f->depth); memcpy(p_buffer, f->buffer + (index * f->item_size), f->item_size); + tu_fifo_unlock(f); + return true; } @@ -228,7 +235,7 @@ bool tu_fifo_write (tu_fifo_t* f, const void * data) tu_fifo_lock(f); - _tu_ff_push(f, data); + _ff_push(f, data, 1); tu_fifo_unlock(f); @@ -257,14 +264,15 @@ uint16_t tu_fifo_write_n (tu_fifo_t* f, const void * data, uint16_t count) tu_fifo_lock(f); uint8_t const* buf8 = (uint8_t const*) data; - // Not overwritable limit up to full + if (!f->overwritable) { + // Not overwritable limit up to full count = tu_min16(count, tu_fifo_remaining(f)); } - // Only copy last part else if (count > f->depth) { + // Only copy last part buf8 = buf8 + (count - f->depth) * f->item_size; count = f->depth; f->wr_idx = 0; @@ -274,21 +282,20 @@ uint16_t tu_fifo_write_n (tu_fifo_t* f, const void * data, uint16_t count) if (count + f->wr_idx <= f->depth ) { - memcpy(f->buffer + f->wr_idx * f->item_size, buf8, count * f->item_size); + _ff_push(f, buf8, count); } else { - uint16_t part1 = (f->depth - f->wr_idx) * f->item_size; - memcpy(f->buffer + f->wr_idx * f->item_size, buf8, part1); - memcpy(f->buffer, buf8 + part1, count * f->item_size - part1); + uint16_t const part1 = f->depth - f->wr_idx; + + // Part 1: from wr_idx to end + _ff_push(f, buf8, part1); + buf8 += part1*f->item_size; + + // Part 2: start to remaining + _ff_push(f, buf8, count-part1); } - f->wr_idx += count; - if (f->wr_idx >= f->depth) - f->wr_idx -= f->depth; - - f->count += count; - tu_fifo_unlock(f); return count; -- cgit v1.3.1 From 1a8ce043ed937012454e5b79396455f9c5568a68 Mon Sep 17 00:00:00 2001 From: hathach Date: Sun, 17 May 2020 14:24:15 +0700 Subject: enable -Wcast-align suppress vendor sdk driver at board.mk --- examples/make.mk | 8 +++----- hw/bsp/adafruit_clue/board.mk | 4 ++-- hw/bsp/arduino_nano33_ble/board.mk | 4 ++-- hw/bsp/circuitplayground_bluefruit/board.mk | 4 ++-- hw/bsp/feather_nrf52840_express/board.mk | 4 ++-- hw/bsp/feather_nrf52840_sense/board.mk | 4 ++-- hw/bsp/feather_stm32f405/board.mk | 3 +++ hw/bsp/nrf52840_mdk_dongle/board.mk | 4 ++-- hw/bsp/nutiny_sdk_nuc505/board.mk | 5 +++-- hw/bsp/pca10056/board.mk | 4 ++-- hw/bsp/pca10059/board.mk | 4 ++-- hw/bsp/pca10100/board.mk | 4 ++-- hw/bsp/raytac_mdbt50q_rx/board.mk | 4 ++-- hw/bsp/stm32f070rbnucleo/board.mk | 4 ++-- hw/bsp/stm32f072disco/board.mk | 4 ++-- hw/bsp/stm32f407disco/board.mk | 3 +++ hw/bsp/stm32f411disco/board.mk | 3 +++ hw/bsp/stm32f412disco/board.mk | 4 ++-- hw/bsp/stm32f746nucleo/board.mk | 4 ++-- hw/bsp/stm32f767nucleo/board.mk | 4 ++-- hw/bsp/stm32h743nucleo/board.mk | 1 - src/common/tusb_common.h | 2 +- src/portable/nxp/transdimension/dcd_transdimension.c | 6 ++++-- 23 files changed, 50 insertions(+), 41 deletions(-) (limited to 'src/common') diff --git a/examples/make.mk b/examples/make.mk index 449dc899d..2ea50753b 100644 --- a/examples/make.mk +++ b/examples/make.mk @@ -63,11 +63,9 @@ CFLAGS += \ -Wwrite-strings \ -Wsign-compare \ -Wmissing-format-attribute \ - -Wunreachable-code - -# This causes lots of warning with nrf5x build due to nrfx code -# CFLAGS += -Wcast-align - + -Wunreachable-code \ + -Wcast-align + # Debugging/Optimization ifeq ($(DEBUG), 1) CFLAGS += -Og -ggdb diff --git a/hw/bsp/adafruit_clue/board.mk b/hw/bsp/adafruit_clue/board.mk index be8c5bf56..5290455cc 100644 --- a/hw/bsp/adafruit_clue/board.mk +++ b/hw/bsp/adafruit_clue/board.mk @@ -9,8 +9,8 @@ CFLAGS += \ -DNRF52840_XXAA \ -DCONFIG_GPIO_AS_PINRESET -# nrfx issue undef _ARMCC_VERSION usage https://github.com/NordicSemiconductor/nrfx/issues/49 -CFLAGS += -Wno-error=undef -Wno-error=unused-parameter +# suppress warning caused by vendor mcu driver +CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) diff --git a/hw/bsp/arduino_nano33_ble/board.mk b/hw/bsp/arduino_nano33_ble/board.mk index d217d37c0..0a25d0b19 100644 --- a/hw/bsp/arduino_nano33_ble/board.mk +++ b/hw/bsp/arduino_nano33_ble/board.mk @@ -9,8 +9,8 @@ CFLAGS += \ -DNRF52840_XXAA \ -DCONFIG_GPIO_AS_PINRESET -# nrfx issue undef _ARMCC_VERSION usage https://github.com/NordicSemiconductor/nrfx/issues/49 -CFLAGS += -Wno-error=undef -Wno-error=unused-parameter +# suppress warning caused by vendor mcu driver +CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) diff --git a/hw/bsp/circuitplayground_bluefruit/board.mk b/hw/bsp/circuitplayground_bluefruit/board.mk index be8c5bf56..5290455cc 100644 --- a/hw/bsp/circuitplayground_bluefruit/board.mk +++ b/hw/bsp/circuitplayground_bluefruit/board.mk @@ -9,8 +9,8 @@ CFLAGS += \ -DNRF52840_XXAA \ -DCONFIG_GPIO_AS_PINRESET -# nrfx issue undef _ARMCC_VERSION usage https://github.com/NordicSemiconductor/nrfx/issues/49 -CFLAGS += -Wno-error=undef -Wno-error=unused-parameter +# suppress warning caused by vendor mcu driver +CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) diff --git a/hw/bsp/feather_nrf52840_express/board.mk b/hw/bsp/feather_nrf52840_express/board.mk index 9f38d6796..7b2625cd4 100644 --- a/hw/bsp/feather_nrf52840_express/board.mk +++ b/hw/bsp/feather_nrf52840_express/board.mk @@ -9,8 +9,8 @@ CFLAGS += \ -DNRF52840_XXAA \ -DCONFIG_GPIO_AS_PINRESET -# nrfx issue undef _ARMCC_VERSION usage https://github.com/NordicSemiconductor/nrfx/issues/49 -CFLAGS += -Wno-error=undef -Wno-error=unused-parameter +# suppress warning caused by vendor mcu driver +CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) diff --git a/hw/bsp/feather_nrf52840_sense/board.mk b/hw/bsp/feather_nrf52840_sense/board.mk index be8c5bf56..5290455cc 100644 --- a/hw/bsp/feather_nrf52840_sense/board.mk +++ b/hw/bsp/feather_nrf52840_sense/board.mk @@ -9,8 +9,8 @@ CFLAGS += \ -DNRF52840_XXAA \ -DCONFIG_GPIO_AS_PINRESET -# nrfx issue undef _ARMCC_VERSION usage https://github.com/NordicSemiconductor/nrfx/issues/49 -CFLAGS += -Wno-error=undef -Wno-error=unused-parameter +# suppress warning caused by vendor mcu driver +CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) diff --git a/hw/bsp/feather_stm32f405/board.mk b/hw/bsp/feather_stm32f405/board.mk index 2d1f8bb8d..8233c6608 100644 --- a/hw/bsp/feather_stm32f405/board.mk +++ b/hw/bsp/feather_stm32f405/board.mk @@ -9,6 +9,9 @@ CFLAGS += \ -DSTM32F405xx \ -DCFG_TUSB_MCU=OPT_MCU_STM32F4 +# suppress warning caused by vendor mcu driver +CFLAGS += -Wno-error=cast-align + ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F4xx_HAL_Driver ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32F4xx diff --git a/hw/bsp/nrf52840_mdk_dongle/board.mk b/hw/bsp/nrf52840_mdk_dongle/board.mk index 0ab5ff2e1..9ba04ba1f 100644 --- a/hw/bsp/nrf52840_mdk_dongle/board.mk +++ b/hw/bsp/nrf52840_mdk_dongle/board.mk @@ -8,8 +8,8 @@ CFLAGS += \ -DNRF52840_XXAA \ -DCFG_TUSB_MCU=OPT_MCU_NRF5X -# nrfx issue undef _ARMCC_VERSION usage https://github.com/NordicSemiconductor/nrfx/issues/49 -CFLAGS += -Wno-error=undef -Wno-error=unused-parameter +# suppress warning caused by vendor mcu driver +CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) diff --git a/hw/bsp/nutiny_sdk_nuc505/board.mk b/hw/bsp/nutiny_sdk_nuc505/board.mk index 39df77d2c..874d4ae42 100644 --- a/hw/bsp/nutiny_sdk_nuc505/board.mk +++ b/hw/bsp/nutiny_sdk_nuc505/board.mk @@ -7,6 +7,9 @@ CFLAGS += \ -mfpu=fpv4-sp-d16 \ -DCFG_TUSB_MCU=OPT_MCU_NUC505 +# TODO this cast-align is caused by dcd_nuc505 should be fixed +CFLAGS += -Wno-error=cast-align + # All source paths should be relative to the top level. LD_FILE = hw/bsp/$(BOARD)/nuc505_flashtoram.ld @@ -19,13 +22,11 @@ SRC_C += \ hw/mcu/nuvoton/nuc505/StdDriver/src/i2s.c \ hw/mcu/nuvoton/nuc505/StdDriver/src/pwm.c \ hw/mcu/nuvoton/nuc505/StdDriver/src/rtc.c \ - hw/mcu/nuvoton/nuc505/StdDriver/src/sd.c \ hw/mcu/nuvoton/nuc505/StdDriver/src/spi.c \ hw/mcu/nuvoton/nuc505/StdDriver/src/spim.c \ hw/mcu/nuvoton/nuc505/StdDriver/src/sys.c \ hw/mcu/nuvoton/nuc505/StdDriver/src/timer.c \ hw/mcu/nuvoton/nuc505/StdDriver/src/uart.c \ - hw/mcu/nuvoton/nuc505/StdDriver/src/usbd.c \ hw/mcu/nuvoton/nuc505/StdDriver/src/wdt.c \ hw/mcu/nuvoton/nuc505/StdDriver/src/wwdt.c diff --git a/hw/bsp/pca10056/board.mk b/hw/bsp/pca10056/board.mk index b2f119626..0971e64c8 100644 --- a/hw/bsp/pca10056/board.mk +++ b/hw/bsp/pca10056/board.mk @@ -9,8 +9,8 @@ CFLAGS += \ -DCONFIG_GPIO_AS_PINRESET \ -DCFG_TUSB_MCU=OPT_MCU_NRF5X -# nrfx issue undef _ARMCC_VERSION usage https://github.com/NordicSemiconductor/nrfx/issues/49 -CFLAGS += -Wno-error=undef -Wno-error=unused-parameter +# suppress warning caused by vendor mcu driver +CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) diff --git a/hw/bsp/pca10059/board.mk b/hw/bsp/pca10059/board.mk index 8cce65eb9..72dfefdcb 100644 --- a/hw/bsp/pca10059/board.mk +++ b/hw/bsp/pca10059/board.mk @@ -9,8 +9,8 @@ CFLAGS += \ -DCONFIG_GPIO_AS_PINRESET \ -DCFG_TUSB_MCU=OPT_MCU_NRF5X -# nrfx issue undef _ARMCC_VERSION usage https://github.com/NordicSemiconductor/nrfx/issues/49 -CFLAGS += -Wno-error=undef -Wno-error=unused-parameter +# suppress warning caused by vendor mcu driver +CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) diff --git a/hw/bsp/pca10100/board.mk b/hw/bsp/pca10100/board.mk index 0ec8f0f69..5231aaf63 100644 --- a/hw/bsp/pca10100/board.mk +++ b/hw/bsp/pca10100/board.mk @@ -9,8 +9,8 @@ CFLAGS += \ -DCONFIG_GPIO_AS_PINRESET \ -DCFG_TUSB_MCU=OPT_MCU_NRF5X -# nrfx issue undef _ARMCC_VERSION usage https://github.com/NordicSemiconductor/nrfx/issues/49 -CFLAGS += -Wno-error=undef -Wno-error=unused-parameter +# suppress warning caused by vendor mcu driver +CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) diff --git a/hw/bsp/raytac_mdbt50q_rx/board.mk b/hw/bsp/raytac_mdbt50q_rx/board.mk index 0960ffe55..47bb430fc 100644 --- a/hw/bsp/raytac_mdbt50q_rx/board.mk +++ b/hw/bsp/raytac_mdbt50q_rx/board.mk @@ -8,8 +8,8 @@ CFLAGS += \ -DNRF52840_XXAA \ -DCFG_TUSB_MCU=OPT_MCU_NRF5X -# nrfx issue undef _ARMCC_VERSION usage https://github.com/NordicSemiconductor/nrfx/issues/49 -CFLAGS += -Wno-error=undef -Wno-error=unused-parameter +# suppress warning caused by vendor mcu driver +CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) diff --git a/hw/bsp/stm32f070rbnucleo/board.mk b/hw/bsp/stm32f070rbnucleo/board.mk index 8a073d524..8ae75dd96 100644 --- a/hw/bsp/stm32f070rbnucleo/board.mk +++ b/hw/bsp/stm32f070rbnucleo/board.mk @@ -9,8 +9,8 @@ CFLAGS += \ -DCFG_EXAMPLE_MSC_READONLY \ -DCFG_TUSB_MCU=OPT_MCU_STM32F0 -# mcu driver cause following warnings -CFLAGS += -Wno-error=unused-parameter +# suppress warning caused by vendor mcu driver +CFLAGS += -Wno-error=unused-parameter -Wno-error=cast-align ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F0xx_HAL_Driver ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32F0xx diff --git a/hw/bsp/stm32f072disco/board.mk b/hw/bsp/stm32f072disco/board.mk index 522459d61..e6787b266 100644 --- a/hw/bsp/stm32f072disco/board.mk +++ b/hw/bsp/stm32f072disco/board.mk @@ -9,8 +9,8 @@ CFLAGS += \ -DCFG_EXAMPLE_MSC_READONLY \ -DCFG_TUSB_MCU=OPT_MCU_STM32F0 -# mcu driver cause following warnings -CFLAGS += -Wno-error=unused-parameter +# suppress warning caused by vendor mcu driver +CFLAGS += -Wno-error=unused-parameter -Wno-error=cast-align ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F0xx_HAL_Driver ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32F0xx diff --git a/hw/bsp/stm32f407disco/board.mk b/hw/bsp/stm32f407disco/board.mk index 92e021538..df2ee4ba5 100644 --- a/hw/bsp/stm32f407disco/board.mk +++ b/hw/bsp/stm32f407disco/board.mk @@ -9,6 +9,9 @@ CFLAGS += \ -DSTM32F407xx \ -DCFG_TUSB_MCU=OPT_MCU_STM32F4 +# suppress warning caused by vendor mcu driver +CFLAGS += -Wno-error=cast-align + ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F4xx_HAL_Driver ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32F4xx diff --git a/hw/bsp/stm32f411disco/board.mk b/hw/bsp/stm32f411disco/board.mk index a5ea8cab2..5e0d6c3a0 100644 --- a/hw/bsp/stm32f411disco/board.mk +++ b/hw/bsp/stm32f411disco/board.mk @@ -9,6 +9,9 @@ CFLAGS += \ -DSTM32F411xE \ -DCFG_TUSB_MCU=OPT_MCU_STM32F4 +# suppress warning caused by vendor mcu driver +CFLAGS += -Wno-error=cast-align + ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F4xx_HAL_Driver ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32F4xx diff --git a/hw/bsp/stm32f412disco/board.mk b/hw/bsp/stm32f412disco/board.mk index 2a3ecbddd..5cf5e9b7a 100644 --- a/hw/bsp/stm32f412disco/board.mk +++ b/hw/bsp/stm32f412disco/board.mk @@ -9,8 +9,8 @@ CFLAGS += \ -DSTM32F412Zx \ -DCFG_TUSB_MCU=OPT_MCU_STM32F4 -# mcu driver cause following warnings -CFLAGS += -Wno-error=maybe-uninitialized +# suppress warning caused by vendor mcu driver +CFLAGS += -Wno-error=cast-align ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F4xx_HAL_Driver ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32F4xx diff --git a/hw/bsp/stm32f746nucleo/board.mk b/hw/bsp/stm32f746nucleo/board.mk index 7e070c1c5..95445486a 100644 --- a/hw/bsp/stm32f746nucleo/board.mk +++ b/hw/bsp/stm32f746nucleo/board.mk @@ -9,8 +9,8 @@ CFLAGS += \ -DSTM32F746xx \ -DCFG_TUSB_MCU=OPT_MCU_STM32F7 -# mcu driver cause following warnings -CFLAGS += -Wno-error=shadow +# suppress warning caused by vendor mcu driver +CFLAGS += -Wno-error=cast-align -Wno-error=shadow ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F7xx_HAL_Driver ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32F7xx diff --git a/hw/bsp/stm32f767nucleo/board.mk b/hw/bsp/stm32f767nucleo/board.mk index e5f0736df..fc638ddcb 100644 --- a/hw/bsp/stm32f767nucleo/board.mk +++ b/hw/bsp/stm32f767nucleo/board.mk @@ -9,8 +9,8 @@ CFLAGS += \ -DSTM32F767xx \ -DCFG_TUSB_MCU=OPT_MCU_STM32F7 -# mcu driver cause following warnings -CFLAGS += -Wno-error=shadow +# suppress warning caused by vendor mcu driver +CFLAGS += -Wno-error=cast-align -Wno-error=shadow ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F7xx_HAL_Driver ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32F7xx diff --git a/hw/bsp/stm32h743nucleo/board.mk b/hw/bsp/stm32h743nucleo/board.mk index 94cc44b5f..30e52dfcc 100644 --- a/hw/bsp/stm32h743nucleo/board.mk +++ b/hw/bsp/stm32h743nucleo/board.mk @@ -10,7 +10,6 @@ CFLAGS += \ -DCFG_TUSB_MCU=OPT_MCU_STM32H7 # mcu driver cause following warnings -CFLAGS += -Wno-error=maybe-uninitialized ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32H7xx_HAL_Driver ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32H7xx diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index 2389bfcd4..f144cda73 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -106,7 +106,7 @@ static inline uint16_t tu_max16 (uint16_t x, uint16_t y) { return (x > y) ? x : static inline uint32_t tu_max32 (uint32_t x, uint32_t y) { return (x > y) ? x : y; } // Align -static inline uint32_t tu_align_n(uint32_t value, uint32_t alignment) +static inline uint32_t tu_align(uint32_t value, uint32_t alignment) { return value & ((uint32_t) ~(alignment-1)); } diff --git a/src/portable/nxp/transdimension/dcd_transdimension.c b/src/portable/nxp/transdimension/dcd_transdimension.c index fcedc1c0c..7baf43e23 100644 --- a/src/portable/nxp/transdimension/dcd_transdimension.c +++ b/src/portable/nxp/transdimension/dcd_transdimension.c @@ -273,7 +273,8 @@ typedef struct { dcd_qtd_t qtd[QHD_MAX] TU_ATTR_ALIGNED(32); // for portability, TinyUSB only queue 1 TD for each Qhd }dcd_data_t; -static dcd_data_t _dcd_data CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(2048); +CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(2048) +static dcd_data_t _dcd_data; //--------------------------------------------------------------------+ // CONTROLLER API @@ -478,7 +479,8 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t t // Force the CPU to flush the buffer. We increase the size by 32 because the call aligns the // address to 32-byte boundaries. - CleanInvalidateDCache_by_Addr((uint32_t*) buffer, total_bytes + 31); + // void* cast to suppress cast-align warning, buffer must be + CleanInvalidateDCache_by_Addr((uint32_t*) tu_align((uint32_t) buffer, 4), total_bytes + 31); //------------- Prepare qtd -------------// qtd_init(p_qtd, buffer, total_bytes); -- cgit v1.3.1 From 10cd3f24bf0af9b7a1f357505ebbb5ef2132e34b Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 28 May 2020 13:48:02 +0700 Subject: initial transfer failed in open() shouldn't cause the driver open to fail. --- src/class/cdc/cdc_device.c | 11 +++++------ src/class/hid/hid_device.c | 9 ++++++++- src/class/midi/midi_device.c | 6 +++++- src/class/msc/msc_device.c | 6 +++++- src/class/vendor/vendor_device.c | 9 ++++++--- src/common/tusb_common.h | 3 +++ 6 files changed, 32 insertions(+), 12 deletions(-) (limited to 'src/common') diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index a24f348f4..a8a58980a 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -231,8 +231,6 @@ uint16_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint1 // Note: 0xFF can be used with RNDIS TU_VERIFY(tu_within(CDC_COMM_PROTOCOL_NONE, itf_desc->bInterfaceProtocol, CDC_COMM_PROTOCOL_ATCOMMAND_CDMA), 0); - uint16_t len = 0; - // Find available interface cdcd_interface_t * p_cdc = NULL; uint8_t cdc_id; @@ -249,13 +247,13 @@ uint16_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint1 //------------- Control Interface -------------// p_cdc->itf_num = itf_desc->bInterfaceNumber; + uint16_t len = sizeof(tusb_desc_interface_t); uint8_t const * p_desc = tu_desc_next( itf_desc ); - len = sizeof(tusb_desc_interface_t); // Communication Functional Descriptors while ( TUSB_DESC_CS_INTERFACE == tu_desc_type(p_desc) && len <= max_len ) { - len += tu_desc_len(p_desc); + len += tu_desc_len(p_desc); p_desc = tu_desc_next(p_desc); } @@ -266,7 +264,7 @@ uint16_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint1 p_cdc->ep_notif = ((tusb_desc_endpoint_t const *) p_desc)->bEndpointAddress; - len += tu_desc_len(p_desc); + len += tu_desc_len(p_desc); p_desc = tu_desc_next(p_desc); } @@ -275,12 +273,13 @@ uint16_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint1 (TUSB_CLASS_CDC_DATA == ((tusb_desc_interface_t const *) p_desc)->bInterfaceClass) ) { // next to endpoint descriptor + len += tu_desc_len(p_desc); p_desc = tu_desc_next(p_desc); // Open endpoint pair TU_ASSERT( usbd_open_edpt_pair(rhport, p_desc, 2, TUSB_XFER_BULK, &p_cdc->ep_out, &p_cdc->ep_in), 0 ); - len += sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t); + len += 2*sizeof(tusb_desc_endpoint_t); } // Prepare for incoming data diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 51bd153ec..64a57e90e 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -196,7 +196,14 @@ uint16_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint1 memcpy(&p_hid->report_desc_len, &(p_hid->hid_descriptor->wReportLength), 2); // Prepare for output endpoint - if (p_hid->ep_out) TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)), 0); + if (p_hid->ep_out) + { + if ( !usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)) ) + { + TU_LOG1_FAILED(); + TU_BREAKPOINT(); + } + } return sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + desc_itf->bNumEndpoints*sizeof(tusb_desc_endpoint_t); } diff --git a/src/class/midi/midi_device.c b/src/class/midi/midi_device.c index 69dafe0a0..14fb3e50d 100644 --- a/src/class/midi/midi_device.c +++ b/src/class/midi/midi_device.c @@ -359,7 +359,11 @@ uint16_t midid_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint } // Prepare for incoming data - TU_ASSERT( usbd_edpt_xfer(rhport, p_midi->ep_out, p_midi->epout_buf, CFG_TUD_MIDI_EPSIZE), 0 ); + if ( !usbd_edpt_xfer(rhport, p_midi->ep_out, p_midi->epout_buf, CFG_TUD_MIDI_EPSIZE) ) + { + TU_LOG1_FAILED(); + TU_BREAKPOINT(); + } return drv_len; } diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index c3ce495e1..00a5b4525 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -174,7 +174,11 @@ uint16_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint1 TU_ASSERT( usbd_open_edpt_pair(rhport, tu_desc_next(itf_desc), 2, TUSB_XFER_BULK, &p_msc->ep_out, &p_msc->ep_in), 0 ); // Prepare for Command Block Wrapper - TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)), 0 ); + if ( !usbd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) ) + { + TU_LOG1_FAILED(); + TU_BREAKPOINT(); + } return _MSC_DRIVER_LEN; } diff --git a/src/class/vendor/vendor_device.c b/src/class/vendor/vendor_device.c index 98eafe44c..8f2dfef32 100644 --- a/src/class/vendor/vendor_device.c +++ b/src/class/vendor/vendor_device.c @@ -186,12 +186,15 @@ uint16_t vendord_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, ui TU_ASSERT(usbd_open_edpt_pair(rhport, tu_desc_next(itf_desc), 2, TUSB_XFER_BULK, &p_vendor->ep_out, &p_vendor->ep_in), 0); p_vendor->itf_num = itf_desc->bInterfaceNumber; - uint16_t const drv_len = sizeof(tusb_desc_interface_t) + itf_desc->bNumEndpoints*sizeof(tusb_desc_endpoint_t); // Prepare for incoming data - TU_ASSERT(usbd_edpt_xfer(rhport, p_vendor->ep_out, p_vendor->epout_buf, sizeof(p_vendor->epout_buf)), drv_len); + if ( !usbd_edpt_xfer(rhport, p_vendor->ep_out, p_vendor->epout_buf, sizeof(p_vendor->epout_buf)) ) + { + TU_LOG1_FAILED(); + TU_BREAKPOINT(); + } - return drv_len; + return sizeof(tusb_desc_interface_t) + itf_desc->bNumEndpoints*sizeof(tusb_desc_endpoint_t); } bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index f144cda73..4b4183ae6 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -228,6 +228,7 @@ void tu_print_var(uint8_t const* buf, uint32_t bufsize) for(uint32_t i=0; i 1 @@ -277,6 +279,7 @@ static inline char const* lookup_find(lookup_table_t const* p_table, uint32_t ke #define TU_LOG1_VAR(...) #define TU_LOG1_INT(...) #define TU_LOG1_HEX(...) + #define TU_LOG1_FAILED() #endif #ifndef TU_LOG2 -- cgit v1.3.1 From 5ffba8536dfaa4602e3e7f1c94be124bfeb3a5ae Mon Sep 17 00:00:00 2001 From: hathach Date: Sun, 31 May 2020 19:41:22 +0700 Subject: able to detect as hs --- hw/bsp/stm32h743eval/stm32h743eval.c | 13 +++++++++---- src/common/tusb_common.h | 4 +++- src/portable/st/synopsys/dcd_synopsys.c | 10 ++++++---- 3 files changed, 18 insertions(+), 9 deletions(-) (limited to 'src/common') diff --git a/hw/bsp/stm32h743eval/stm32h743eval.c b/hw/bsp/stm32h743eval/stm32h743eval.c index d149c1230..836f1ecab 100644 --- a/hw/bsp/stm32h743eval/stm32h743eval.c +++ b/hw/bsp/stm32h743eval/stm32h743eval.c @@ -265,6 +265,7 @@ void board_init(void) #endif #if BOARD_DEVICE_RHPORT_NUM == 1 + // Despite being call USB2_OTG // OTG_HS is marked as RHPort1 by TinyUSB to be consistent across stm32 port __GPIOA_CLK_ENABLE(); @@ -316,6 +317,8 @@ void board_init(void) GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Alternate = GPIO_AF10_OTG2_HS; HAL_GPIO_Init(GPIOI, &GPIO_InitStruct); + + // Enable ULPI clock __HAL_RCC_USB1_OTG_HS_ULPI_CLK_ENABLE(); /* Enable USB HS Clocks */ @@ -325,12 +328,14 @@ void board_init(void) USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_VBDEN; // Force device mode - // USB_OTG_HS->GUSBCFG &= ~USB_OTG_GUSBCFG_FHMOD; - // USB_OTG_HS->GUSBCFG |= USB_OTG_GUSBCFG_FDMOD; + USB_OTG_HS->GUSBCFG &= ~USB_OTG_GUSBCFG_FHMOD; + USB_OTG_HS->GUSBCFG |= USB_OTG_GUSBCFG_FDMOD; // B-peripheral session valid override enabl -// USB_OTG_HS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN; -// USB_OTG_HS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL; + USB_OTG_HS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN; + USB_OTG_HS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL; + + HAL_PWREx_EnableUSBVoltageDetector(); #endif // rhport = 1 } diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index f144cda73..d77893b6b 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -241,9 +241,9 @@ void tu_print_var(uint8_t const* buf, uint32_t bufsize) #define TU_LOG2 TU_LOG1 #define TU_LOG2_MEM TU_LOG1_MEM #define TU_LOG2_VAR TU_LOG1_VAR - #define TU_LOG2_LOCATION() TU_LOG1_LOCATION() #define TU_LOG2_INT TU_LOG1_INT #define TU_LOG2_HEX TU_LOG1_HEX + #define TU_LOG2_LOCATION() TU_LOG1_LOCATION() #endif @@ -277,6 +277,7 @@ static inline char const* lookup_find(lookup_table_t const* p_table, uint32_t ke #define TU_LOG1_VAR(...) #define TU_LOG1_INT(...) #define TU_LOG1_HEX(...) + #define TU_LOG1_LOCATION() #endif #ifndef TU_LOG2 @@ -285,6 +286,7 @@ static inline char const* lookup_find(lookup_table_t const* p_table, uint32_t ke #define TU_LOG2_VAR(...) #define TU_LOG2_INT(...) #define TU_LOG2_HEX(...) + #define TU_LOG2_LOCATION() #endif #ifdef __cplusplus diff --git a/src/portable/st/synopsys/dcd_synopsys.c b/src/portable/st/synopsys/dcd_synopsys.c index 8ca67dbb4..fe6fe5cea 100644 --- a/src/portable/st/synopsys/dcd_synopsys.c +++ b/src/portable/st/synopsys/dcd_synopsys.c @@ -197,6 +197,8 @@ static void end_of_reset(uint8_t rhport) // However, keep for debugging and in case Low Speed is ever supported. uint32_t enum_spd = (dev->DSTS & USB_OTG_DSTS_ENUMSPD_Msk) >> USB_OTG_DSTS_ENUMSPD_Pos; + // TODO set turnaround in GUSBCFG accordingly to the speed + // Maximum packet size for EP 0 is set for both directions by writing // DIEPCTL. if(enum_spd == 0x03) { @@ -239,7 +241,8 @@ void dcd_init (uint8_t rhport) // Turn around time for Highspeed is 0x09 usb_otg->GUSBCFG &= ~USB_OTG_GUSBCFG_TRDT; usb_otg->GUSBCFG |= (0x09 << USB_OTG_GUSBCFG_TRDT_Pos); - }else + } + else #endif { // Turn around programmed for 32+ MHz is 0x06 @@ -256,8 +259,6 @@ void dcd_init (uint8_t rhport) // Force device mode usb_otg->GUSBCFG |= USB_OTG_GUSBCFG_FDMOD; - TU_LOG2_LOCATION(); - // Restart PHY clock *((volatile uint32_t *)(_dcd_rhport[rhport].regs + USB_OTG_PCGCCTL_BASE)) = 0; @@ -282,8 +283,9 @@ void dcd_init (uint8_t rhport) dev->DCFG &= ~(3 << USB_OTG_DCFG_DSPD_Pos); // Transceiver delay, necessary for some ULPI PHYs - dev->DCFG |= (1 << 14); + //dev->DCFG |= (1 << 14); } + else #endif { // full speed with internal phy -- cgit v1.3.1 From 9bf2b3336610044dfb0187311797c5324eeec0ea Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 1 Aug 2020 12:02:59 +0700 Subject: correct isr context for nrf DCD_EVENT_UNPLUGGED also rename debug lookup to prevent conflict --- src/class/msc/msc_device.c | 6 +++--- src/common/tusb_common.h | 10 +++++----- src/portable/nordic/nrf5x/dcd_nrf5x.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/common') diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index 692fd2441..9b79b68a7 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -105,7 +105,7 @@ static inline uint16_t rdwr10_get_blockcount(uint8_t const command[]) //--------------------------------------------------------------------+ #if CFG_TUSB_DEBUG >= 2 -static lookup_entry_t const _msc_scsi_cmd_lookup[] = +static tu_lookup_entry_t const _msc_scsi_cmd_lookup[] = { { .key = SCSI_CMD_TEST_UNIT_READY , .data = "Test Unit Ready" }, { .key = SCSI_CMD_INQUIRY , .data = "Inquiry" }, @@ -120,7 +120,7 @@ static lookup_entry_t const _msc_scsi_cmd_lookup[] = { .key = SCSI_CMD_WRITE_10 , .data = "Write10" } }; -static lookup_table_t const _msc_scsi_cmd_table = +static tu_lookup_table_t const _msc_scsi_cmd_table = { .count = TU_ARRAY_SIZE(_msc_scsi_cmd_lookup), .items = _msc_scsi_cmd_lookup @@ -418,7 +418,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t TU_ASSERT( event == XFER_RESULT_SUCCESS && xferred_bytes == sizeof(msc_cbw_t) && p_cbw->signature == MSC_CBW_SIGNATURE ); - TU_LOG2(" SCSI Command: %s\r\n", lookup_find(&_msc_scsi_cmd_table, p_cbw->command[0])); + TU_LOG2(" SCSI Command: %s\r\n", tu_lookup_find(&_msc_scsi_cmd_table, p_cbw->command[0])); // TU_LOG2_MEM(p_cbw, xferred_bytes, 2); p_csw->signature = MSC_CSW_SIGNATURE; diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index 1dba6c914..d95c0ffc4 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -251,16 +251,16 @@ void tu_print_var(uint8_t const* buf, uint32_t bufsize) typedef struct { uint32_t key; - char const * data; -}lookup_entry_t; + const char* data; +} tu_lookup_entry_t; typedef struct { uint16_t count; - lookup_entry_t const* items; -} lookup_table_t; + tu_lookup_entry_t const* items; +} tu_lookup_table_t; -static inline char const* lookup_find(lookup_table_t const* p_table, uint32_t key) +static inline const char* tu_lookup_find(tu_lookup_table_t const* p_table, uint32_t key) { for(uint16_t i=0; icount; i++) { diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c index 7ca32c4f6..fdf56b6ca 100644 --- a/src/portable/nordic/nrf5x/dcd_nrf5x.c +++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c @@ -829,7 +829,7 @@ void tusb_hal_nrf_power_event (uint32_t event) hfclk_disable(); - dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, true); + dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) ? true : false); } break; -- cgit v1.3.1