Skip to content

Commit

Permalink
feat(spi_master): p4 enable test and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
wanckl committed Oct 8, 2023
1 parent 00fcdce commit eb75aa4
Show file tree
Hide file tree
Showing 20 changed files with 128 additions and 181 deletions.
11 changes: 11 additions & 0 deletions components/driver/test_apps/.build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,21 @@ components/driver/test_apps/spi/master:
components/driver/test_apps/spi/param:
disable:
- if: SOC_GPSPI_SUPPORTED != 1
- if: IDF_TARGET in ["esp32p4"]
temporary: true
reason: target(s) is not supported yet # TODO: IDF-7503

components/driver/test_apps/spi/slave:
disable:
- if: SOC_GPSPI_SUPPORTED != 1
- if: IDF_TARGET in ["esp32p4"]
temporary: true
reason: target(s) is not supported yet # TODO: IDF-7503 slave support

components/driver/test_apps/spi/slave_hd:
disable:
- if: SOC_GPSPI_SUPPORTED != 1
- if: SOC_SPI_SUPPORT_SLAVE_HD_VER2 != 1

components/driver/test_apps/temperature_sensor:
disable:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
#define ESP_SPI_SLAVE_TV (12.5*3.5)
#define WIRE_DELAY 12.5

#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4
#define SLAVE_IOMUX_PIN_MISO -1
#define SLAVE_IOMUX_PIN_MOSI -1
#define SLAVE_IOMUX_PIN_SCLK -1
Expand Down
4 changes: 2 additions & 2 deletions components/driver/test_apps/spi/master/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- |
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
12 changes: 2 additions & 10 deletions components/driver/test_apps/spi/master/main/test_app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,15 @@
// iterator to load partition tables in `test spi bus lock, with flash` will lead memory not free
#define TEST_MEMORY_LEAK_THRESHOLD (350)

static size_t before_free_8bit;
static size_t before_free_32bit;

void setUp(void)
{
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
unity_utils_record_free_mem();
}

void tearDown(void)
{
esp_reent_cleanup(); //clean up some of the newlib's lazy allocations
size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
printf("\n");
unity_utils_check_leak(before_free_8bit, after_free_8bit, "8BIT", TEST_MEMORY_LEAK_THRESHOLD);
unity_utils_check_leak(before_free_32bit, after_free_32bit, "32BIT", TEST_MEMORY_LEAK_THRESHOLD);
unity_utils_evaluate_leaks_direct(TEST_MEMORY_LEAK_THRESHOLD);
}

void app_main(void)
Expand Down
30 changes: 16 additions & 14 deletions components/driver/test_apps/spi/master/main/test_spi_master.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -287,8 +287,8 @@ TEST_CASE("SPI Master test", "[spi]")
success &= spi_test(handle, 4096 - 2); //multiple descs, edge case 1
success &= spi_test(handle, 4096 - 1); //multiple descs, edge case 2
success &= spi_test(handle, 4096 * 3); //multiple descs

master_free_device_bus(handle);
TEST_ASSERT(success);

printf("Testing bus at 80KHz, non-DMA\n");
handle = setup_spi_bus_loopback(80000, false);
Expand All @@ -299,19 +299,18 @@ TEST_CASE("SPI Master test", "[spi]")
success &= spi_test(handle, 47); //small, unaligned
success &= spi_test(handle, 63); //small
success &= spi_test(handle, 64); //small, unaligned

master_free_device_bus(handle);
TEST_ASSERT(success);

printf("Testing bus at 26MHz\n");
printf("Testing bus at 20MHz\n");
handle = setup_spi_bus_loopback(20000000, true);

success &= spi_test(handle, 128); //DMA, aligned
success &= spi_test(handle, 4096 * 3); //DMA, multiple descs
master_free_device_bus(handle);
TEST_ASSERT(success);

printf("Testing bus at 900KHz\n");
handle = setup_spi_bus_loopback(9000000, true);

success &= spi_test(handle, 128); //DMA, aligned
success &= spi_test(handle, 4096 * 3); //DMA, multiple descs
master_free_device_bus(handle);
Expand Down Expand Up @@ -790,11 +789,8 @@ TEST_CASE("SPI Master DMA test: length, start, not aligned", "[spi]")
//connect MOSI to two devices breaks the output, fix it.
spitest_gpio_output_sel(buscfg.mosi_io_num, FUNC_GPIO, spi_periph_signal[TEST_SPI_HOST].spid_out);

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;
Expand Down Expand Up @@ -881,12 +877,12 @@ void test_cmd_addr(spi_slave_task_context_t *slave_context, bool lsb_first)
vTaskDelay(50);
//prepare master tx data
int cmd_bits = (i + 1) * 2;
int addr_bits =
int addr_bits = 0;
#ifdef CONFIG_IDF_TARGET_ESP32
56 - 8 * i;
addr_bits = 56 - 8 * i;
#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
//ESP32S2 only supportes up to 32 bits address
28 - 4 * i;
addr_bits = 28 - 4 * i;
#endif
int round_up = (cmd_bits + addr_bits + 7) / 8 * 8;
addr_bits = round_up - cmd_bits;
Expand Down Expand Up @@ -1073,6 +1069,7 @@ TEST_CASE("SPI master variable dummy test", "[spi]")
master_free_device_bus(spi);
}

#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32P4) //IDF-7503 slave support
/**
* This test is to check when the first transaction of the HD master is to send data without receiving data via DMA,
* then if the master could receive data correctly.
Expand Down Expand Up @@ -1161,8 +1158,10 @@ TEST_CASE("SPI master hd dma TX without RX test", "[spi]")
spi_slave_free(TEST_SLAVE_HOST);
master_free_device_bus(spi);
}
#endif
#endif //#if (TEST_SPI_PERIPH_NUM >= 2)

#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32P4) //IDF-7503 slave support
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32) //TODO: IDF-3494
#define FD_TEST_BUF_SIZE 32
#define TEST_NUM 4
Expand Down Expand Up @@ -1338,6 +1337,7 @@ static void fd_slave(void)

TEST_CASE_MULTIPLE_DEVICES("SPI Master: FD, DMA, Master Single Direction Test", "[spi_ms][test_env=generic_multi_device]", fd_master, fd_slave);
#endif //#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32) //TODO: IDF-3494
#endif //p4 slave support


//NOTE: Explained in IDF-1445 | MR !14996
Expand Down Expand Up @@ -1491,6 +1491,7 @@ TEST_CASE("spi_speed", "[spi]")
#endif // CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE
#endif // !(CONFIG_SPIRAM) || (CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL >= 16384)

#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32P4) //IDF-7503 slave support
//****************************************spi master add device test************************************//
//add dummy devices first
#if CONFIG_IDF_TARGET_ESP32
Expand Down Expand Up @@ -1601,7 +1602,7 @@ void test_add_device_slave(void)
}

TEST_CASE_MULTIPLE_DEVICES("SPI_Master:Test multiple devices", "[spi_ms]", test_add_device_master, test_add_device_slave);

#endif //p4 slave support

#if (SOC_CPU_CORES_NUM > 1) && (!CONFIG_FREERTOS_UNICORE)

Expand Down Expand Up @@ -1661,8 +1662,8 @@ TEST_CASE("test_master_isr_pin_to_core","[spi]")
}
#endif

#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32P4) //IDF-7503 slave support
#if CONFIG_SPI_MASTER_IN_IRAM

#define TEST_MASTER_IRAM_TRANS_LEN 120
static IRAM_ATTR void test_master_iram_post_trans_cbk(spi_transaction_t *trans)
{
Expand Down Expand Up @@ -1767,3 +1768,4 @@ static void test_iram_slave_normal(void)

TEST_CASE_MULTIPLE_DEVICES("SPI_Master:IRAM_safe", "[spi_ms]", test_master_iram, test_iram_slave_normal);
#endif
#endif //p4 slave support
7 changes: 5 additions & 2 deletions components/driver/test_apps/spi/master/main/test_spi_sio.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -37,6 +37,8 @@
********************************************************************************/
#if CONFIG_IDF_TARGET_ESP32
#define MASTER_DIN_SIGNAL HSPID_IN_IDX
#elif CONFIG_IDF_TARGET_ESP32P4
#define MASTER_DIN_SIGNAL SPI2_D_PAD_IN_IDX
#else
#define MASTER_DIN_SIGNAL FSPID_IN_IDX
#endif
Expand Down Expand Up @@ -142,7 +144,7 @@ TEST_CASE("SPI Single Board Test SIO", "[spi]")
}
#endif //#if (TEST_SPI_PERIPH_NUM >= 2)


#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32P4) //IDF-7503 slave support
/********************************************************************************
* Test SIO Master
* SIO Slave is not suported, and one unit test is limited to one feature, so,,,
Expand Down Expand Up @@ -326,3 +328,4 @@ void test_slave_run(void)
}

TEST_CASE_MULTIPLE_DEVICES("SPI_Master:Test_SIO_Mode_Multi_Board", "[spi_ms][test_env=generic_multi_device]", test_master_run, test_slave_run);
#endif //p4 slave support
4 changes: 2 additions & 2 deletions components/driver/test_apps/spi/slave_hd/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 |
| ----------------- | -------- | -------- | -------- | -------- | -------- | -------- |
12 changes: 10 additions & 2 deletions components/driver/test_apps/spi/slave_hd/pytest_spi_slave_hd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@


# If `test_env` is define, should not run on generic runner
@pytest.mark.supported_targets
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.esp32c2
@pytest.mark.esp32c3
@pytest.mark.esp32c6
@pytest.mark.esp32h2
@pytest.mark.generic
def test_slave_hd_single_dev(case_tester) -> None: # type: ignore
Expand All @@ -16,7 +20,11 @@ def test_slave_hd_single_dev(case_tester) -> None: # type: ignore


# if `test_env` not defined, will run on `generic_multi_device` by default
@pytest.mark.supported_targets
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.esp32c2
@pytest.mark.esp32c3
@pytest.mark.esp32c6
@pytest.mark.esp32h2
@pytest.mark.generic_multi_device
@pytest.mark.parametrize('count', [2,], indirect=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- |
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -127,7 +127,11 @@ void static test_isr(void*arg)
TEST_CASE("Allocate previously freed interrupt, with different flags", "[intr_alloc]")
{
intr_handle_t intr;
#if CONFIG_IDF_TARGET_ESP32P4
int test_intr_source = ETS_GPIO_INTR0_SOURCE;
#else
int test_intr_source = ETS_GPIO_INTR_SOURCE;
#endif
int isr_flags = ESP_INTR_FLAG_LEVEL2;

TEST_ESP_OK(esp_intr_alloc(test_intr_source, isr_flags, test_isr, NULL, &intr));
Expand Down Expand Up @@ -179,7 +183,15 @@ TEST_CASE("allocate 2 handlers for a same source and remove the later one", "[in
intr_handle_t handle1, handle2;

// enable SPI2
#if CONFIG_IDF_TARGET_ESP32P4 //deprecate clk_gate_ll start from p4, others in TODO: IDF-8159
PERIPH_RCC_ATOMIC() {
spi_ll_enable_bus_clock(1, true);
spi_ll_reset_register(1);
spi_ll_enable_clock(1, true);
}
#else
periph_module_enable(spi_periph_signal[1].module);
#endif

esp_err_t r;
r = esp_intr_alloc(spi_periph_signal[1].irq, ESP_INTR_FLAG_SHARED, int_handler1, &ctx, &handle1);
Expand Down
4 changes: 2 additions & 2 deletions components/esp_lcd/test_apps/spi_lcd/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- |
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |

This test app is used to test LCDs with SPI interface.
11 changes: 5 additions & 6 deletions components/esp_lcd/test_apps/spi_lcd/main/test_spi_lcd_panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "esp_lcd_panel_vendor.h"
#include "esp_lcd_panel_ops.h"
#include "esp_lcd_panel_commands.h"
#include "esp_random.h"
#include "soc/soc_caps.h"
#include "test_spi_board.h"

Expand Down Expand Up @@ -92,9 +91,9 @@ static void lcd_panel_test(esp_lcd_panel_io_handle_t io_handle, esp_lcd_panel_ha
gpio_set_level(TEST_LCD_BK_LIGHT_GPIO, 1);

for (int i = 0; i < 200; i++) {
uint8_t color_byte = esp_random() & 0xFF;
int x_start = esp_random() % (TEST_LCD_H_RES - 200);
int y_start = esp_random() % (TEST_LCD_V_RES - 200);
uint8_t color_byte = rand() & 0xFF;
int x_start = rand() % (TEST_LCD_H_RES - 200);
int y_start = rand() % (TEST_LCD_V_RES - 200);
memset(img, color_byte, TEST_IMG_SIZE);
esp_lcd_panel_draw_bitmap(panel_handle, x_start, y_start, x_start + 200, y_start + 200, img);
}
Expand Down Expand Up @@ -202,7 +201,7 @@ TEST_CASE("spi_lcd_send_colors_to_fixed_region", "[lcd]")
size_t color_size = (x_end - x_start) * (y_end - y_start) * 2;
void *color_data = malloc(color_size);
TEST_ASSERT_NOT_NULL(color_data);
uint8_t color_byte = esp_random() & 0xFF;
uint8_t color_byte = rand() & 0xFF;
memset(color_data, color_byte, color_size);

esp_lcd_panel_io_handle_t io_handle = NULL;
Expand Down Expand Up @@ -249,7 +248,7 @@ TEST_CASE("spi_lcd_send_colors_to_fixed_region", "[lcd]")
}
vTaskDelay(pdMS_TO_TICKS(1000));
// change to another color
color_byte = esp_random() & 0xFF;
color_byte = rand() & 0xFF;
memset(color_data, color_byte, color_size);
for (int i = 0; i < steps; i++) {
TEST_ESP_OK(esp_lcd_panel_io_tx_color(io_handle, -1, color_data + i * color_size_per_step, color_size_per_step));
Expand Down
15 changes: 10 additions & 5 deletions examples/peripherals/.build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,12 @@ examples/peripherals/spi_master/lcd:
disable:
- if: SOC_GPSPI_SUPPORTED != 1

examples/peripherals/spi_slave/receiver:
disable:
- if: SOC_GPSPI_SUPPORTED != 1

examples/peripherals/spi_slave/sender:
examples/peripherals/spi_slave:
disable:
- if: SOC_GPSPI_SUPPORTED != 1
- if: IDF_TARGET in ["esp32p4"]
temporary: true
reason: target(s) is not supported yet # TODO: IDF-7503 slave support

examples/peripherals/spi_slave_hd/append_mode/master:
disable:
Expand All @@ -255,10 +254,16 @@ examples/peripherals/spi_slave_hd/append_mode/slave:
examples/peripherals/spi_slave_hd/segment_mode/seg_master:
disable:
- if: SOC_GPSPI_SUPPORTED != 1
- if: IDF_TARGET in ["esp32p4"]
temporary: true
reason: target(s) is not supported yet # TODO: IDF-7505 slave hd support

examples/peripherals/spi_slave_hd/segment_mode/seg_slave:
disable:
- if: IDF_TARGET == "esp32" or SOC_GPSPI_SUPPORTED != 1
- if: IDF_TARGET in ["esp32p4"]
temporary: true
reason: target(s) is not supported yet # TODO: IDF-7505 slave hd support

examples/peripherals/temperature_sensor/temp_sensor:
disable:
Expand Down
4 changes: 2 additions & 2 deletions examples/peripherals/lcd/spi_lcd_touch/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- |
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |

# SPI LCD and Touch Panel Example

Expand Down
4 changes: 2 additions & 2 deletions examples/peripherals/lcd/tjpgd/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- |
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |

## LCD tjpgd example

Expand Down
4 changes: 2 additions & 2 deletions examples/peripherals/spi_master/hd_eeprom/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- |
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |

## SPI master half duplex EEPROM example

Expand Down
Loading

0 comments on commit eb75aa4

Please sign in to comment.