Skip to main content
Explorer II
November 6, 2023
Question

usb buffer descriptor masks in cmsis device h5

  • November 6, 2023
  • 3 replies
  • 902 views

They are defined like this in stm32h563xx.h:

/*Buffer Descriptor Mask*/
#define USB_PMA_TXBD_ADDMSK (0xFFFF0000UL)
#define USB_PMA_TXBD_COUNTMSK (0x0000FFFFUL)
#define USB_PMA_RXBD_ADDMSK (0xFFFF0000UL)
#define USB_PMA_RXBD_COUNTMSK (0x03FFFFFFUL)

ADDMSKs are correct, but I was expecting both COUNTMSK to be 0xFC00FFFFUL since both COUNT_TX and COUNT_RX are 10 bits [25:16]. When double buffering is used there is BLSIZE and NUM_BLOCK but I dont see anything about these in the header. Is there a reason the TXBD and RXBD_COUNTMSK are defined like this ?

    This topic has been closed for replies.

    3 replies

    ST Employee
    November 8, 2023

    Hello @mete ,

    i'm checking this out i will come back to you as soon as possible .

    BR

    Hichem

    ST Employee
    November 9, 2023

    Hello @mete 

    after investigation on this matter i have the following informations :

    1. The USB_PMA_TXBD_COUNTMSK clears 16 -> 31 bits including the reserved ones . As the in the USB_CHEP_TXRXBD_n are store in the RAM the clear is doing its intended  function as used in the  usb driver stm32h5xx_ll_usb.h

      #define USB_DRD_SET_CHEP_TX_CNT(USBx,bEpChNum, wCount) \

      do { \

      /* Reset old TX_Count value */ \

      (USB_DRD_PMA_BUFF + (bEpChNum))->TXBD &= USB_PMA_TXBD_COUNTMSK; \

      \

      /* Set the wCount in the dedicated EP_TXBuffer */ \

      (USB_DRD_PMA_BUFF + (bEpChNum))->TXBD |= (uint32_t)((uint32_t)(wCount) << 16U); \

      } while(0)

    2.  The USB_PMA_TXBD_COUNTMSK clears 26 -> 31 and it is not used in the  stm32h5xx_ll_usb.h define for USB_DRD_SET_CHEP_RX_CNT as it's not set as intended this issue this has been escalated internally for further investigation 

    Internal ticket number: 165995 (This is an internal tracking number and is not accessible or usable by customers).

    this has no effect on the HAL implementation of USB as this mask is not used so using the HAL you shouldn't have any issues .

    BR

     

    Technical Moderator
    October 10, 2025

    Hi @mete 

    The mask USB_PMA_RXBD_COUNTMSK = 0x03FFFFFFUL ensures that when you read or write the RX count, these bits are preserved and not accidentally cleared or overwritten. This was meant to avoid corrupting the actual data length information.

    So, the RX count mask keeps bits [25:16] because these bits directly represent the valid received data length from the host. Maintaining this mask ensures accurate tracking of incoming data size.