Merge branch 'bugfix/i2c_example_esp32s3' into 'master'
i2c: bringup on ESP32-S3 Closes IDF-3232 and IDF-3292 See merge request espressif/esp-idf!13985
This commit is contained in:
@@ -23,13 +23,14 @@
|
||||
#include "driver/periph_ctrl.h"
|
||||
#include "esp_rom_gpio.h"
|
||||
#include "hal/gpio_hal.h"
|
||||
#include "hal/uart_ll.h"
|
||||
|
||||
|
||||
#define DATA_LENGTH 512 /*!<Data buffer length for test buffer*/
|
||||
#define RW_TEST_LENGTH 129 /*!<Data length for r/w test, any value from 0-DATA_LENGTH*/
|
||||
#define DELAY_TIME_BETWEEN_ITEMS_MS 1234 /*!< delay time between different test items */
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32C3
|
||||
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3
|
||||
#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
|
||||
@@ -44,9 +45,12 @@
|
||||
#if CONFIG_IDF_TARGET_ESP32C3
|
||||
#define I2C_MASTER_SCL_IO 5 /*!<gpio number for i2c master clock */
|
||||
#define I2C_MASTER_SDA_IO 6 /*!<gpio number for i2c master data */
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#define I2C_MASTER_SCL_IO 2 /*!<gpio number for i2c master clock */
|
||||
#define I2C_MASTER_SDA_IO 1 /*!<gpio number for i2c master data */
|
||||
#else
|
||||
#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_SCL_IO 19 /*!< gpio number for I2C master clock */
|
||||
#define I2C_MASTER_SDA_IO 18 /*!< gpio number for I2C master data */
|
||||
#endif
|
||||
|
||||
#define I2C_MASTER_NUM I2C_NUM_0 /*!< I2C port number for master dev */
|
||||
@@ -662,9 +666,10 @@ static void uart_aut_baud_det_init(int rxd_io_num)
|
||||
esp_rom_gpio_connect_out_signal(rxd_io_num, I2CEXT1_SCL_OUT_IDX, 0, 0);
|
||||
esp_rom_gpio_connect_in_signal(rxd_io_num, U1RXD_IN_IDX, 0);
|
||||
periph_module_enable(PERIPH_UART1_MODULE);
|
||||
UART1.int_ena.val = 0;
|
||||
UART1.int_clr.val = ~0;
|
||||
UART1.auto_baud.en = 1;
|
||||
/* Reset all the bits */
|
||||
uart_ll_disable_intr_mask(&UART1, ~0);
|
||||
uart_ll_clr_intsts_mask(&UART1, ~0);
|
||||
uart_ll_set_autobaud_en(&UART1, true);
|
||||
}
|
||||
|
||||
//Calculate I2C scl freq
|
||||
@@ -672,11 +677,11 @@ static void i2c_scl_freq_cal(void)
|
||||
{
|
||||
const int i2c_source_clk_freq = 80000000;
|
||||
const float i2c_cource_clk_period = 0.0125;
|
||||
int edg_cnt = UART1.rxd_cnt.edge_cnt;
|
||||
int pospulse_cnt = UART1.pospulse.min_cnt;
|
||||
int negpulse_cnt = UART1.negpulse.min_cnt;
|
||||
int high_period_cnt = UART1.highpulse.min_cnt;
|
||||
int low_period_cnt = UART1.lowpulse.min_cnt;
|
||||
int edg_cnt = uart_ll_get_rxd_edge_cnt(&UART1);
|
||||
int pospulse_cnt = uart_ll_get_pos_pulse_cnt(&UART1);
|
||||
int negpulse_cnt = uart_ll_get_neg_pulse_cnt(&UART1);
|
||||
int high_period_cnt = uart_ll_get_high_pulse_cnt(&UART1);
|
||||
int low_period_cnt = uart_ll_get_low_pulse_cnt(&UART1);
|
||||
if(edg_cnt != 542) {
|
||||
printf("\nedg_cnt != 542, test fail\n");
|
||||
return;
|
||||
@@ -684,7 +689,7 @@ static void i2c_scl_freq_cal(void)
|
||||
printf("\nDetected SCL frequency: %d Hz\n", i2c_source_clk_freq / ((pospulse_cnt + negpulse_cnt) / 2) );
|
||||
|
||||
printf("\nSCL high period %.3f (us), SCL low_period %.3f (us)\n\n", (float)(i2c_cource_clk_period * high_period_cnt), (float)(i2c_cource_clk_period * low_period_cnt));
|
||||
UART1.auto_baud.en = 0;
|
||||
uart_ll_set_autobaud_en(&UART1, false);
|
||||
periph_module_disable(PERIPH_UART1_MODULE);
|
||||
}
|
||||
|
||||
@@ -717,4 +722,4 @@ TEST_CASE("I2C SCL freq test (local test)", "[i2c][ignore]")
|
||||
TEST_ESP_OK(i2c_driver_delete(i2c_num));
|
||||
}
|
||||
|
||||
#endif // TEMPORARY_DISABLED_FOR_TARGETS(ESP32S3)
|
||||
#endif // TEMPORARY_DISABLED_FOR_TARGETS(ESP32S3, ESP32C3)
|
||||
|
||||
Reference in New Issue
Block a user