Merge branch 'test/spi_master_internal_connect' into 'master'
test(spi_master): add test case for 3 DMA issues with internal connection by gpio mux. See merge request !1217
This commit is contained in:
commit
58a5d883f4
1 changed files with 134 additions and 51 deletions
|
@ -286,37 +286,37 @@ TEST_CASE("SPI Master no response when switch from host1 (HSPI) to host2 (VSPI)"
|
||||||
struct spi_transaction_t transaction = {
|
struct spi_transaction_t transaction = {
|
||||||
.flags = SPI_TRANS_USE_TXDATA | SPI_TRANS_USE_RXDATA,
|
.flags = SPI_TRANS_USE_TXDATA | SPI_TRANS_USE_RXDATA,
|
||||||
.length = 16,
|
.length = 16,
|
||||||
.tx_buffer = NULL,
|
|
||||||
.rx_buffer = NULL,
|
.rx_buffer = NULL,
|
||||||
.tx_data = {0x04, 0x00}
|
.tx_data = {0x04, 0x00}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//initialize for first host
|
//initialize for first host
|
||||||
host = 1;
|
host = 1;
|
||||||
|
|
||||||
assert(spi_bus_initialize(host, &bus_config, dma) == ESP_OK);
|
TEST_ASSERT(spi_bus_initialize(host, &bus_config, dma) == ESP_OK);
|
||||||
assert(spi_bus_add_device(host, &device_config, &spi) == ESP_OK);
|
TEST_ASSERT(spi_bus_add_device(host, &device_config, &spi) == ESP_OK);
|
||||||
|
|
||||||
printf("before first xmit\n");
|
printf("before first xmit\n");
|
||||||
assert(spi_device_transmit(spi, &transaction) == ESP_OK);
|
TEST_ASSERT(spi_device_transmit(spi, &transaction) == ESP_OK);
|
||||||
printf("after first xmit\n");
|
printf("after first xmit\n");
|
||||||
|
|
||||||
assert(spi_bus_remove_device(spi) == ESP_OK);
|
TEST_ASSERT(spi_bus_remove_device(spi) == ESP_OK);
|
||||||
assert(spi_bus_free(host) == ESP_OK);
|
TEST_ASSERT(spi_bus_free(host) == ESP_OK);
|
||||||
|
|
||||||
|
|
||||||
//for second host and failed before
|
//for second host and failed before
|
||||||
host = 2;
|
host = 2;
|
||||||
|
|
||||||
assert(spi_bus_initialize(host, &bus_config, dma) == ESP_OK);
|
TEST_ASSERT(spi_bus_initialize(host, &bus_config, dma) == ESP_OK);
|
||||||
assert(spi_bus_add_device(host, &device_config, &spi) == ESP_OK);
|
TEST_ASSERT(spi_bus_add_device(host, &device_config, &spi) == ESP_OK);
|
||||||
|
|
||||||
printf("before second xmit\n");
|
printf("before second xmit\n");
|
||||||
// the original version (bit mis-written) stucks here.
|
// the original version (bit mis-written) stucks here.
|
||||||
assert(spi_device_transmit(spi, &transaction) == ESP_OK);
|
TEST_ASSERT(spi_device_transmit(spi, &transaction) == ESP_OK);
|
||||||
// test case success when see this.
|
// test case success when see this.
|
||||||
printf("after second xmit\n");
|
printf("after second xmit\n");
|
||||||
|
|
||||||
|
TEST_ASSERT(spi_bus_remove_device(spi) == ESP_OK);
|
||||||
|
TEST_ASSERT(spi_bus_free(host) == ESP_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
IRAM_ATTR static uint32_t data_iram[320];
|
IRAM_ATTR static uint32_t data_iram[320];
|
||||||
|
@ -355,11 +355,10 @@ TEST_CASE("SPI Master DMA test, TX and RX in different regions", "[spi]")
|
||||||
};
|
};
|
||||||
//Initialize the SPI bus
|
//Initialize the SPI bus
|
||||||
ret=spi_bus_initialize(HSPI_HOST, &buscfg, 1);
|
ret=spi_bus_initialize(HSPI_HOST, &buscfg, 1);
|
||||||
assert(ret==ESP_OK);
|
TEST_ASSERT(ret==ESP_OK);
|
||||||
//Attach the LCD to the SPI bus
|
//Attach the LCD to the SPI bus
|
||||||
ret=spi_bus_add_device(HSPI_HOST, &devcfg, &spi);
|
ret=spi_bus_add_device(HSPI_HOST, &devcfg, &spi);
|
||||||
assert(ret==ESP_OK);
|
TEST_ASSERT(ret==ESP_OK);
|
||||||
|
|
||||||
|
|
||||||
static spi_transaction_t trans[6];
|
static spi_transaction_t trans[6];
|
||||||
int x;
|
int x;
|
||||||
|
@ -392,17 +391,101 @@ TEST_CASE("SPI Master DMA test, TX and RX in different regions", "[spi]")
|
||||||
trans[5].length = 8*4;
|
trans[5].length = 8*4;
|
||||||
trans[5].flags = SPI_TRANS_USE_RXDATA | SPI_TRANS_USE_TXDATA;
|
trans[5].flags = SPI_TRANS_USE_RXDATA | SPI_TRANS_USE_TXDATA;
|
||||||
|
|
||||||
|
|
||||||
//Queue all transactions.
|
//Queue all transactions.
|
||||||
for (x=0; x<6; x++) {
|
for (x=0; x<6; x++) {
|
||||||
ret=spi_device_queue_trans(spi,&trans[x], portMAX_DELAY);
|
ret=spi_device_queue_trans(spi,&trans[x], portMAX_DELAY);
|
||||||
assert(ret==ESP_OK);
|
TEST_ASSERT(ret==ESP_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (x=0; x<6; x++) {
|
for (x=0; x<6; x++) {
|
||||||
spi_transaction_t* ptr;
|
spi_transaction_t* ptr;
|
||||||
ret=spi_device_get_trans_result(spi,&ptr, portMAX_DELAY);
|
ret=spi_device_get_trans_result(spi,&ptr, portMAX_DELAY);
|
||||||
assert(ret==ESP_OK);
|
TEST_ASSERT(ret==ESP_OK);
|
||||||
assert(ptr = trans+x);
|
TEST_ASSERT(ptr = trans+x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_ASSERT(spi_bus_remove_device(spi) == ESP_OK);
|
||||||
|
TEST_ASSERT(spi_bus_free(HSPI_HOST) == ESP_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline void int_connect( uint32_t gpio, uint32_t sigo, uint32_t sigi )
|
||||||
|
{
|
||||||
|
gpio_matrix_out( gpio, sigo, false, false );
|
||||||
|
gpio_matrix_in( gpio, sigi, false );
|
||||||
|
}
|
||||||
|
|
||||||
|
//this part tests 3 DMA issues in master mode, full-duplex in IDF2.1
|
||||||
|
// 1. RX buffer not aligned (start and end)
|
||||||
|
// 2. not setting rx_buffer
|
||||||
|
// 3. setting rx_length != length
|
||||||
|
TEST_CASE("SPI Master DMA test: length, start, not aligned", "[spi]")
|
||||||
|
{
|
||||||
|
uint8_t tx_buf[320]={0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0xaa, 0xcc, 0xff, 0xee, 0x55, 0x77, 0x88, 0x43};
|
||||||
|
uint8_t rx_buf[320];
|
||||||
|
|
||||||
|
esp_err_t ret;
|
||||||
|
spi_device_handle_t spi;
|
||||||
|
spi_bus_config_t buscfg={
|
||||||
|
.miso_io_num=PIN_NUM_MISO,
|
||||||
|
.mosi_io_num=PIN_NUM_MOSI,
|
||||||
|
.sclk_io_num=PIN_NUM_CLK,
|
||||||
|
.quadwp_io_num=-1,
|
||||||
|
.quadhd_io_num=-1
|
||||||
|
};
|
||||||
|
spi_device_interface_config_t devcfg={
|
||||||
|
.clock_speed_hz=10*1000*1000, //Clock out at 10 MHz
|
||||||
|
.mode=0, //SPI mode 0
|
||||||
|
.spics_io_num=PIN_NUM_CS, //CS pin
|
||||||
|
.queue_size=7, //We want to be able to queue 7 transactions at a time
|
||||||
|
.pre_cb=NULL,
|
||||||
|
};
|
||||||
|
//Initialize the SPI bus
|
||||||
|
ret=spi_bus_initialize(HSPI_HOST, &buscfg, 1);
|
||||||
|
TEST_ASSERT(ret==ESP_OK);
|
||||||
|
//Attach the LCD to the SPI bus
|
||||||
|
ret=spi_bus_add_device(HSPI_HOST, &devcfg, &spi);
|
||||||
|
TEST_ASSERT(ret==ESP_OK);
|
||||||
|
|
||||||
|
//do internal connection
|
||||||
|
int_connect( PIN_NUM_MOSI, HSPID_OUT_IDX, HSPIQ_IN_IDX );
|
||||||
|
|
||||||
|
memset(rx_buf, 0x66, 320);
|
||||||
|
|
||||||
|
for ( int i = 0; i < 8; i ++ ) {
|
||||||
|
memset( rx_buf, 0x66, sizeof(rx_buf));
|
||||||
|
|
||||||
|
spi_transaction_t t = {};
|
||||||
|
t.length = 8*(i+1);
|
||||||
|
t.rxlength = 0;
|
||||||
|
t.tx_buffer = tx_buf+2*i;
|
||||||
|
t.rx_buffer = rx_buf + i;
|
||||||
|
|
||||||
|
if ( i == 1 ) {
|
||||||
|
//test set no start
|
||||||
|
t.rx_buffer = NULL;
|
||||||
|
} else if ( i == 2 ) {
|
||||||
|
//test rx length != tx_length
|
||||||
|
t.rxlength = t.length - 8;
|
||||||
|
}
|
||||||
|
spi_device_transmit( spi, &t );
|
||||||
|
|
||||||
|
for( int i = 0; i < 16; i ++ ) {
|
||||||
|
printf("%02X ", rx_buf[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
if ( i == 1 ) {
|
||||||
|
// no rx, skip check
|
||||||
|
} else if ( i == 2 ) {
|
||||||
|
//test rx length = tx length-1
|
||||||
|
TEST_ASSERT( memcmp(t.tx_buffer, t.rx_buffer, t.length/8-1)==0 );
|
||||||
|
} else {
|
||||||
|
//normal check
|
||||||
|
TEST_ASSERT( memcmp(t.tx_buffer, t.rx_buffer, t.length/8)==0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_ASSERT(spi_bus_remove_device(spi) == ESP_OK);
|
||||||
|
TEST_ASSERT(spi_bus_free(HSPI_HOST) == ESP_OK);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue