Skip to content

Commit 477952f

Browse files
author
oclyke
committed
patch full duplex SPI transfers after migration to AmbiqSuite SDK 2.4.2 HAL
Copied functionality from 2.2.0 version of HAL. Will ultimately want to fix this. Tested with this sketch: ``` #include "SPI.h" #define CS_PIN 13 SPISettings MySPISettings(14000000, MSBFIRST, SPI_MODE0); ///////////////////////////////////////////// // Set TX and RX values for various data types uint8_t tx_val_8 = 0xAA; uint8_t rx_val_8 = 0x00; uint16_t tx_val_16 = 0xABBA; uint16_t rx_val_16 = 0x00; const uint8_t msg_len = 8; uint8_t tx_msg[msg_len] = {'H', 'e', 'l', 'l', 'o', '!', '!', 0}; uint8_t rx_msg[msg_len] = {0, 0, 0, 0, 0, 0, 0, 0}; uint8_t single_buff[msg_len] = {'t', 'e', 's', 't', ' ', 'p', 'a', 't'}; uint8_t single_buff_copy[msg_len] = {0, 0, 0, 0, 0, 0, 0, 0}; ///////////////////////////////////////////// // Main test void setup() { Serial.begin(115200); SPI.begin(); pinMode(CS_PIN, OUTPUT); digitalWrite(CS_PIN, HIGH); memcpy(single_buff_copy, single_buff, msg_len); // copy single buff for comparison after the fact delay(100); Serial.println("\n\nApollo3 SPI Full Duplex Test Sketch\n"); ///////////////////////////////////////////// // SPI Transaction with tests of each data type transfer (connect MOSI to MISO) SPI.beginTransaction(MySPISettings); digitalWrite(CS_PIN, LOW); rx_val_8 = SPI.transfer(tx_val_8); // test 8-bit fullduplex (Arduino API) rx_val_16 = SPI.transfer16(tx_val_16); // test 16-bit fullduplex (Arduino API) SPI.transferOutIn(tx_msg, rx_msg, msg_len); // test buffer fullduplex (API extension - shows HW capability) SPI.transfer(single_buff, msg_len); // test out/in in-place (Arduino API) digitalWrite(CS_PIN, HIGH); SPI.endTransaction(); ///////////////////////////////////////////// // Check if received values match sent values Serial.print("SPI.transfer(uint8_t); RESULT: "); test_8bit_match(); Serial.print("SPI.transfer16(uint16_t); RESULT: "); test_16bit_match(); Serial.print("SPI.transferOutIn(void*, void*, size_t); RESULT: "); test_msg_match(tx_msg, rx_msg, msg_len); Serial.print("SPI.transfer(void*, size_t); RESULT: "); test_msg_match(single_buff_copy, single_buff, msg_len); Serial.println(); } void loop() { } void test_8bit_match( void ){ if(rx_val_8 != tx_val_8){ Serial.printf("Error: failed fullduplex\n\tSent 0x%02X, received 0x%02X\n", tx_val_8, rx_val_8); }else{ Serial.printf("Passed!\n"); } } void test_16bit_match( void ){ if(rx_val_16 != tx_val_16){ Serial.printf("Error: failed fullduplex\n\tSent 0x%04X, received 0x%04X\n", tx_val_16, rx_val_16); }else{ Serial.printf("Passed!\n"); } } void test_msg_match( uint8_t* tx, uint8_t* rx, size_t len ){ bool msg_match = true; for(uint8_t ix = 0; ix < len; ix++){ if(tx[ix] != rx[ix]){ msg_match = false; break; } } if(!msg_match){ Serial.printf("Error: failed fullduplex\n\tSent: { "); for(uint8_t ix = 0; ix < len; ix++){ if(ix != 0){ Serial.print(", "); } Serial.print((char)tx[ix]); } Serial.print("}, recieved { "); for(uint8_t ix = 0; ix < len; ix++){ if(ix != 0){ Serial.print(", "); } Serial.print((char)rx[ix]); } Serial.print("}\n"); }else{ Serial.printf("Passed!\n"); } } ```
1 parent 72b62bb commit 477952f

File tree

4 files changed

+454
-20
lines changed

4 files changed

+454
-20
lines changed

cores/arduino/ard_sup/ap3_iomaster_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ typedef enum{
3535
AP3_IOM_PAD_TYPES_NUM,
3636
}ap3_iom_pad_type_e;
3737

38+
#define AM_HAL_IOM_FULLDUPLEX (3) // providing this symbol to recover SPI FULLDUPLEX capabilities within SDK 2.4.2
39+
3840
#endif // _AP3_IOM_TYPES_H_

0 commit comments

Comments
 (0)