Skip to content
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

SDBlockDevice: revert HW CS support, add async support #181

Merged
merged 4 commits into from
Aug 27, 2023

Conversation

multiplemonomials
Copy link
Collaborator

@multiplemonomials multiplemonomials commented Aug 23, 2023

Summary of changes

Some time ago, in 0874f74, I updated the SDBlockDevice class to support HW chip selects. My intention was to use this as part of the CI test shield test suite, so that hardware CS functionality could be tested. However, after looking at the SDBlockDevice code and the SPI code more closely, I realized that this cannot work. The reason is, SDBlockDevice relies on keeping CS low across multiple transfers, but that is currently impossible when using hardware CS control with Mbed (even though I bet that most chips support it...).

So, I reverted that commit, expunging the HW CS constructors that were added.

However, for my DMA SPI test suite, I do need to be able to run at least some of the operations in SDBlockDevice with DMA, so that I can prove that DMA works the same as regular SPI. So, this MR converts some of the long-running operations from synchronous SPI calls into transfer_and_wait() calls. I converted every "readily convertable" call, meaning calls where it sends a multibyte buffer over the bus. There are plenty of places where it still uses the single byte API as part of the logic which I don't want to touch as they are part of the logic. However, trying to change that would require a broader refactor of the entire block device which I'm not signing up for (yet!).

The cool thing is, I can do these changes only because !180 adds the ability for asynchronous transfers to respect calls to the select() and deselect() functions. Without that feature, async transfers couldn't be used here because they would always bring CS high again after the transfer.

At any rate, the goal of this change is to steal back some execution time while it's running long transfers, such as sending/receiving 512 byte data blocks. And, even though it still isn't fully asynchronous, what I have here does that, so I'm good to ship it.

Impact of changes

Migration actions required

Documentation

See class docs


Pull request type

[] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[X] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[X] Tests / results supplied as part of this PR

I ran my new SD block device test suite with this MR and it passed!

7: [1692807337.44][CONN][RXD] >>> Running 9 test cases...
7: [1692807337.44][CONN][INF] found SYNC in stream: {{__sync;2fb8e63e-ed2d-4b6a-b8e5-6460d0312eaf}} it is #0 sent, queued...
7: [1692807337.44][CONN][INF] found KV pair in stream: {{__version;1.3.0}}, queued...
7: [1692807337.44][CONN][INF] found KV pair in stream: {{__timeout;40}}, queued...
7: [1692807337.44][CONN][INF] found KV pair in stream: {{__host_test_name;default_auto}}, queued...
7: [1692807337.44][HTST][INF] sync KV found, uuid=2fb8e63e-ed2d-4b6a-b8e5-6460d0312eaf, timestamp=1692807337.442130
7: [1692807337.44][HTST][INF] DUT greentea-client version: 1.3.0
7: [1692807337.44][HTST][INF] setting timeout to: 40 sec
7: [1692807337.44][HTST][INF] host test class: '<class 'mbed_os_tools.test.host_tests.default_auto.DefaultAuto'>'
7: [1692807337.44][HTST][INF] host test setup() call...
7: [1692807337.44][HTST][INF] CALLBACKs updated
7: [1692807337.44][HTST][INF] host test detected: default_auto
7: [1692807337.46][CONN][INF] found KV pair in stream: {{__testcase_name;SPI - SD card present (1MHz)}}, queued...
7: [1692807337.46][CONN][INF] found KV pair in stream: {{__testcase_name;SPI - Mount FS, Create File (1MHz)}}, queued...
7: [1692807337.46][CONN][INF] found KV pair in stream: {{__testcase_name;SPI - Write, Read, and Delete File (1MHz)}}, queued...
7: [1692807337.47][CONN][INF] found KV pair in stream: {{__testcase_name;[Async Interrupts] SPI - SD card present (1MHz)}}, queued...
7: [1692807337.47][CONN][INF] found KV pair in stream: {{__testcase_name;[Async Interrupts] SPI - Mount FS, Create File (1MHz)}}, queued...
7: [1692807337.47][CONN][INF] found KV pair in stream: {{__testcase_name;[Async Interrupts] SPI - Write, Read, and Delete File (1MHz)}}, queued...       
7: [1692807337.49][CONN][INF] found KV pair in stream: {{__testcase_name;[Async DMA] SPI - SD card present (1MHz)}}, queued...
7: [1692807337.49][CONN][INF] found KV pair in stream: {{__testcase_name;[Async DMA] SPI - Mount FS, Create File (1MHz)}}, queued...
7: [1692807337.49][CONN][INF] found KV pair in stream: {{__testcase_name;[Async DMA] SPI - Write, Read, and Delete File (1MHz)}}, queued...
7: [1692807337.51][CONN][RXD] 
7: [1692807337.51][CONN][RXD] >>> Running case #1: 'SPI - SD card present (1MHz)'...
7: [1692807337.51][CONN][RXD] Card Initialized: High Capacity Card
7: [1692807337.51][CONN][RXD] init card = 1
7: [1692807337.51][CONN][INF] found KV pair in stream: {{__testcase_start;SPI - SD card present (1MHz)}}, queued...
7: [1692807337.52][CONN][RXD] SDHC/SDXC Card: hc_c_size: 7562 
7: [1692807337.52][CONN][RXD] Sectors: 0x762c00x : 7744512
7: [1692807337.52][CONN][RXD] Capacity: 3781 MB
7: [1692807337.52][CONN][RXD] >>> 'SPI - SD card present (1MHz)': 1 passed, 0 failed
7: [1692807337.52][CONN][INF] found KV pair in stream: {{__testcase_finish;SPI - SD card present (1MHz);1;0}}, queued...
7: [1692807337.54][CONN][RXD] <greentea test suite>:0::PASS
7: [1692807337.54][CONN][RXD]
7: [1692807337.54][CONN][RXD] >>> Running case #2: 'SPI - Mount FS, Create File (1MHz)'...
7: [1692807337.54][CONN][RXD] Card Initialized: High Capacity Card
7: [1692807337.54][CONN][INF] found KV pair in stream: {{__testcase_start;SPI - Mount FS, Create File (1MHz)}}, queued...
7: [1692807337.55][CONN][RXD] init card = 1
7: [1692807337.55][CONN][RXD] SDHC/SDXC Card: hc_c_size: 7562
7: [1692807337.55][CONN][RXD] Sectors: 0x762c00x : 7744512
7: [1692807337.55][CONN][RXD] Capacity: 3781 MB
7: [1692807337.58][CONN][RXD] >>> 'SPI - Mount FS, Create File (1MHz)': 1 passed, 0 failed
7: [1692807337.58][CONN][RXD] <greentea test suite>:0::PASS
7: [1692807337.58][CONN][RXD]
7: [1692807337.58][CONN][INF] found KV pair in stream: {{__testcase_finish;SPI - Mount FS, Create File (1MHz);1;0}}, queued...
7: [1692807337.60][CONN][RXD] >>> Running case #3: 'SPI - Write, Read, and Delete File (1MHz)'...
7: [1692807337.60][CONN][RXD] Card Initialized: High Capacity Card
7: [1692807337.60][CONN][RXD] init card = 1
7: [1692807337.60][CONN][INF] found KV pair in stream: {{__testcase_start;SPI - Write, Read, and Delete File (1MHz)}}, queued...
7: [1692807337.62][CONN][RXD] SDHC/SDXC Card: hc_c_size: 7562 
7: [1692807337.62][CONN][RXD] Sectors: 0x762c00x : 7744512
7: [1692807337.62][CONN][RXD] Capacity: 3781 MB
7: [1692807337.77][CONN][RXD] >>> 'SPI - Write, Read, and Delete File (1MHz)': 1 passed, 0 failed
7: [1692807337.77][CONN][RXD] <greentea test suite>:0::PASS
7: [1692807337.77][CONN][RXD]
7: [1692807337.77][CONN][INF] found KV pair in stream: {{__testcase_finish;SPI - Write, Read, and Delete File (1MHz);1;0}}, queued...
7: [1692807337.79][CONN][RXD] >>> Running case #4: '[Async Interrupts] SPI - SD card present (1MHz)'...
7: [1692807337.79][CONN][RXD] Card Initialized: High Capacity Card
7: [1692807337.79][CONN][RXD] init card = 1
7: [1692807337.79][CONN][INF] found KV pair in stream: {{__testcase_start;[Async Interrupts] SPI - SD card present (1MHz)}}, queued...
7: [1692807337.80][CONN][RXD] SDHC/SDXC Card: hc_c_size: 7562 
7: [1692807337.80][CONN][RXD] Sectors: 0x762c00x : 7744512
7: [1692807337.80][CONN][RXD] Capacity: 3781 MB
7: [1692807337.80][CONN][INF] found KV pair in stream: {{__testcase_finish;[Async Interrupts] SPI - SD card present (1MHz);1;0}}, queued...
7: [1692807337.82][CONN][RXD] >>> '[Async Interrupts] SPI - SD card present (1MHz)': 1 passed, 0 failed
7: [1692807337.82][CONN][RXD] <greentea test suite>:0::PASS
7: [1692807337.82][CONN][RXD]
7: [1692807337.82][CONN][RXD] >>> Running case #5: '[Async Interrupts] SPI - Mount FS, Create File (1MHz)'...
7: [1692807337.84][CONN][RXD] Card Initialized: High Capacity Card 
7: [1692807337.84][CONN][RXD] init card = 1
7: [1692807337.84][CONN][RXD] SDHC/SDXC Card: hc_c_size: 7562
7: [1692807337.84][CONN][RXD] Sectors: 0x762c00x : 7744512
7: [1692807337.84][CONN][RXD] Capacity: 3781 MB
7: [1692807337.84][CONN][INF] found KV pair in stream: {{__testcase_start;[Async Interrupts] SPI - Mount FS, Create File (1MHz)}}, queued...
7: [1692807337.87][CONN][INF] found KV pair in stream: {{__testcase_finish;[Async Interrupts] SPI - Mount FS, Create File (1MHz);1;0}}, queued...
7: [1692807337.88][CONN][RXD] >>> '[Async Interrupts] SPI - Mount FS, Create File (1MHz)': 1 passed, 0 failed
7: [1692807337.88][CONN][RXD] <greentea test suite>:0::PASS
7: [1692807337.88][CONN][RXD]
7: [1692807337.88][CONN][RXD] >>> Running case #6: '[Async Interrupts] SPI - Write, Read, and Delete File (1MHz)'...
7: [1692807337.90][CONN][RXD] Card Initialized: High Capacity Card 
7: [1692807337.90][CONN][RXD] init card = 1
7: [1692807337.90][CONN][RXD] SDHC/SDXC Card: hc_c_size: 7562
7: [1692807337.90][CONN][INF] found KV pair in stream: {{__testcase_start;[Async Interrupts] SPI - Write, Read, and Delete File (1MHz)}}, queued...      
7: [1692807337.91][CONN][RXD] Sectors: 0x762c00x : 7744512
7: [1692807337.91][CONN][RXD] Capacity: 3781 MB
7: [1692807338.06][CONN][INF] found KV pair in stream: {{__testcase_finish;[Async Interrupts] SPI - Write, Read, and Delete File (1MHz);1;0}}, queued...
7: [1692807338.07][CONN][RXD] >>> '[Async Interrupts] SPI - Write, Read, and Delete File (1MHz)': 1 passed, 0 failed
7: [1692807338.07][CONN][RXD] <greentea test suite>:0::PASS

Reviewers


JohnK1987
JohnK1987 previously approved these changes Aug 23, 2023
Base automatically changed from dev/spi-api-cleanup-part2 to master August 25, 2023 16:14
@multiplemonomials multiplemonomials dismissed JohnK1987’s stale review August 25, 2023 16:14

The base branch was changed.

@multiplemonomials
Copy link
Collaborator Author

Merging this because it was approved but the approval was removed by a rebase

@multiplemonomials multiplemonomials merged commit 264dbe2 into master Aug 27, 2023
9 checks passed
@multiplemonomials multiplemonomials deleted the dev/async-sdblockdevice branch August 27, 2023 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants