2026-04-14 2:21 AM - last edited on 2026-04-15 3:15 AM by FBL
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.
Solved! Go to Solution.
2026-04-22 4:30 AM
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.
2026-04-14 2:32 AM
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?
2026-04-14 2:32 AM
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.
2026-04-14 11:31 PM
@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.
2026-04-15 2:28 AM
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.
2026-04-16 1:19 AM
@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
But before sending response memory is curupted
During debugging I didn't found where it could happen.
2026-04-22 4:30 AM
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.
2026-04-22 8:55 AM
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.
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.
2026-04-22 10:33 PM
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.