From 5a854ef2dc03373f125b48e93accf302c2fbdd66 Mon Sep 17 00:00:00 2001 From: henneboi Date: Mon, 11 Mar 2024 13:36:25 +0100 Subject: [PATCH 1/4] dcd_stm32_fsdev.c: Fix a bug seend with stm32h5xxx when the driver is compiled with cubeide O1/O2/O3 --- .../st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h index 3f4db985d..e0df21860 100644 --- a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h +++ b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h @@ -296,6 +296,19 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_rx_cnt(USB_TypeDef * USB { #ifdef FSDEV_BUS_32BIT (void) USBx; + volatile uint32_t count = 10; + /* + WA: few cycles for RX PMA descriptor to update + This workaround is ported from stm32h5xx_hal_pcd.h : PCD_GET_EP_RX_CNT H5 + This code fixes an issue when the code is compiled in GCC with a fast optimization(O2/O3) and device with an high frequency. + The function doesn't return the correct value. + Issue observed on Windows 10 and stm32h573i_dk and tud_task() scheduled by IT, the device is not migrated the USB device is not visible . + */ + while (count > 0U) + { + asm("NOP"); + count--; + } return (pma32[2*bEpIdx + 1] & 0x03FF0000) >> 16; #else __I uint16_t *regPtr = pcd_ep_rx_cnt_ptr(USBx, bEpIdx); From f9c85ae47b0aacd6716b671a5b6ea289b43275c0 Mon Sep 17 00:00:00 2001 From: henneboi Date: Wed, 6 Mar 2024 17:46:47 +0100 Subject: [PATCH 2/4] IAR Warning: Fixed due to an boolean operation between enum (Pa089) Warning[Pa089]: enumerated type mixed with another enumerated type ...tusb_uac2_audio.c 199 This issue stops the build if we treat warning as error --- src/device/usbd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/device/usbd.h b/src/device/usbd.h index 3ab6c813f..cf500143a 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -421,7 +421,7 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb /* Standard AS Isochronous Feedback Endpoint Descriptor(4.10.2.1) */ #define TUD_AUDIO_DESC_STD_AS_ISO_FB_EP_LEN 7 #define TUD_AUDIO_DESC_STD_AS_ISO_FB_EP(_ep, _interval) \ - TUD_AUDIO_DESC_STD_AS_ISO_FB_EP_LEN, TUSB_DESC_ENDPOINT, _ep, (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_NO_SYNC | TUSB_ISO_EP_ATT_EXPLICIT_FB), U16_TO_U8S_LE(4), _interval + TUD_AUDIO_DESC_STD_AS_ISO_FB_EP_LEN, TUSB_DESC_ENDPOINT, _ep, (uint8_t) ((uint8_t)TUSB_XFER_ISOCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_NO_SYNC | (uint8_t)TUSB_ISO_EP_ATT_EXPLICIT_FB), U16_TO_U8S_LE(4), _interval // AUDIO simple descriptor (UAC2) for 1 microphone input // - 1 Input Terminal, 1 Feature Unit (Mute and Volume Control), 1 Output Terminal, 1 Clock Source From 0610070d07babf3623016603325afa938d4fc9f7 Mon Sep 17 00:00:00 2001 From: Ha Thach Date: Mon, 25 Mar 2024 18:44:51 +0700 Subject: [PATCH 3/4] Update dcd_stm32_fsdev_pvt_st.h --- .../st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h index e0df21860..5a129ecf8 100644 --- a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h +++ b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h @@ -296,17 +296,14 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_rx_cnt(USB_TypeDef * USB { #ifdef FSDEV_BUS_32BIT (void) USBx; - volatile uint32_t count = 10; - /* - WA: few cycles for RX PMA descriptor to update - This workaround is ported from stm32h5xx_hal_pcd.h : PCD_GET_EP_RX_CNT H5 - This code fixes an issue when the code is compiled in GCC with a fast optimization(O2/O3) and device with an high frequency. - The function doesn't return the correct value. - Issue observed on Windows 10 and stm32h573i_dk and tud_task() scheduled by IT, the device is not migrated the USB device is not visible . + /* WA: few cycles for RX PMA descriptor to update, otherwise doesn't return the correct value. + Note: required for G0, U5, H5 etc. + This workaround is ported from stm32h5xx_hal_pcd.h and fixes the issue when calling this function fast enough. + Reproduced with GCC ast optimization(O2/O3) and stm32h573i_dk with an high frequency. + Observed on Windows 10 where tud_task() is scheduled by interrupt handler. */ - while (count > 0U) - { - asm("NOP"); + volatile uint32_t count = 10; // defined as PCD_RX_PMA_CNT in stm32 hal_driver + while (count > 0U) { count--; } return (pma32[2*bEpIdx + 1] & 0x03FF0000) >> 16; From 29f016ae15eb94654748bf29b81557f6ab611384 Mon Sep 17 00:00:00 2001 From: Ha Thach Date: Mon, 25 Mar 2024 18:59:05 +0700 Subject: [PATCH 4/4] fix pre-commit --- src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h index 5a129ecf8..ade64b4fb 100644 --- a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h +++ b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h @@ -297,9 +297,9 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_rx_cnt(USB_TypeDef * USB #ifdef FSDEV_BUS_32BIT (void) USBx; /* WA: few cycles for RX PMA descriptor to update, otherwise doesn't return the correct value. - Note: required for G0, U5, H5 etc. + Note: required for G0, U5, H5 etc. This workaround is ported from stm32h5xx_hal_pcd.h and fixes the issue when calling this function fast enough. - Reproduced with GCC ast optimization(O2/O3) and stm32h573i_dk with an high frequency. + Reproduced with GCC ast optimization(O2/O3) and stm32h573i_dk with an high frequency. Observed on Windows 10 where tud_task() is scheduled by interrupt handler. */ volatile uint32_t count = 10; // defined as PCD_RX_PMA_CNT in stm32 hal_driver