SdSpiTeensy3.cpp - Use transfer(tx, rx, size) - avoid 512 bytes on stack #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As I mentioned in a new issue, I created against the original code base for SdFat:
greiman#506
I noticed that the code for Teensy boards uses a special driver SdSpiTeensy3.cpp which uses
the SPI call: transfer(buffer, count);
Which on write functions, the code allocates 512 bytes on the stack, then copies the data out of the buffer passed in, to the copy on the stack, as to avoid having the transfer method overwriting the buffer passed in.
As you know, 8 years ago we added the alternative transfer method: transfer(txbuf, rxbuf, count); where either of these could be nullptr. Using this instead removes the need for the temporary copy on the stack.
Note: this is not the fix I would do, now, and from the comments by @greiman on the issue, he probably would not accept. His current released sources, now has the ability to do the exact same stuff without the need for a special driver. As the SdFatConfig.h file now has the ability to choose a few different ways to do these transfers without the need for a specialized driver:
We could simply use: #define USE_SPI_ARRAY_TRANSFER 2
The only thing this would miss, is the ability to pass in: that I am using the built-in SD adapter on T3.5/3.6/4.x to the SPI driver, and it will map that to the SPI pins on the adapter, which I have not seen nor heard of anyone using?
However, this updated code has not been merged into your fork, so went with this
limited update for now.