mirror of
https://github.com/espressif/esp-idf
synced 2025-03-10 01:29:21 -04:00
test(i2c): Enhance i2c test stability
This commit is contained in:
parent
3f6d1f6496
commit
78af773348
@ -31,13 +31,10 @@ components/driver/test_apps/legacy_adc_driver:
|
|||||||
components/driver/test_apps/legacy_i2c_driver:
|
components/driver/test_apps/legacy_i2c_driver:
|
||||||
disable:
|
disable:
|
||||||
- if: SOC_I2C_SUPPORTED != 1
|
- if: SOC_I2C_SUPPORTED != 1
|
||||||
depends_filepatterns:
|
disable_test:
|
||||||
- components/driver/i2c/**
|
- if: IDF_TARGET != "none"
|
||||||
# Following dependency is needed because they might increase lazy installed memory
|
temporary: false
|
||||||
# that can cause sleep retention memory leak check failed.
|
reason: disable target test for legacy i2c driver.
|
||||||
- components/ieee802154/**
|
|
||||||
- components/esp_coex/**
|
|
||||||
- components/esp_phy/**
|
|
||||||
|
|
||||||
components/driver/test_apps/legacy_mcpwm_driver:
|
components/driver/test_apps/legacy_mcpwm_driver:
|
||||||
disable:
|
disable:
|
||||||
|
@ -2,13 +2,6 @@ set(srcs "test_app_main.c"
|
|||||||
"test_i2c.c"
|
"test_i2c.c"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Only build this file with `CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP` and `CONFIG_IEEE802154_ENABLED` enabled
|
|
||||||
# Enable `CONFIG_IEEE802154_ENABLED` is for modem domain really power down.
|
|
||||||
# This reliable can be removed if the sleep retention got finished.
|
|
||||||
if(CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP AND CONFIG_IEEE802154_ENABLED)
|
|
||||||
list(APPEND srcs "test_legacy_i2c_sleep_retention.c")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
idf_component_register(SRCS ${srcs}
|
idf_component_register(SRCS ${srcs}
|
||||||
PRIV_REQUIRES unity test_utils driver ieee802154
|
PRIV_REQUIRES unity test_utils driver
|
||||||
WHOLE_ARCHIVE)
|
WHOLE_ARCHIVE)
|
||||||
|
@ -1,193 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "unity.h"
|
|
||||||
#include "unity_config.h"
|
|
||||||
#include "driver/i2c.h"
|
|
||||||
#include "esp_attr.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include "esp_system.h"
|
|
||||||
#include "hal/i2c_types.h"
|
|
||||||
#include "test_utils.h"
|
|
||||||
#include "esp_sleep.h"
|
|
||||||
#include "esp_private/sleep_cpu.h"
|
|
||||||
#include "esp_ieee802154.h"
|
|
||||||
#include "esp_pm.h"
|
|
||||||
|
|
||||||
#define DATA_LENGTH 100 /*!<Data buffer length for test buffer*/
|
|
||||||
|
|
||||||
#define I2C_SLAVE_SCL_IO 4 /*!<gpio number for i2c slave clock */
|
|
||||||
#define I2C_SLAVE_SDA_IO 5 /*!<gpio number for i2c slave data */
|
|
||||||
|
|
||||||
#define I2C_SLAVE_NUM I2C_NUM_0 /*!<I2C port number for slave dev */
|
|
||||||
#define I2C_SLAVE_TX_BUF_LEN (2*DATA_LENGTH) /*!<I2C slave tx buffer size */
|
|
||||||
#define I2C_SLAVE_RX_BUF_LEN (2*DATA_LENGTH) /*!<I2C slave rx buffer size */
|
|
||||||
|
|
||||||
#define I2C_MASTER_SCL_IO 4 /*!<gpio number for i2c master clock */
|
|
||||||
#define I2C_MASTER_SDA_IO 5 /*!<gpio number for i2c master data */
|
|
||||||
|
|
||||||
#define I2C_MASTER_NUM I2C_NUM_0 /*!< I2C port number for master dev */
|
|
||||||
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master do not need buffer */
|
|
||||||
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master do not need buffer */
|
|
||||||
#define I2C_MASTER_FREQ_HZ 100000 /*!< I2C master clock frequency */
|
|
||||||
|
|
||||||
#define ESP_SLAVE_ADDR 0x28 /*!< ESP32 slave address, you can set any 7bit value */
|
|
||||||
#define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
|
|
||||||
#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
|
|
||||||
|
|
||||||
static esp_err_t i2c_master_write_slave(i2c_port_t i2c_num, uint8_t *data_wr, size_t size)
|
|
||||||
{
|
|
||||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
|
||||||
i2c_master_start(cmd);
|
|
||||||
TEST_ESP_OK(i2c_master_write_byte(cmd, (ESP_SLAVE_ADDR << 1) | WRITE_BIT, ACK_CHECK_EN));
|
|
||||||
TEST_ESP_OK(i2c_master_write(cmd, data_wr, size, ACK_CHECK_EN));
|
|
||||||
TEST_ESP_OK(i2c_master_stop(cmd));
|
|
||||||
esp_err_t ret = i2c_master_cmd_begin(i2c_num, cmd, 5000 / portTICK_PERIOD_MS);
|
|
||||||
i2c_cmd_link_delete(cmd);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static i2c_config_t i2c_master_init(void)
|
|
||||||
{
|
|
||||||
i2c_config_t conf_master = {
|
|
||||||
.mode = I2C_MODE_MASTER,
|
|
||||||
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
|
||||||
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
|
||||||
.master.clk_speed = I2C_MASTER_FREQ_HZ,
|
|
||||||
.sda_io_num = I2C_MASTER_SDA_IO,
|
|
||||||
.scl_io_num = I2C_MASTER_SCL_IO,
|
|
||||||
.clk_flags = 0,
|
|
||||||
};
|
|
||||||
return conf_master;
|
|
||||||
}
|
|
||||||
|
|
||||||
static i2c_config_t i2c_slave_init(void)
|
|
||||||
{
|
|
||||||
i2c_config_t conf_slave = {
|
|
||||||
.mode = I2C_MODE_SLAVE,
|
|
||||||
.sda_io_num = I2C_SLAVE_SDA_IO,
|
|
||||||
.scl_io_num = I2C_SLAVE_SCL_IO,
|
|
||||||
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
|
||||||
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
|
||||||
.slave.addr_10bit_en = 0,
|
|
||||||
.slave.slave_addr = ESP_SLAVE_ADDR,
|
|
||||||
};
|
|
||||||
return conf_slave;
|
|
||||||
}
|
|
||||||
|
|
||||||
// print the reading buffer
|
|
||||||
static void disp_buf(uint8_t *buf, int len)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
printf("%02x ", buf[i]);
|
|
||||||
if ((i + 1) % 16 == 0) {
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void i2c_master_write_sleep_test(void)
|
|
||||||
{
|
|
||||||
uint8_t *data_wr = (uint8_t *) malloc(DATA_LENGTH);
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i2c_config_t conf_master = i2c_master_init();
|
|
||||||
TEST_ESP_OK(i2c_param_config(I2C_MASTER_NUM, &conf_master));
|
|
||||||
|
|
||||||
TEST_ESP_OK(i2c_driver_install(I2C_MASTER_NUM, I2C_MODE_MASTER,
|
|
||||||
I2C_MASTER_RX_BUF_DISABLE,
|
|
||||||
I2C_MASTER_TX_BUF_DISABLE, 0));
|
|
||||||
unity_wait_for_signal("i2c slave init finish");
|
|
||||||
|
|
||||||
unity_send_signal("master write and sleep");
|
|
||||||
for (i = 0; i < DATA_LENGTH; i++) {
|
|
||||||
data_wr[i] = i;
|
|
||||||
}
|
|
||||||
i2c_master_write_slave(I2C_MASTER_NUM, data_wr, DATA_LENGTH);
|
|
||||||
disp_buf(data_wr, i + 1);
|
|
||||||
|
|
||||||
TEST_ESP_OK(esp_ieee802154_enable());
|
|
||||||
TEST_ESP_OK(sleep_cpu_configure(true));
|
|
||||||
TEST_ESP_OK(esp_sleep_enable_timer_wakeup(3 * 1000 * 1000));
|
|
||||||
TEST_ESP_OK(esp_light_sleep_start());
|
|
||||||
|
|
||||||
printf("Waked up!!\n");
|
|
||||||
unity_wait_for_signal("i2c slave receive once");
|
|
||||||
|
|
||||||
for (i = 0; i < DATA_LENGTH; i++) {
|
|
||||||
data_wr[i] = i;
|
|
||||||
}
|
|
||||||
i2c_master_write_slave(I2C_MASTER_NUM, data_wr, DATA_LENGTH);
|
|
||||||
disp_buf(data_wr, i + 1);
|
|
||||||
unity_send_signal("master write again");
|
|
||||||
|
|
||||||
free(data_wr);
|
|
||||||
unity_wait_for_signal("ready to delete");
|
|
||||||
TEST_ESP_OK(sleep_cpu_configure(false));
|
|
||||||
TEST_ESP_OK(esp_ieee802154_disable());
|
|
||||||
TEST_ESP_OK(i2c_driver_delete(I2C_MASTER_NUM));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void i2c_slave_read_sleep_test(void)
|
|
||||||
{
|
|
||||||
uint8_t *data_rd = (uint8_t *) malloc(DATA_LENGTH);
|
|
||||||
int size_rd = 0;
|
|
||||||
int len = 0;
|
|
||||||
|
|
||||||
i2c_config_t conf_slave = i2c_slave_init();
|
|
||||||
TEST_ESP_OK(i2c_param_config(I2C_SLAVE_NUM, &conf_slave));
|
|
||||||
TEST_ESP_OK(i2c_driver_install(I2C_SLAVE_NUM, I2C_MODE_SLAVE,
|
|
||||||
I2C_SLAVE_RX_BUF_LEN,
|
|
||||||
I2C_SLAVE_TX_BUF_LEN, 0));
|
|
||||||
unity_send_signal("i2c slave init finish");
|
|
||||||
|
|
||||||
unity_wait_for_signal("master write and sleep");
|
|
||||||
while (1) {
|
|
||||||
len = i2c_slave_read_buffer(I2C_SLAVE_NUM, data_rd + size_rd, DATA_LENGTH, 10000 / portTICK_PERIOD_MS);
|
|
||||||
if (len == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
size_rd += len;
|
|
||||||
}
|
|
||||||
disp_buf(data_rd, size_rd);
|
|
||||||
for (int i = 0; i < size_rd; i++) {
|
|
||||||
TEST_ASSERT(data_rd[i] == i);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_ESP_OK(esp_ieee802154_enable());
|
|
||||||
TEST_ESP_OK(sleep_cpu_configure(true));
|
|
||||||
TEST_ESP_OK(esp_sleep_enable_timer_wakeup(1 * 1000 * 1000));
|
|
||||||
TEST_ESP_OK(esp_light_sleep_start());
|
|
||||||
|
|
||||||
unity_send_signal("i2c slave receive once");
|
|
||||||
unity_wait_for_signal("master write again");
|
|
||||||
|
|
||||||
memset(data_rd, 0, DATA_LENGTH);
|
|
||||||
size_rd = 0;
|
|
||||||
while (1) {
|
|
||||||
len = i2c_slave_read_buffer(I2C_SLAVE_NUM, data_rd + size_rd, DATA_LENGTH, 10000 / portTICK_PERIOD_MS);
|
|
||||||
if (len == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
size_rd += len;
|
|
||||||
}
|
|
||||||
disp_buf(data_rd, size_rd);
|
|
||||||
for (int i = 0; i < size_rd; i++) {
|
|
||||||
TEST_ASSERT(data_rd[i] == i);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(data_rd);
|
|
||||||
unity_send_signal("ready to delete");
|
|
||||||
TEST_ESP_OK(sleep_cpu_configure(false));
|
|
||||||
TEST_ESP_OK(esp_ieee802154_disable());
|
|
||||||
TEST_ESP_OK(i2c_driver_delete(I2C_SLAVE_NUM));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE_MULTIPLE_DEVICES("I2C legacy sleep retention test", "[i2c][test_env=generic_multi_device][timeout=250]", i2c_master_write_sleep_test, i2c_slave_read_sleep_test);
|
|
@ -1,56 +0,0 @@
|
|||||||
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
|
||||||
# SPDX-License-Identifier: CC0-1.0
|
|
||||||
import pytest
|
|
||||||
from pytest_embedded import Dut
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.supported_targets
|
|
||||||
@pytest.mark.generic
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
'config',
|
|
||||||
[
|
|
||||||
'release',
|
|
||||||
'iram_safe',
|
|
||||||
],
|
|
||||||
indirect=True,
|
|
||||||
)
|
|
||||||
def test_i2c_legacy(dut: Dut) -> None:
|
|
||||||
dut.run_all_single_board_cases()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.esp32
|
|
||||||
@pytest.mark.esp32c3
|
|
||||||
@pytest.mark.esp32c6
|
|
||||||
@pytest.mark.esp32c5
|
|
||||||
@pytest.mark.esp32h2
|
|
||||||
@pytest.mark.esp32p4
|
|
||||||
@pytest.mark.esp32s2
|
|
||||||
@pytest.mark.esp32s3
|
|
||||||
@pytest.mark.generic_multi_device
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
'count, config',
|
|
||||||
[
|
|
||||||
(2, 'defaults',),
|
|
||||||
],
|
|
||||||
indirect=True
|
|
||||||
)
|
|
||||||
def test_i2c_multi_dev_legacy(case_tester) -> None: # type: ignore
|
|
||||||
for case in case_tester.test_menu:
|
|
||||||
if case.attributes.get('test_env', 'generic_multi_device') == 'generic_multi_device':
|
|
||||||
case_tester.run_multi_dev_case(case=case, reset=True, timeout=120)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.esp32c6
|
|
||||||
@pytest.mark.esp32h2
|
|
||||||
@pytest.mark.generic_multi_device
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
'count, config',
|
|
||||||
[
|
|
||||||
(2, 'sleep_retention',),
|
|
||||||
],
|
|
||||||
indirect=True
|
|
||||||
)
|
|
||||||
def test_i2c_sleep_retention_legacy(case_tester) -> None: # type: ignore
|
|
||||||
for case in case_tester.test_menu:
|
|
||||||
if case.attributes.get('test_env', 'generic_multi_device') == 'generic_multi_device':
|
|
||||||
case_tester.run_multi_dev_case(case=case, reset=True, timeout=250)
|
|
@ -1,5 +0,0 @@
|
|||||||
CONFIG_PM_ENABLE=y
|
|
||||||
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
|
|
||||||
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
|
|
||||||
CONFIG_IEEE802154_ENABLED=y
|
|
||||||
CONFIG_IEEE802154_SLEEP_ENABLE=y
|
|
@ -61,6 +61,8 @@ static void i2c_master_write_test_10bit(void)
|
|||||||
i2c_master_dev_handle_t dev_handle;
|
i2c_master_dev_handle_t dev_handle;
|
||||||
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
||||||
|
|
||||||
|
unity_send_signal("i2c master init first");
|
||||||
|
|
||||||
unity_wait_for_signal("i2c slave init finish");
|
unity_wait_for_signal("i2c slave init finish");
|
||||||
|
|
||||||
unity_send_signal("master write");
|
unity_send_signal("master write");
|
||||||
@ -78,6 +80,7 @@ static void i2c_master_write_test_10bit(void)
|
|||||||
|
|
||||||
static void i2c_slave_read_test_10bit(void)
|
static void i2c_slave_read_test_10bit(void)
|
||||||
{
|
{
|
||||||
|
unity_wait_for_signal("i2c master init first");
|
||||||
uint8_t data_rd[DATA_LENGTH] = {0};
|
uint8_t data_rd[DATA_LENGTH] = {0};
|
||||||
|
|
||||||
i2c_slave_config_t i2c_slv_config = {
|
i2c_slave_config_t i2c_slv_config = {
|
||||||
|
@ -61,6 +61,8 @@ static void i2c_master_write_test_broadcast(void)
|
|||||||
i2c_master_dev_handle_t dev_handle;
|
i2c_master_dev_handle_t dev_handle;
|
||||||
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
||||||
|
|
||||||
|
unity_send_signal("i2c master init first");
|
||||||
|
|
||||||
unity_wait_for_signal("i2c slave init finish");
|
unity_wait_for_signal("i2c slave init finish");
|
||||||
|
|
||||||
unity_send_signal("master write");
|
unity_send_signal("master write");
|
||||||
@ -78,6 +80,7 @@ static void i2c_master_write_test_broadcast(void)
|
|||||||
|
|
||||||
static void i2c_slave_read_test_broadcast(void)
|
static void i2c_slave_read_test_broadcast(void)
|
||||||
{
|
{
|
||||||
|
unity_wait_for_signal("i2c master init first");
|
||||||
uint8_t data_rd[DATA_LENGTH] = {0};
|
uint8_t data_rd[DATA_LENGTH] = {0};
|
||||||
|
|
||||||
i2c_slave_config_t i2c_slv_config = {
|
i2c_slave_config_t i2c_slv_config = {
|
||||||
|
@ -163,6 +163,8 @@ static void i2c_master_write_test_large_write_small_read(void)
|
|||||||
i2c_master_dev_handle_t dev_handle;
|
i2c_master_dev_handle_t dev_handle;
|
||||||
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
||||||
|
|
||||||
|
unity_send_signal("i2c master init first");
|
||||||
|
|
||||||
unity_wait_for_signal("i2c slave init finish");
|
unity_wait_for_signal("i2c slave init finish");
|
||||||
|
|
||||||
unity_send_signal("master write");
|
unity_send_signal("master write");
|
||||||
@ -180,6 +182,7 @@ static void i2c_master_write_test_large_write_small_read(void)
|
|||||||
|
|
||||||
static void i2c_slave_read_test_large_write_small_read(void)
|
static void i2c_slave_read_test_large_write_small_read(void)
|
||||||
{
|
{
|
||||||
|
unity_wait_for_signal("i2c master init first");
|
||||||
uint8_t data_rd[7] = {0};
|
uint8_t data_rd[7] = {0};
|
||||||
|
|
||||||
i2c_slave_config_t i2c_slv_config = {
|
i2c_slave_config_t i2c_slv_config = {
|
||||||
@ -321,6 +324,8 @@ static void i2c_master_write_read_test(void)
|
|||||||
i2c_master_dev_handle_t dev_handle;
|
i2c_master_dev_handle_t dev_handle;
|
||||||
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
||||||
|
|
||||||
|
unity_send_signal("i2c master init first");
|
||||||
|
|
||||||
unity_wait_for_signal("i2c slave init finish");
|
unity_wait_for_signal("i2c slave init finish");
|
||||||
|
|
||||||
printf("master read buffer\n");
|
printf("master read buffer\n");
|
||||||
@ -351,6 +356,7 @@ static void i2c_master_write_read_test(void)
|
|||||||
|
|
||||||
static void i2c_slave_read_write_test(void)
|
static void i2c_slave_read_write_test(void)
|
||||||
{
|
{
|
||||||
|
unity_wait_for_signal("i2c master init first");
|
||||||
uint8_t data_rd[DATA_LENGTH] = {0};
|
uint8_t data_rd[DATA_LENGTH] = {0};
|
||||||
uint8_t data_wr[DATA_LENGTH] = {0};
|
uint8_t data_wr[DATA_LENGTH] = {0};
|
||||||
|
|
||||||
@ -426,6 +432,8 @@ static void i2c_master_repeat_write(void)
|
|||||||
i2c_master_dev_handle_t dev_handle;
|
i2c_master_dev_handle_t dev_handle;
|
||||||
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
||||||
|
|
||||||
|
unity_send_signal("i2c master init first");
|
||||||
|
|
||||||
unity_wait_for_signal("i2c slave init finish");
|
unity_wait_for_signal("i2c slave init finish");
|
||||||
|
|
||||||
for (int j = 0; j < times; j++) {
|
for (int j = 0; j < times; j++) {
|
||||||
@ -442,6 +450,7 @@ static void i2c_master_repeat_write(void)
|
|||||||
|
|
||||||
static void i2c_slave_repeat_read(void)
|
static void i2c_slave_repeat_read(void)
|
||||||
{
|
{
|
||||||
|
unity_wait_for_signal("i2c master init first");
|
||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
int times = 3;
|
int times = 3;
|
||||||
uint8_t data_rd[DATA_LENGTH * 3] = {0};
|
uint8_t data_rd[DATA_LENGTH * 3] = {0};
|
||||||
@ -654,6 +663,8 @@ static void i2c_master_write_multi_buffer_test(void)
|
|||||||
i2c_master_dev_handle_t dev_handle;
|
i2c_master_dev_handle_t dev_handle;
|
||||||
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
||||||
|
|
||||||
|
unity_send_signal("i2c master init first");
|
||||||
|
|
||||||
unity_wait_for_signal("i2c slave init finish");
|
unity_wait_for_signal("i2c slave init finish");
|
||||||
|
|
||||||
unity_send_signal("master write");
|
unity_send_signal("master write");
|
||||||
@ -670,6 +681,7 @@ static void i2c_master_write_multi_buffer_test(void)
|
|||||||
|
|
||||||
static void i2c_slave_read_multi_buffer_test(void)
|
static void i2c_slave_read_multi_buffer_test(void)
|
||||||
{
|
{
|
||||||
|
unity_wait_for_signal("i2c master init first");
|
||||||
uint8_t data_rd[DATA_LENGTH * 3] = {0};
|
uint8_t data_rd[DATA_LENGTH * 3] = {0};
|
||||||
|
|
||||||
i2c_slave_config_t i2c_slv_config = {
|
i2c_slave_config_t i2c_slv_config = {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -63,6 +63,8 @@ static void i2c_master_write_to_ram_test(void)
|
|||||||
i2c_master_dev_handle_t dev_handle;
|
i2c_master_dev_handle_t dev_handle;
|
||||||
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
||||||
|
|
||||||
|
unity_send_signal("i2c master init first");
|
||||||
|
|
||||||
unity_wait_for_signal("i2c slave init finish");
|
unity_wait_for_signal("i2c slave init finish");
|
||||||
|
|
||||||
unity_send_signal("master write");
|
unity_send_signal("master write");
|
||||||
@ -81,6 +83,7 @@ static void i2c_master_write_to_ram_test(void)
|
|||||||
|
|
||||||
static void i2c_slave_read_from_ram_test(void)
|
static void i2c_slave_read_from_ram_test(void)
|
||||||
{
|
{
|
||||||
|
unity_wait_for_signal("i2c master init first");
|
||||||
uint8_t data_rd[DATA_LENGTH_RAM] = {0};
|
uint8_t data_rd[DATA_LENGTH_RAM] = {0};
|
||||||
|
|
||||||
i2c_slave_config_t i2c_slv_config = {
|
i2c_slave_config_t i2c_slv_config = {
|
||||||
@ -135,6 +138,8 @@ static void master_read_slave_from_ram_test(void)
|
|||||||
i2c_master_dev_handle_t dev_handle;
|
i2c_master_dev_handle_t dev_handle;
|
||||||
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
||||||
|
|
||||||
|
unity_send_signal("i2c master init first");
|
||||||
|
|
||||||
unity_wait_for_signal("i2c slave init finish");
|
unity_wait_for_signal("i2c slave init finish");
|
||||||
|
|
||||||
printf("Slave please write data to buffer\n");
|
printf("Slave please write data to buffer\n");
|
||||||
@ -158,6 +163,7 @@ static void master_read_slave_from_ram_test(void)
|
|||||||
|
|
||||||
static void slave_write_buffer_to_ram_test(void)
|
static void slave_write_buffer_to_ram_test(void)
|
||||||
{
|
{
|
||||||
|
unity_wait_for_signal("i2c master init first");
|
||||||
uint8_t data_wr[DATA_LENGTH_RAM] = {0};
|
uint8_t data_wr[DATA_LENGTH_RAM] = {0};
|
||||||
|
|
||||||
i2c_slave_config_t i2c_slv_config = {
|
i2c_slave_config_t i2c_slv_config = {
|
||||||
|
@ -60,6 +60,7 @@ static bool i2c_slave_receive_cb(i2c_slave_dev_handle_t i2c_slave, const i2c_sla
|
|||||||
|
|
||||||
static void i2c_slave_read_test_v2(void)
|
static void i2c_slave_read_test_v2(void)
|
||||||
{
|
{
|
||||||
|
unity_wait_for_signal("i2c master init first");
|
||||||
i2c_slave_dev_handle_t handle;
|
i2c_slave_dev_handle_t handle;
|
||||||
event_queue = xQueueCreate(2, sizeof(i2c_slave_event_t));
|
event_queue = xQueueCreate(2, sizeof(i2c_slave_event_t));
|
||||||
assert(event_queue);
|
assert(event_queue);
|
||||||
@ -132,6 +133,8 @@ static void i2c_master_write_test_v2(void)
|
|||||||
i2c_master_dev_handle_t dev_handle;
|
i2c_master_dev_handle_t dev_handle;
|
||||||
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
||||||
|
|
||||||
|
unity_send_signal("i2c master init first");
|
||||||
|
|
||||||
unity_wait_for_signal("i2c slave init finish");
|
unity_wait_for_signal("i2c slave init finish");
|
||||||
|
|
||||||
unity_send_signal("master write");
|
unity_send_signal("master write");
|
||||||
@ -147,7 +150,12 @@ static void i2c_master_write_test_v2(void)
|
|||||||
TEST_ESP_OK(i2c_del_master_bus(bus_handle));
|
TEST_ESP_OK(i2c_del_master_bus(bus_handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32S2
|
||||||
|
// The test for s2 is unstable on ci, but it should not fail in local test
|
||||||
|
TEST_CASE_MULTIPLE_DEVICES("I2C master write slave v2 test", "[i2c][test_env=generic_multi_device][timeout=150][ignore]", i2c_master_write_test_v2, i2c_slave_read_test_v2);
|
||||||
|
#else
|
||||||
TEST_CASE_MULTIPLE_DEVICES("I2C master write slave v2 test", "[i2c][test_env=generic_multi_device][timeout=150]", i2c_master_write_test_v2, i2c_slave_read_test_v2);
|
TEST_CASE_MULTIPLE_DEVICES("I2C master write slave v2 test", "[i2c][test_env=generic_multi_device][timeout=150]", i2c_master_write_test_v2, i2c_slave_read_test_v2);
|
||||||
|
#endif
|
||||||
|
|
||||||
static void master_read_slave_test_v2(void)
|
static void master_read_slave_test_v2(void)
|
||||||
{
|
{
|
||||||
@ -262,6 +270,8 @@ static void i2c_master_write_test_with_customize_api(void)
|
|||||||
i2c_master_dev_handle_t dev_handle;
|
i2c_master_dev_handle_t dev_handle;
|
||||||
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
||||||
|
|
||||||
|
unity_send_signal("i2c master init first");
|
||||||
|
|
||||||
unity_wait_for_signal("i2c slave init finish");
|
unity_wait_for_signal("i2c slave init finish");
|
||||||
|
|
||||||
unity_send_signal("master write");
|
unity_send_signal("master write");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user