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

[rtl872x] hal: fix false TX DMA completion in SPI HAL. #2749

Merged
merged 1 commit into from Mar 7, 2024

Conversation

XuGuohui
Copy link
Member

@XuGuohui XuGuohui commented Mar 7, 2024

Problem

SPIClass::transfer(const void* tx_buffer, void* rx_buffer, size_t length, wiring_spi_dma_transfercomplete_callback_t user_callback) exits even if the data is not fully clocked out when RX buffer is nullptr. If the CS pin is deasserted following the API, the on-going SPI transaction is ended up unexpectedly.

Solution

Check the busy state of the SPI peripheral, instead of only relying on internal flags.

Steps to Test

Run the attached test app.

Example App

#include "application.h"

SYSTEM_MODE(MANUAL);

#define SPI_TRANSACTION_LEN     (4096 * 3 + 9)

Serial1LogHandler l(115200, LOG_LEVEL_ALL);

uint8_t txBuf[SPI_TRANSACTION_LEN] = {0x00};
uint8_t rxBuf[SPI_TRANSACTION_LEN];

void setup() {
    while (!Serial.isConnected());
    Log.info("Starting...");

    pinMode(SS, OUTPUT);
    SPI.setClockSpeed(1000000);
    SPI.begin(SPI_MODE_MASTER);

    for (uint16_t i = 0; i < SPI_TRANSACTION_LEN; i++) {
        txBuf[i] = i;
    }

    delay(1s);
}

void loop() {
    digitalWrite(SS, LOW);

    // 1. No RX buffer
    SPI.transfer(txBuf, nullptr, SPI_TRANSACTION_LEN, nullptr);

    // 2. With RX buffer
    // SPI.transfer(txBuf, rxBuf, SPI_TRANSACTION_LEN, nullptr);

    // 3. No TX buffer (but there is an internal dummy buffer)
    // SPI.transfer(nullptr, rxBuf, SPI_TRANSACTION_LEN, nullptr);

    digitalWrite(SS, HIGH);

    delay(1s);
    Log.info("loop");
}

References

https://app.shortcut.com/particle/story/125500/fram-read-write-failures-for-jacuzzi-on-msom


Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

@avtolstoy avtolstoy added this to the 5.8.0 milestone Mar 7, 2024
@avtolstoy avtolstoy merged commit ff20b5d into develop Mar 7, 2024
13 checks passed
@avtolstoy avtolstoy deleted the fix/SC125500/rtl872x-spi-sync branch March 7, 2024 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants