Skip to content

Commit 62f9245

Browse files
committed
Merge branch 'test/spi_performance' into 'master'
test(spi_master): add performance display for spi master. See merge request idf/esp-idf!1923
2 parents 16de6bf + a151767 commit 62f9245

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

components/driver/test/test_spi_master.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,3 +728,76 @@ TEST_CASE("SPI master variable cmd & addr test","[spi]")
728728

729729
ESP_LOGI(MASTER_TAG, "test passed.");
730730
}
731+
732+
#define RECORD_TIME_PREPARE() uint32_t __t1, __t2
733+
#define RECORD_TIME_START() do {__t1 = xthal_get_ccount();}while(0)
734+
#define RECORD_TIME_END(p_time) do{__t2 = xthal_get_ccount(); *p_time = (__t2-__t1)/240;}while(0)
735+
736+
TEST_CASE("spi_speed","[spi]")
737+
{
738+
RECORD_TIME_PREPARE();
739+
uint32_t t_no_dma, t_dma;
740+
esp_err_t ret;
741+
spi_device_handle_t spi;
742+
spi_bus_config_t buscfg={
743+
.miso_io_num=PIN_NUM_MISO,
744+
.mosi_io_num=PIN_NUM_MOSI,
745+
.sclk_io_num=PIN_NUM_CLK,
746+
.quadwp_io_num=-1,
747+
.quadhd_io_num=-1
748+
};
749+
spi_device_interface_config_t devcfg={
750+
.clock_speed_hz=10*1000*1000, //currently only up to 4MHz for internel connect
751+
.mode=0, //SPI mode 0
752+
.spics_io_num=PIN_NUM_CS, //CS pin
753+
.queue_size=16, //We want to be able to queue 7 transactions at a time
754+
.pre_cb=NULL,
755+
.cs_ena_pretrans = 0,
756+
};
757+
//Initialize the SPI bus
758+
ret=spi_bus_initialize(HSPI_HOST, &buscfg, 1);
759+
TEST_ASSERT(ret==ESP_OK);
760+
//Attach the LCD to the SPI bus
761+
ret=spi_bus_add_device(HSPI_HOST, &devcfg, &spi);
762+
TEST_ASSERT(ret==ESP_OK);
763+
764+
spi_transaction_t trans = {
765+
.length = 1*8,
766+
.flags = SPI_TRANS_USE_TXDATA,
767+
};
768+
spi_device_transmit(spi, &trans);
769+
770+
//only record the second time
771+
RECORD_TIME_START();
772+
spi_device_transmit(spi, &trans);
773+
RECORD_TIME_END(&t_dma);
774+
775+
TEST_PERFORMANCE_LESS_THAN( SPI_PER_TRANS_NO_POLLING, "%d us", t_dma );
776+
777+
TEST_ESP_OK( spi_bus_remove_device(spi) );
778+
TEST_ESP_OK( spi_bus_free(HSPI_HOST) );
779+
780+
ret=spi_bus_initialize(HSPI_HOST, &buscfg, 0);
781+
TEST_ASSERT(ret==ESP_OK);
782+
//Attach the LCD to the SPI bus
783+
ret=spi_bus_add_device(HSPI_HOST, &devcfg, &spi);
784+
TEST_ASSERT(ret==ESP_OK);
785+
786+
trans = (spi_transaction_t){
787+
.length = 1*8,
788+
.flags = SPI_TRANS_USE_TXDATA,
789+
};
790+
spi_device_transmit(spi, &trans);
791+
792+
//only record the second time
793+
RECORD_TIME_START();
794+
spi_device_transmit(spi, &trans);
795+
RECORD_TIME_END(&t_no_dma);
796+
797+
TEST_PERFORMANCE_LESS_THAN( SPI_PER_TRANS_NO_POLLING_NO_DMA, "%d us", t_no_dma );
798+
799+
TEST_ESP_OK( spi_bus_remove_device(spi) );
800+
TEST_ESP_OK( spi_bus_free(HSPI_HOST) );
801+
802+
803+
}

components/idf_test/include/idf_performance.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@
1414
#define IDF_PERFORMANCE_MAX_FREERTOS_SPINLOCK_CYCLES_PER_OP_PSRAM 270
1515
#define IDF_PERFORMANCE_MAX_FREERTOS_SPINLOCK_CYCLES_PER_OP_UNICORE 130
1616
#define IDF_PERFORMANCE_MAX_ESP_TIMER_GET_TIME_PER_CALL 1000
17+
#define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING 30
18+
#define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING_NO_DMA 25
19+
20+

0 commit comments

Comments
 (0)