8000 samd: Refactor to use shared tinyusb, implement unique id (with cross-port refactor) by projectgus · Pull Request #12908 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

samd: Refactor to use shared tinyusb, implement unique id (with cross-port refactor) #12908

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 3 commits into from
Nov 16, 2023

Conversation

projectgus
Copy link
Contributor
@projectgus projectgus commented Nov 7, 2023

Three related changes for tinyusb on samd port (including a refactor that also covers rp2 and renesas-ra):

  • Switch to use the shared tinyusb implementation (same functionality, shared source code). This is a precursor to supporting Python-implemented USB devices on this platform.
  • Add a helper for "bytes to hex" conversion that is implemented in multiple ports for serial numbers. Refactor the rp2 and renesas-ra ports to use the helper instead of the same piece of code.
  • Implement a unique USB device serial number for samd based on the existing machine.unique_id() implementation. Previously this was all-zeroes // TODO.

Can split into two PRs if that is easier to review.

Tested on a Seeed WIO Terminal and a Seeed XIAO.

Code size impacts:

Stage Flash Size - WIO Terminal (SAMD51) Seeed XIAO (SAMD21)
master 261180 184144
Refactor to shared tinyusb 261208 184180
Implement serial number 261284 184244

@projectgus
Copy link
Contributor Author

There is a merge conflict between this PR and #12846 as they make some of the same changes. If either merges, I'll rebase the other.

Copy link
codecov bot commented Nov 8, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (033361d) 98.43% compared to head (c8d6af4) 98.43%.

❗ Current head c8d6af4 differs from pull request most recent head 8b1980a. Consider uploading reports for the commit 8b1980a to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #12908   +/-   ##
=======================================
  Coverage   98.43%   98.43%           
=======================================
  Files         158      158           
  Lines       20978    20978           
=======================================
  Hits        20649    20649           
  Misses        329      329           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dpgeorge dpgeorge added this to the release-1.22.0 milestone Nov 8, 2023
@dpgeorge
Copy link
Member
dpgeorge commented Nov 9, 2023

This can be rebased now.

@projectgus projectgus force-pushed the refactor/samd_tinyusb branch from ec9be41 to c8d6af4 Compare November 14, 2023 00:23
@projectgus
Copy link
Contributor Author

Rebased, updated the size numbers.

Functionality and code size don't really change, but removes port-specific
code in favour of shared code.

(The MSC implemented in shared/tinyusb depends on some functions in the
pico-sdk, so this change doesn't make this available for samd.)

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
Change the rp2 and renesas-ra ports to use the helper function.

Saves copy-pasta, at the small cost of one more function call in the
firmware (if not using LTO).

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
Replaces the previous all-zeroes "TODO" serial number.

Requires refactoring the low-level unique_id routine out from modmachine.c.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
@dpgeorge dpgeorge force-pushed the refactor/samd_tinyusb branch from c8d6af4 to 8b1980a Compare November 16, 2023 04:05
@dpgeorge dpgeorge merged commit 8b1980a into micropython:master Nov 16, 2023
@dpgeorge
Copy link
Member

Merged, thank you.

@projectgus projectgus deleted the refactor/samd_tinyusb branch November 1, 2024 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0