mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'ci/enable_i2c_test_v4.3' into 'release/v4.3'
I2C: enable all unit test for i2c on esp32c3 (backport 4.3) See merge request espressif/esp-idf!13061
This commit is contained in:
commit
52d9d466fb
@ -267,7 +267,7 @@ TEST_CASE("I2C driver memory leaking check", "[i2c]")
|
||||
TEST_ASSERT_INT_WITHIN(100, size, esp_get_free_heap_size());
|
||||
}
|
||||
|
||||
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32S3, ESP32C3)
|
||||
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32S3)
|
||||
|
||||
// print the reading buffer
|
||||
static void disp_buf(uint8_t *buf, int len)
|
||||
@ -397,7 +397,7 @@ static void slave_write_buffer_test(void)
|
||||
|
||||
TEST_CASE_MULTIPLE_DEVICES("I2C master read slave test", "[i2c][test_env=UT_T2_I2C][timeout=150]", master_read_slave_test, slave_write_buffer_test);
|
||||
|
||||
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32, ESP32C3)
|
||||
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32)
|
||||
static void i2c_master_write_read_test(void)
|
||||
{
|
||||
uint8_t *data_rd = (uint8_t *) malloc(DATA_LENGTH);
|
||||
@ -538,8 +538,8 @@ static void i2c_slave_repeat_read(void)
|
||||
TEST_CASE_MULTIPLE_DEVICES("I2C repeat write test", "[i2c][test_env=UT_T2_I2C][timeout=150]", i2c_master_repeat_write, i2c_slave_repeat_read);
|
||||
|
||||
|
||||
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32S3, ESP32C3)
|
||||
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32S3, ESP32C3)
|
||||
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32S3)
|
||||
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32S3)
|
||||
|
||||
static volatile bool exit_flag;
|
||||
static bool test_read_func;
|
||||
|
@ -903,6 +903,7 @@ static inline void i2c_ll_slave_init(i2c_dev_t *hw)
|
||||
ctrl_reg.sda_force_out = 1;
|
||||
ctrl_reg.scl_force_out = 1;
|
||||
hw->ctr.val = ctrl_reg.val;
|
||||
hw->ctr.slv_tx_auto_start_en = 1;
|
||||
hw->fifo_conf.fifo_addr_cfg_en = 0;
|
||||
}
|
||||
|
||||
|
@ -892,6 +892,7 @@ static inline void i2c_ll_slave_init(i2c_dev_t *hw)
|
||||
ctrl_reg.sda_force_out = 1;
|
||||
ctrl_reg.scl_force_out = 1;
|
||||
hw->ctr.val = ctrl_reg.val;
|
||||
hw->ctr.slv_tx_auto_start_en = 1;
|
||||
hw->fifo_conf.fifo_addr_cfg_en = 0;
|
||||
}
|
||||
|
||||
|
@ -32,12 +32,23 @@ using namespace idf;
|
||||
#define MAGIC_TEST_NUMBER 47
|
||||
|
||||
#define I2C_SLAVE_NUM I2C_NUM_0 /*!<I2C port number for slave dev */
|
||||
#if CONFIG_IDF_TARGET_ESP32C3
|
||||
#define I2C_SLAVE_SCL_IO 5 /*!<gpio number for i2c slave clock */
|
||||
#define I2C_SLAVE_SDA_IO 6 /*!<gpio number for i2c slave data */
|
||||
#else
|
||||
#define I2C_SLAVE_SCL_IO 19 /*!<gpio number for i2c slave clock */
|
||||
#define I2C_SLAVE_SDA_IO 18 /*!<gpio number for i2c slave data */
|
||||
#endif
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32C3
|
||||
#define I2C_MASTER_NUM I2C_NUM_0 /*!< I2C port number for master dev */
|
||||
#define I2C_MASTER_SCL_IO 5 /*!<gpio number for i2c master clock */
|
||||
#define I2C_MASTER_SDA_IO 6 /*!<gpio number for i2c master data */
|
||||
#else
|
||||
#define I2C_MASTER_NUM I2C_NUM_1 /*!< I2C port number for master dev */
|
||||
#define I2C_MASTER_SCL_IO 19 /*!< gpio number for I2C master clock */
|
||||
#define I2C_MASTER_SDA_IO 18 /*!< gpio number for I2C master data */
|
||||
#define I2C_MASTER_SDA_IO 18 /*!< gpio number for I2C master data */
|
||||
#endif
|
||||
|
||||
struct MasterFixture {
|
||||
MasterFixture(const vector<uint8_t> &data_arg = {47u}) :
|
||||
@ -59,7 +70,7 @@ TEST_CASE("I2CMaster SDA and SCL equal", "[cxx i2c][leaks=300]")
|
||||
}
|
||||
|
||||
// TODO The I2C driver tests are disabled, so disable them here, too. Probably due to no runners.
|
||||
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32S3, ESP32C3)
|
||||
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32S3)
|
||||
|
||||
static void i2c_slave_read_raw_byte(void)
|
||||
{
|
||||
@ -107,7 +118,7 @@ static void i2c_slave_read_multiple_raw_bytes(void)
|
||||
|
||||
static void i2c_slave_write_multiple_raw_bytes(void)
|
||||
{
|
||||
I2CSlave slave(1, I2C_SLAVE_SCL_IO, I2C_SLAVE_SDA_IO, ADDR, 512, 512);
|
||||
I2CSlave slave(I2C_SLAVE_NUM, I2C_SLAVE_SCL_IO, I2C_SLAVE_SDA_IO, ADDR, 512, 512);
|
||||
uint8_t WRITE_BUFFER [8] = {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
|
||||
unity_wait_for_signal("master init");
|
||||
@ -120,7 +131,7 @@ static void i2c_slave_write_multiple_raw_bytes(void)
|
||||
|
||||
static void i2c_slave_composed_trans(void)
|
||||
{
|
||||
I2CSlave slave(1, I2C_SLAVE_SCL_IO, I2C_SLAVE_SDA_IO, ADDR, 512, 512);
|
||||
I2CSlave slave(I2C_SLAVE_NUM, I2C_SLAVE_SCL_IO, I2C_SLAVE_SDA_IO, ADDR, 512, 512);
|
||||
size_t BUF_SIZE = 2;
|
||||
const uint8_t SLAVE_WRITE_BUFFER [BUF_SIZE] = {0xde, 0xad};
|
||||
uint8_t slave_read_buffer = 0;
|
||||
@ -330,7 +341,7 @@ TEST_CASE_MULTIPLE_DEVICES("I2CMaster Composed transfer", "[cxx i2c][test_env=UT
|
||||
|
||||
static void i2c_slave_write_multiple_raw_bytes_twice(void)
|
||||
{
|
||||
I2CSlave slave(1, I2C_SLAVE_SCL_IO, I2C_SLAVE_SDA_IO, ADDR, 512, 512);
|
||||
I2CSlave slave(I2C_SLAVE_NUM, I2C_SLAVE_SCL_IO, I2C_SLAVE_SDA_IO, ADDR, 512, 512);
|
||||
const size_t BUF_SIZE = 8;
|
||||
uint8_t WRITE_BUFFER [BUF_SIZE] = {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
|
||||
@ -350,7 +361,7 @@ static void i2c_master_reuse_read_multiple_raw_bytes(void)
|
||||
unity_send_signal("master init");
|
||||
unity_wait_for_signal("slave write");
|
||||
const size_t BUF_SIZE = 8;
|
||||
|
||||
#if !CONFIG_IDF_TARGET_ESP32C3
|
||||
std::shared_ptr<I2CRead> reader(new I2CRead(BUF_SIZE));
|
||||
|
||||
future<vector<uint8_t> > fut;
|
||||
@ -368,6 +379,22 @@ static void i2c_master_reuse_read_multiple_raw_bytes(void)
|
||||
TEST_ASSERT_EQUAL(i, data1[i]);
|
||||
TEST_ASSERT_EQUAL(i, data2[i]);
|
||||
}
|
||||
#else // Cannot read twice because the `prefetch` behaviour on C3.
|
||||
std::shared_ptr<I2CRead> reader(new I2CRead(BUF_SIZE * 2));
|
||||
|
||||
future<vector<uint8_t> > fut;
|
||||
fut = fix.master->transfer(reader, ADDR);
|
||||
vector<uint8_t> data = fut.get();
|
||||
|
||||
unity_send_signal("master read done");
|
||||
|
||||
TEST_ASSERT_EQUAL(BUF_SIZE * 2, data.size());
|
||||
for (int i = 0; i < BUF_SIZE; i++) {
|
||||
TEST_ASSERT_EQUAL((i % BUF_SIZE), data[i]);
|
||||
}
|
||||
|
||||
#endif // !CONFIG_IDF_TARGET_ESP32C3
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE_MULTIPLE_DEVICES("I2CMaster reuse read multiple bytes", "[cxx i2c][test_env=UT_T2_I2C][timeout=150]",
|
||||
@ -414,7 +441,7 @@ TEST_CASE_MULTIPLE_DEVICES("I2CMaster reuse write multiple bytes", "[cxx i2c][te
|
||||
|
||||
static void i2c_slave_composed_trans_twice(void)
|
||||
{
|
||||
I2CSlave slave(1, I2C_SLAVE_SCL_IO, I2C_SLAVE_SDA_IO, ADDR, 512, 512);
|
||||
I2CSlave slave(I2C_SLAVE_NUM, I2C_SLAVE_SCL_IO, I2C_SLAVE_SDA_IO, ADDR, 512, 512);
|
||||
size_t BUF_SIZE = 2;
|
||||
const uint8_t SLAVE_WRITE_BUFFER1 [BUF_SIZE] = {0xde, 0xad};
|
||||
const uint8_t SLAVE_WRITE_BUFFER2 [BUF_SIZE] = {0xbe, 0xef};
|
||||
@ -429,8 +456,10 @@ static void i2c_slave_composed_trans_twice(void)
|
||||
|
||||
TEST_ASSERT_EQUAL(1, slave.read_raw(&slave_read_buffer, 1, chrono::milliseconds(1000)));
|
||||
TEST_ASSERT_EQUAL(MAGIC_TEST_NUMBER, slave_read_buffer);
|
||||
#if !CONFIG_IDF_TARGET_ESP32C3
|
||||
TEST_ASSERT_EQUAL(1, slave.read_raw(&slave_read_buffer, 1, chrono::milliseconds(1000)));
|
||||
TEST_ASSERT_EQUAL(MAGIC_TEST_NUMBER, slave_read_buffer);
|
||||
#endif // !CONFIG_IDF_TARGET_ESP32C3
|
||||
}
|
||||
|
||||
static void i2c_master_reuse_composed_trans(void)
|
||||
@ -442,6 +471,7 @@ static void i2c_master_reuse_composed_trans(void)
|
||||
|
||||
std::shared_ptr<I2CComposed> composed_transfer(new I2CComposed);
|
||||
composed_transfer->add_write({47u});
|
||||
#if !CONFIG_IDF_TARGET_ESP32C3
|
||||
composed_transfer->add_read(BUF_SIZE);
|
||||
|
||||
unity_wait_for_signal("slave init");
|
||||
@ -461,9 +491,31 @@ static void i2c_master_reuse_composed_trans(void)
|
||||
TEST_ASSERT_EQUAL(SLAVE_WRITE_BUFFER1[i], read_data1[0][i]);
|
||||
TEST_ASSERT_EQUAL(SLAVE_WRITE_BUFFER2[i], read_data2[0][i]);
|
||||
}
|
||||
#else // Cannot read twice because the `prefetch` behaviour on C3.
|
||||
composed_transfer->add_read(BUF_SIZE * 2);
|
||||
|
||||
unity_wait_for_signal("slave init");
|
||||
|
||||
vector<vector<uint8_t> > read_data = fix.master->transfer(composed_transfer, ADDR).get();
|
||||
|
||||
unity_send_signal("master transfer");
|
||||
|
||||
TEST_ASSERT_EQUAL(1, read_data.size());
|
||||
TEST_ASSERT_EQUAL(4, read_data[0].size());
|
||||
|
||||
|
||||
for (int i = 0; i < BUF_SIZE; i++) {
|
||||
TEST_ASSERT_EQUAL(SLAVE_WRITE_BUFFER1[i], read_data[0][i]);
|
||||
}
|
||||
for (int i = BUF_SIZE; i < BUF_SIZE * 2; i++) {
|
||||
TEST_ASSERT_EQUAL(SLAVE_WRITE_BUFFER2[i - BUF_SIZE], read_data[0][i]);
|
||||
}
|
||||
|
||||
#endif //!CONFIG_IDF_TARGET_ESP32C3
|
||||
}
|
||||
|
||||
TEST_CASE_MULTIPLE_DEVICES("I2CMaster reuse composed transfer", "[cxx i2c][test_env=UT_T2_I2C][timeout=150]",
|
||||
i2c_master_reuse_composed_trans, i2c_slave_composed_trans_twice);
|
||||
#endif //TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32S3, ESP32C3)
|
||||
|
||||
#endif //TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32S3)
|
||||
#endif // __cpp_exceptions
|
||||
|
@ -601,7 +601,7 @@ UT_C3:
|
||||
|
||||
UT_C3_FLASH:
|
||||
extends: .unit_test_c3_template
|
||||
parallel: 3
|
||||
parallel: 2
|
||||
tags:
|
||||
- ESP32C3_IDF
|
||||
- UT_T1_ESP_FLASH
|
||||
@ -613,6 +613,12 @@ UT_C3_SPI_DUAL:
|
||||
- ESP32C3_IDF
|
||||
- Example_SPI_Multi_device
|
||||
|
||||
UT_C3_I2C:
|
||||
extends: .unit_test_c3_template
|
||||
tags:
|
||||
- ESP32C3_IDF
|
||||
- UT_T2_I2C
|
||||
|
||||
nvs_compatible_test:
|
||||
extends: .integration_test_template
|
||||
artifacts:
|
||||
|
Loading…
Reference in New Issue
Block a user