Skip to content

Ambiq apollo3 fix of an SPI related SD bug #13861

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 2 commits into from
Nov 12, 2020
Merged

Ambiq apollo3 fix of an SPI related SD bug #13861

merged 2 commits into from
Nov 12, 2020

Conversation

idea--list
Copy link
Contributor

Summary of changes

While trying to implement SD functionality on the Artemis Thing Plus board i discovered that SDBlockDevice::program() fails for that target. After some investigation i found the root of the issue in spi_api.c for this target. Modifications:

  • within spi_master_write() spi_master_block_write() has been called with a hard-coded 0x00 fill character before, now it is changed to SPI_FILL_CHAR to be in synch with the fill char set in the Mbed configuration.
  • Also modified spi_master_block_write()previously it called am_hal_iom_blocking_transfer on line 182, but that prevented succesful SD card writing operations. This PR also changes that part to am_hal_iom_spi_blocking_fullduplex and SD functionality seems to be working.
  • This PR also normalizes the power consumption of an SD card with this target as after the SPI transaction the consumption does not remain high as it was the case before this PR.

Impact of changes

Enables succesfull SD-writes with the Apollo3 processor family, while other SPI functionalities seem to be preserved (tested with an eink and also an ADC which communicate over SPI).

Migration actions required

None

Documentation


Pull request type

[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] 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)
[] Tests / results supplied as part of this PR

Reviewers


Modified line 145:  previously the fill character has been hard coded to 0x00. However in Mbed OS core SPI_FILL_CHAR is defined in the core to be 0xFF by default (one can change that through mbed_app.json for example). This mod allows us to use the same fill character that is defined for Mbed OS.

Also modified spi_master_block_write(): previously it called am_hal_iom_blocking_transfer on line 182, but that prevented succesful SD card writing operations. Now i changed that part to am_hal_iom_spi_blocking_fullduplex and SD functionality seems to be working.
Modified the spi_master_block_write() function yet again. SD related examples still read/erase/write the SD cards as expected and with these alterations the power consumption does not remain high after the SPI transaction has been finished. However i still only tested the SD functionality. Please test other SPI scenarios and different sensors as well to find out if this PR introduces unexpected bugs or not.

Changes:
- deleted the whole if (xfer.ui32NumBytes) condition as i did not find it logical (by that i mean xfer.ui32NumBytes was also true within the following else if (tx_length != rx_length){} block, so basically when the 2 buffers had different lengths an extra transfer has been done for nothing)
- removed the bool Rw = (rx_length >= tx_length) as the comparison >= has no sense anymore after if (tx_length == rx_length) on line 159.
@0xc0170
Copy link
Contributor

0xc0170 commented Nov 4, 2020

@Wenn0101 Please review

@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Nov 4, 2020
@ciarmcom
Copy link
Member

ciarmcom commented Nov 4, 2020

@idea--list, thank you for your changes.
@ARMmbed/mbed-os-maintainers please review.

@ciarmcom ciarmcom requested a review from a team November 4, 2020 17:05
@0xc0170 0xc0170 requested a review from a team November 5, 2020 14:26
@0xc0170
Copy link
Contributor

0xc0170 commented Nov 11, 2020

CI started

@mbed-ci
Copy link

mbed-ci commented Nov 11, 2020

Jenkins CI Test : ✔️ SUCCESS

Build Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_dynamic-memory-usage ✔️
jenkins-ci/mbed-os-ci_cloud-client-pytest ✔️
jenkins-ci/mbed-os-ci_cmake-example-test ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️

@0xc0170 0xc0170 merged commit 74f9603 into ARMmbed:master Nov 12, 2020
@mergify mergify bot removed the ready for merge label Nov 12, 2020
@mbedmain mbedmain added release-version: 6.5.0 Release-pending and removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Nov 18, 2020
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.

5 participants