cancel
Showing results for 
Search instead for 
Did you mean: 

How to define USB PMA Buffers size and addresses ?

arnaud239955
Associate II
Posted on May 22, 2015 at 09:34

Hello

I am designing an USB device on the STM32L151CB micro-controller. I use the STM32Cube_FW_L1_V1.2.0 USB library.

My device enumerates correctly. I reach the point of sending an receiving data. So I need to define PMA buffers. I looked at a CDC generated project to try to understand how buffers must be declared in the PMA. I have difficulties to understand how PMA works. So, here are my questions:

- In the USBD_LL_Init function, the code is as follows

    HAL_PCDEx_PMAConfig(pdev->pData , 0x00 , PCD_SNG_BUF, 0x18);

    HAL_PCDEx_PMAConfig(pdev->pData , 0x80 , PCD_SNG_BUF, 0x58);

    HAL_PCDEx_PMAConfig(pdev->pData , 0x81 , PCD_SNG_BUF, 0xC0);  

    HAL_PCDEx_PMAConfig(pdev->pData , 0x01 , PCD_SNG_BUF, 0x110);

    HAL_PCDEx_PMAConfig(pdev->pData , 0x82 , PCD_SNG_BUF, 0x100);  

-I don't understand the relatioship between the pmaadress (hardcoded as 0x18, 0x58...) and the necessary size of the tx/rx buffer ?

-Is the size calculated by difference of successive addresses ?

-Is there another place in the code where I shall declare the buffers and then calculate addresses ?

Thanks a lot

Zirco

#usb-device #stm32f103 #pma-usb-pmaconfig #pma
1 REPLY 1
itxs
Associate II
Posted on July 24, 2015 at 16:19

Hi. the relationship between PMA addresses are that they maped hard to endpoints. 0x18/0x58 - two halfs of memory mapped to Endpoint 0 (default control endpoint) In(0x18) and Out(0x58) buffers. Endpoint maximum buffer size are 64 bytes, so PMA addresses should differ by 64 bytes: 0x18, 0x58, 0x98, 0xD8, ... 0x98 and 0xD8 mapped to next EP buffers - EP1 In and Out buffers. I think, in other MCUs starting address may be different... I not found these information in RM0008, its my opinion.

UPD: If high byte of endpoint address (not PMA address, endpoint address for example 0x01, 0x81, 0x02, 0x82) is 8 (for example 0x81), that means IN endpoint buffer (transmitting INTO tube, into PC). Without 8 it will be OUT endpoint buffer address (receiving from OUT of tube, from PC usb)