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

Cannot Receive Transaction over 32768 bytes #56

Closed
grahamgrieb opened this issue May 31, 2024 · 6 comments
Closed

Cannot Receive Transaction over 32768 bytes #56

grahamgrieb opened this issue May 31, 2024 · 6 comments

Comments

@grahamgrieb
Copy link

If my SPI transfer is over 32768 bytes, it seems like the receive size I get back will always be the size of the transfer minus 32,768 (if I do a 50000 byte transfer, my received_bytes will be 17232). My buffer size is well over 32,768 so I don't think that is the issue. I feel like it might be an overflow issue somewhere since 32,768 is the max value of a signed 16-bit integer. My SPI device i is sending data at 2 MHz. I've attached my code below. I am running on an ESP32-S3 on PlatformIO.



ESP32DMASPI::Slave slave;
static constexpr size_t BUFFER_SIZE = 90000;
static constexpr size_t QUEUE_SIZE = 1;
uint8_t *dma_rx_buf;

void loop()
{
  Serial.println("Waiting for data");
  //slave.queue(NULL, dma_rx_buf, BUFFER_SIZE);
  //const std::vector<size_t> received_bytes = slave.wait();
  size_t received_bytes = slave.transfer(NULL, dma_rx_buf, BUFFER_SIZE);
  Serial.println("Data received");
  Serial.println(received_bytes);
  //print error
  
  Serial.println(slave.errors()[0]);


}

void setup () {  
  Serial.begin(9600);
  
  //dma_tx_buf = slave.allocDMABuffer(BUFFER_SIZE);
  dma_rx_buf = slave.allocDMABuffer(BUFFER_SIZE);

  slave.setDataMode(SPI_MODE3);           // default: SPI_MODE0
  slave.setMaxTransferSize(BUFFER_SIZE);  // default: 4092 bytes
  slave.setQueueSize(QUEUE_SIZE);         // default: 1
  
  
  // begin() after setting
  slave.begin();  // default: HSPI (please refer README for pin assignments)

}
@hideakitai
Copy link
Owner

hideakitai commented Jun 1, 2024

Could you try again with build_flags = -DCORE_DEBUG_LEVEL=4 to show the debug log? After that, please send me the whole log output.

https://community.platformio.org/t/how-to-set-up-log-level-to-be-able-to-debug-the-esp32/8278

@grahamgrieb
Copy link
Author

This is what it looked like for a 50000 byte transfer. It says the receive size is 17232 (50000 minus 32768).

[D][ESP32DMASPISlave.h:112] spi_slave_task(): [ESP32DMASPISlave] spi_slavve_task start
Waiting for data
[ 324][D][ESP32DMASPISlave.h:140] spi_slave_task(): [ESP32DMASPISlave] new transaction request received (size = 1)
[ 3073][D][ESP32DMASPISlave.h:166] spi_slave_task(): [ESP32DMASPISlave] transaction complete: 137856 bits (17232 bytes) received
[ 3075][D][ESP32DMASPISlave.h:189] spi_slave_task(): [ESP32DMASPISlave] all requested transactions completed
Data received
17232

@hideakitai
Copy link
Owner

hideakitai commented Jun 1, 2024

Hmm, then ESP32's API does not receive more than 32768 bytes. The API does not limit the transfer size to it (and in my library). I'd like to confirm if the master really sends more than 32768 bytes. It is wrapped by signed 16 bits (int16_t). Does the master can send bytes more than the max of int16_t?

@grahamgrieb
Copy link
Author

I am using a logic analyzer to view the SPI messages so I can confirm it is actually 50000 bytes. It might just be an ESP32 API issue then.

@hideakitai
Copy link
Owner

Yes, maybe limited by esp-idf for ESP32-S3 esp-rs/esp-idf-hal#377

@hideakitai
Copy link
Owner

Closing this issue because this library does not cause it

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

No branches or pull requests

2 participants