Recent

Author Topic: Getting a USB stack to work on STM32  (Read 4218 times)

petex

  • Jr. Member
  • **
  • Posts: 69
Re: Getting a USB stack to work on STM32 [solved]
« Reply #30 on: February 11, 2021, 08:06:29 pm »
Definitely works better than the old code. Looking quite reliable with my test PC program talking to the STM32. Nice one Laksen and MiR  :P
« Last Edit: February 11, 2021, 08:47:23 pm by petex »

petex

  • Jr. Member
  • **
  • Posts: 69
Re: Getting a USB stack to work on STM32
« Reply #31 on: February 12, 2021, 05:12:18 pm »
I have been writing some test code and the USB services are hanging.....

Code: Pascal  [Select][+][-]
  1.  
  2. function TCDCDevice.Write(const AData; ASize: SizeInt): SizeInt;
  3. var
  4.   ptr: pbyte;
  5.   left: SizeInt;
  6. begin
  7.   result:=0;
  8.   ptr:=@AData;
  9.  
  10.   while ASize>0 do
  11.   begin
  12.     if fTXPos>=fTXBufferSize then // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< HANGING
  13.     begin
  14.       if fBlocking then
  15.         fDevice^.Poll
  16.       else
  17.         break;
  18.     end        
  19.  

I am doing a succession of transmits which is different to the request/response protocol on the previous test. The request sizes of the transmits can exceed the TXBuffer size.

The CDC Write procedure is meant to issue several TX buffer transmits until all the application data is sent and blocks until this is done.

I can get it to hang where it is always repeating as shown in the above code excerpt. The write procedure does not return to the application.

fTXPos = 64 and
fTXBufferSize = 64 and
fBlocking = true

Laksen

  • Hero Member
  • *****
  • Posts: 697
    • J-Software
Re: Getting a USB stack to work on STM32
« Reply #32 on: February 12, 2021, 06:04:56 pm »
Can you consistently reproduce this? What's the value of fTxDone when it hangs?

petex

  • Jr. Member
  • **
  • Posts: 69
Re: Getting a USB stack to work on STM32
« Reply #33 on: February 13, 2021, 11:00:43 am »
hello,
I have changed my app somewhat and the problem manifests itself in a different way. This time it is in the receiver:

Code: Pascal  [Select][+][-]
  1. function TCDCDevice.Read(var ABuffer; ASize: SizeInt): SizeInt;
  2. var
  3.   left: SizeInt;
  4.   ptr: pbyte;
  5. begin
  6.   Result:=0;
  7.   ptr:=@ABuffer;
  8.  
  9.   while ASize>0 do
  10.   begin
  11.     if fRXPos<=0 then
  12.     begin
  13.       if fBlocking then
  14.         fDevice^.Poll
  15.       else
  16.         break;  // <<<<<<<<<<<<<< NEVER EXITS
  17.     end
  18.  

I am requesting 1 byte but the receiver does not return and sits polling the USB.

RXPos=0
fBlocking = true
TXpos=0
TXDone=true


The comms is request/response
THe request is 4 bytes
This works fine when the response is small ~ 8-16 bytes
When I increase the response size (probably over the TX buffer size of 64 bytes), there is a point when it hangs.

Is the problem due to the operation of "fBlocking", I have not looked at the code in any detail so i am guessing here.

edit:
I can normally plug and unplug the usb when the STM32 app is running with no problem. In the hang situation, when i plug it in Windows registers an error handling the USB interface.
« Last Edit: February 13, 2021, 11:04:08 am by petex »

Laksen

  • Hero Member
  • *****
  • Posts: 697
    • J-Software
Re: Getting a USB stack to work on STM32
« Reply #34 on: February 16, 2021, 01:50:14 pm »
I found a way to reproduce this bug. It seems to be related to how the hardware is driven in high throughput cases. The bulk out endpoint can get stuck in a case where it's not sending but all bits indicate that it should send. Might be a timing or bus issue

 

TinyPortal © 2005-2018