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

feat(spi): add transfer api with tx and rx buffer #2206

Merged
merged 3 commits into from
Nov 28, 2023

Conversation

fpistm
Copy link
Member

@fpistm fpistm commented Nov 24, 2023

Fixes #2205

For ref: arduino/ArduinoCore-API#189

Tested with SdFat patched with:

index 8b7da94..296a752 100644
@@ -44,9 +44,13 @@ void SdSpiArduinoDriver::end() { m_spi->end(); }
 uint8_t SdSpiArduinoDriver::receive() { return m_spi->transfer(0XFF); }
 //------------------------------------------------------------------------------
 uint8_t SdSpiArduinoDriver::receive(uint8_t* buf, size_t count) {
+#if defined(STM32_CORE_VERSION) && STM32_CORE_VERSION > 0x02070000
+  m_spi->transfer(NULL, buf, count);
+#else
   // Must send 0XFF - SD looks at send data for command.
   memset(buf, 0XFF, count);
   m_spi->transfer(buf, count);
+#endif
   return 0;
 }
 //------------------------------------------------------------------------------
@@ -57,9 +61,17 @@ void SdSpiArduinoDriver::send(const uint8_t* buf, size_t count) {
   if (count > 512) {
     return;
   }
+#if defined(STM32_CORE_VERSION)
+#if STM32_CORE_VERSION > 0x02070000
+  m_spi->transfer(buf, NULL, count);
+#elif STM32_CORE_VERSION == 0x02070000
+  #error "STM32 core version 2.7.0 is not compatible due to SPI API changes."
+#endif
+#else
   // Not easy to avoid receive so use tmp RX buffer.
   uint8_t rxBuf[512];
   // Discard const - STM32 not const correct.
   m_spi->transfer(const_cast<uint8_t*>(buf), rxBuf, count);
+#endif
 }
 #endif  // defined(SD_USE_CUSTOM_SPI) && defined(STM32_CORE_VERSION)

SPI_TRANSFER_TIMEOUT is always passed as an argument
while it is a constant definition.
So simply function call and check.

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
@fpistm fpistm added this to the 2.7.1 milestone Nov 24, 2023
@fpistm fpistm added this to In progress in STM32 core based on ST HAL via automation Nov 24, 2023
Fixes stm32duino#2205

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
@fpistm
Copy link
Member Author

fpistm commented Nov 28, 2023

PR is now ready. Thanks @greiman.

Results of bench sketch:

-### 2.6.0
-Sketch uses 41400 bytes (3%) of program storage space. Maximum is 1048576 bytes.
-Global variables use 3296 bytes (3%) of dynamic memory, leaving 95008 bytes for local variables. Maximum is 98304 bytes.
+### 2.7.1
+Sketch uses 40224 bytes (3%) of program storage space. Maximum is 1048576 bytes.
+Global variables use 3248 bytes (3%) of dynamic memory, leaving 95056 bytes for local variables. Maximum is 98304 bytes.
 
-FreeStack: 94912
+FreeStack: 94960
 Type is FAT16
 Card size: 1.98 GB (GB = 1E9 bytes)
 
@@ -20,15 +20,15 @@
 write speed and latency
 speed,max,min,avg
 KB/Sec,usec,usec,usec
-1126.13,154491,406,453
-1089.56,154378,406,468
+1138.69,154066,401,448
+1100.11,155705,401,463
 
 Starting read test, please wait.
 
 read speed and latency
 speed,max,min,avg
 KB/Sec,usec,usec,usec
-1143.64,458,444,445
-1143.90,457,445,445
+1222.79,428,416,417
+1222.49,428,416,417
 
 Done

@fpistm fpistm merged commit 20339e8 into stm32duino:main Nov 28, 2023
23 checks passed
STM32 core based on ST HAL automation moved this from In progress to Done Nov 28, 2023
@fpistm fpistm deleted the spi_transfer_buf branch November 28, 2023 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

Request to restore SPI.transfer(bufout, bufin, count) removed from 2.7.0.
1 participant