cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103C8T6 USB Buffer Descriptor Table

Vladimir Mitrofanov
Associate II
@FBL Can you explain me about buffer descriptor table (BDT)?

Is it fixed?
I have got behavior that I can't explain.
Dumping packets on host I got wrong data. Length is ok, but data is wrong.
In BDT I wrote correct address and length. Data wrote in pma (adress that is in BDT) is correct.
But when I stop in debugging address in BDT is changed. As I think in BDT there is a place for each endpoint (or it is like cyclic buffer?)
What I found if I set break point with "if" condition, just before sending address in BDT is OK, and data on host is OK.

It seems to me that I am working incorrectly with BDT.

1 ACCEPTED SOLUTION

Accepted Solutions

I didn't find why BDT for endpoint 3 and 4 is changed by some code. I tried to set watch points and debug fw but, debugger stops incorrectly. For my task I start to use endpoint 5, for which BDT stays correct after configuring it and it works as described in programming manual.

View solution in original post

8 REPLIES 8
isikli
Associate III

The issues you are seeing are likely caused by these two point :

1) The Address Gap: The PMA is 16 bits wide but mapped to a 32-bit CPU bus. Every 2 bytes of data are followed by a 2-byte hole in memory. If you use memcpy(), your data will be corrupted. You must use a custom copy function that skips every other half-word. Offsets, Not Addresses: The BDT expects offsets from the start of the PMA, not absolute CPU addresses (e.g., use 0x40, not 0x40006040).

2) Debugger Illusion: The address in the BDT doesn't "change" on its own, but the hardware might mask bits, or your debugger might be struggling with the 32-bit/16-bit aliasing.

Ensure your code writes 16-bit values to 32-bit aligned addresses in the PMA. Are you using a custom USB stack, or are you modifying the standard ST/HAL library?

FBL
ST Employee

Hi  @Vladimir Mitrofanov 

Could you please provide more details about your setup ? Are you using CubeF1 Do you reproduce using a reference board?

Did you check this article How to configure the packet memory area in STM32

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.




Best regards,
FBL

@FBL @isikli Hi, colleagues.
I didn't still solve this. I use standard ST/HAL library.

Board looks OK, because I generated simple HID project and interrupt endpoint data goes ok.
I configure endpoint in my project using
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x84 , PCD_SNG_BUF, 0x150);
and data writes to it by USB_EPStartXfer that calls USB_WritePMA and PCD_SET_EP_TX_CNT.
@isikli USB_WritePMA align/skips data.

OK @Vladimir Mitrofanov 

Could you please verify the values configured for USB_BTABLE, BLSIZE, and NUM_BLOCK in the failing endpoint?

USB_BTABLE defines the base address of the buffer descriptor table, while BLSIZE and NUM_BLOCK determine the memory allocation size for the buffer. An incorrect combination may lead to unexpected behavior even if the buffer content appears correct while debugging firmware. If possible, it is preferable to use a USB analyzer rather than relying only on debugging.

Please refer to the reference manual and the article on PMA configuration for the table that maps buffer size allocation according to NUM_BLOCK and BLSIZE.

If the issue persists, could you please provide a minimum firmware that reproduces the problem on our reference board? This would help us narrow down the root cause more efficiently.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.




Best regards,
FBL

@FBL Thank you for your reply
When I just init device it is ok. 
As you can see in the picture memory contains correct values

VladimirMitrofanov_0-1776327403587.png

But before sending response memory is curupted

VladimirMitrofanov_1-1776327492416.png

During debugging I didn't found where it could happen.

I didn't find why BDT for endpoint 3 and 4 is changed by some code. I tried to set watch points and debug fw but, debugger stops incorrectly. For my task I start to use endpoint 5, for which BDT stays correct after configuring it and it works as described in programming manual.

FBL
ST Employee

Hello @Vladimir Mitrofanov 

First, debugger watchpoints/breakpoints are unreliable for catching the exact moment of change in USB app.

>I didn't find why BDT for endpoint 3 and 4 is changed by some code.

Do you mean EP 0x03 or 0x83? or maybe 0x84?  Maybe your EP sizes are overlapping.

FBL_0-1776871312867.png

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.




Best regards,
FBL

Hello, @FBL 
As you wrote about overlapping, I had this thought. I check device descriptor and other place where endpoint size used, but without results.
Second, buffer descriptor table is changed, not data area.
I set watch point with constraints to BDT (0x40006040 - for endpoint 4) for data changing/writing but constraints not working (or I do something wrong) and it is difficult to catch moment when corruption happens.
A bit later I will continue to debug. Now I use endpoint 5 for my goal.
Thank you.