Skip to content

Receive double buffering for STM32F1xx #456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 8, 2019

Conversation

makarenya
Copy link
Contributor

@makarenya makarenya commented Feb 24, 2019

Receive double buffering for STM32F103 and others. Milestone 1

Affected devices:

  • STM32F103x6
  • STM32F103xB
  • STM32F103xG
  • STM32F103xE
  • STM32F102x6
  • STM32F102xB

Transmission double buffering not tested yet.

Reception works. It achieve maximum CDC speed, available for this devices.
It also contains a set of fixes and improvements.

@fpistm fpistm self-requested a review February 25, 2019 07:59
fpistm
fpistm previously requested changes Feb 25, 2019
Copy link
Member

@fpistm fpistm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will review it deeply later.
Just a first request changes:
Remove the .idea (you can also use .gitignore to ensure not add it after)

@makarenya makarenya force-pushed the receive_double_buffering_for_f1 branch 3 times, most recently from c1e5b09 to 2e88dba Compare February 25, 2019 08:36
@fpistm fpistm self-requested a review February 25, 2019 08:38
@makarenya makarenya force-pushed the receive_double_buffering_for_f1 branch 2 times, most recently from c9309c1 to 7b09ae3 Compare February 25, 2019 08:48
@makarenya
Copy link
Contributor Author

Ok. .idea removed.
All my changes are splitted by a set of commits. Many of them very small and and evident.

@makarenya
Copy link
Contributor Author

And... You can review it later... but maybe you can test it? Speed on bluepill. And communication errors?

@fpistm
Copy link
Member

fpistm commented Feb 25, 2019

Yes I will test it. ;)

@fpistm
Copy link
Member

fpistm commented Feb 26, 2019

  • Board: BluePill F103C8
  • Test: Benchmark_USB_Receive_Standard from PJRC.
    • Without this PR:
      • Linux: Average bytes per second = 288175
      • Windows: Average bytes per second = 296861
    • With This PR:
      • Linux: Average bytes per second = 1251652
      • Windows: errors transmitting data

On Windows, AnalogReadSerial is functional only the benchmark test return an issue.
Data integrity will need to be tested.

FYI, benchmark code returning the issue:

		for (sent = 0; sent < 50000; sent += size) {
			n = transmit_bytes(port, buffer, size);
			if (n != size) die("errors transmitting data\n");
		}

@makarenya makarenya force-pushed the receive_double_buffering_for_f1 branch from a6f600e to ffb44b5 Compare March 5, 2019 20:21
@makarenya
Copy link
Contributor Author

It was hard. Very hard, so hard, that i must say any bad word: poop. Ok, i'm better. But i tested receiving on my mac and linux, and it works in many cases. I done it without interrupt disabling... Please, test it

@fpistm
Copy link
Member

fpistm commented Mar 6, 2019

Thanks @makarenya
I've started to debug but I had to switch to some other task. I will test it as soon as possible.

@makarenya makarenya force-pushed the receive_double_buffering_for_f1 branch 2 times, most recently from b872823 to 0cd04d8 Compare March 6, 2019 17:26
@makarenya makarenya changed the title Receive double buffering for f1 Receive double buffering for STM32F1xx Mar 6, 2019
@makarenya
Copy link
Contributor Author

And some interactive rebasing...

@makarenya makarenya force-pushed the receive_double_buffering_for_f1 branch 2 times, most recently from 051ad2b to 1cd5b35 Compare March 6, 2019 19:04
@fpistm fpistm added enhancement New feature or request review on going labels Mar 7, 2019
@fpistm fpistm dismissed their stale review March 7, 2019 13:20

Old review

@makarenya makarenya force-pushed the receive_double_buffering_for_f1 branch from 3065501 to f3fdfe3 Compare March 7, 2019 13:48
- Transmit endpoint over receive endpoint in both branches (style correction).
- Initialize receive buffer for the double-buffered endpoint (as single buffered already have)
- In double buffering transmission, set EP to valid, and set DTOG-s to the same buffer for NAK-ing

After activation, all endpoint would NAK-ing for any host attempt to receive anything,
it is impossible to determine exactly how large the allocated buffer should be.
To achieve double-buffering acceleration, the PCD_FreeUserBuffer call must
occur before the HAL_PCD_DataOutStageCallback call. But the real data buffer
can be allocated only in this callback. It turns out that the approach itself
needs to be changed - always allocate maximum allowable endpoint buffer size
(it's already happends in USB_ActivateEndpoint). At the same time we need to
check the size of the data received. This check be done at the time of data
receipt. During reception confirmation, it may be that there is no allocated
buffer at all. In this case, we will have to leave the filled PMA intact and
not complete its release. In this case, this operation will be repeated in
HAL_PCD_EP_ReceiveData.
@makarenya makarenya force-pushed the receive_double_buffering_for_f1 branch from 126c341 to 2bdb516 Compare March 7, 2019 13:55
Copy link
Member

@fpistm fpistm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one questions around double buffering.
Else seems nice. I will need to test deeply.

@fpistm
Copy link
Member

fpistm commented Mar 7, 2019

Argh, just retry with BP the speed test... and got old results ⁉️

Average bytes per second = 253013

@makarenya
Copy link
Contributor Author

I test BluePill on the two platforms: OpenWRT MT7688 Linux host and on my MacBook Pro 2017... And i get about 760 000 bps on first and 720 000 on second.

@makarenya
Copy link
Contributor Author

Moreover, I cannot get a speed greater than 760,000 under any circumstances at all, even if I do nothing in response to the IRQ, but simply say that the buffer is free and the hardware can work further.

@makarenya
Copy link
Contributor Author

I just dust off my windows PC and repeat all tests with the BluePill
With PR:

System Before PR With PR
OpenWRT on MT7688 730 000 760 000
MacBook Pro 2017 540 000 709 000
My old PC with i7 1-st gen 510 000 940 000

As you can see, on windows system speed is close to theoretical maximum

@fpistm
Copy link
Member

fpistm commented Mar 7, 2019

Strange, I will check that tomorrow. 😞
So, still the same issue.
Have you fix the resistor for USB of your BP ?
Anyway tested on Maple with the same result 😣
Reverting clean buffer allows to get speed higher on Linux but test failed on Windows. But clean is required.

@makarenya
Copy link
Contributor Author

No, i'm using original chinese BP. Two BP-s. First - connected to my MacBook via micro usb cable, second one connected to OpenWRT via two 68 Ohm resistors (resistors connects A11 and A12 pins of the BP board to the USB- and USB+ pins of OpenWRT board)

@makarenya
Copy link
Contributor Author

It seems to me, that there are reasons, that doesn't allow your host to speed up greater than 250 000 bps... Maybe some isochronous device connected to it... USB speakers or mic...

@fpistm
Copy link
Member

fpistm commented Mar 8, 2019

Well, seems my host USB stack was corrupted.... Fresh restart and it's work.
I've made several iterations and never seen issue.
Speed is now correct and seen no data corruption.

@fpistm fpistm added this to the 1.5.1/1.6.0 milestone Mar 8, 2019
@fpistm fpistm merged commit c7dffcd into stm32duino:master Mar 8, 2019
@makarenya makarenya deleted the receive_double_buffering_for_f1 branch March 8, 2019 18:21
benwaffle pushed a commit to benwaffle/Arduino_Core_STM32 that referenced this pull request Apr 10, 2019
…ring_for_f1

Receive double buffering for STM32F1xx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants