Skip to content

Commit

Permalink
Merge branch 'feature/c6_spi_master_driver_support' into 'master'
Browse files Browse the repository at this point in the history
esp32c6: support spi master & slave driver

Closes IDF-5335 and IDF-5336

See merge request espressif/esp-idf!20877
  • Loading branch information
wanckl committed Nov 22, 2022
2 parents 439a709 + 3aeedc2 commit 65c0b2b
Show file tree
Hide file tree
Showing 28 changed files with 157 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@
#define GPIO_DELAY 0
#define ESP_SPI_SLAVE_TV 0
#define WIRE_DELAY 12.5

#elif CONFIG_IDF_TARGET_ESP32C6
#define TEST_SPI_HOST SPI2_HOST
#define TEST_SLAVE_HOST SPI2_HOST

#define PIN_NUM_MISO SPI2_IOMUX_PIN_NUM_MISO
#define PIN_NUM_MOSI SPI2_IOMUX_PIN_NUM_MOSI
#define PIN_NUM_CLK SPI2_IOMUX_PIN_NUM_CLK
#define PIN_NUM_CS 10 //the IOMUX pin of SPI2 CS0&CS1 is Pin_16&17 which is same from UART Tx&Rx Pin
#define PIN_NUM_WP SPI2_IOMUX_PIN_NUM_WP
#define PIN_NUM_HD SPI2_IOMUX_PIN_NUM_HD
#endif

#define GET_DMA_CHAN(HOST) (HOST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "esp_rom_gpio.h"


#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C6)
int test_freq_default[]=TEST_FREQ_DEFAULT();

const char MASTER_TAG[] = "test_master";
Expand Down Expand Up @@ -250,5 +249,3 @@ void get_tx_buffer(uint32_t seed, uint8_t *master_send_buf, uint8_t *slave_send_
master_send_buf[i] = rand() % 256;
}
}

#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C6)
53 changes: 9 additions & 44 deletions components/driver/test_apps/spi/master/main/test_spi_master.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "test_spi_utils.h"


#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C6)
const static char TAG[] = "test_spi";

// There is no input-only pin except on esp32 and esp32s2
Expand Down Expand Up @@ -597,8 +596,7 @@ TEST_CASE("SPI Master no response when switch from host1 (SPI2) to host2 (SPI3)"
TEST_ESP_OK(spi_bus_free(host));
}

#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
//IDF-5146

DRAM_ATTR static uint32_t data_dram[80] = {0};
//force to place in code area.
static const uint8_t data_drom[320 + 3] = {
Expand Down Expand Up @@ -631,18 +629,8 @@ TEST_CASE("SPI Master DMA test, TX and RX in different regions", "[spi]")
ESP_LOGI(TAG, "dram: %p", data_dram);
ESP_LOGI(TAG, "drom: %p, malloc: %p", data_drom, data_malloc);

#ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
uint32_t *data_iram = (uint32_t *)heap_caps_malloc(324, MALLOC_CAP_EXEC);
TEST_ASSERT(data_iram != NULL);
TEST_ASSERT(esp_ptr_executable(data_iram) || esp_ptr_in_iram(data_iram) || esp_ptr_in_diram_iram(data_iram));
ESP_LOGI(TAG, "iram: %p", data_iram);
#endif

srand(52);
for (int i = 0; i < 320 / 4; i++) {
#ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
data_iram[i] = rand();
#endif
data_dram[i] = rand();
data_malloc[i] = rand();
}
Expand All @@ -660,42 +648,24 @@ TEST_CASE("SPI Master DMA test, TX and RX in different regions", "[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);

#define TEST_REGION_SIZE 5
#define TEST_REGION_SIZE 2
static spi_transaction_t trans[TEST_REGION_SIZE];
int x;
memset(trans, 0, sizeof(trans));

#ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
trans[0].length = 320 * 8,
trans[0].tx_buffer = data_iram;
trans[0].rx_buffer = data_malloc + 1;

trans[1].length = 320 * 8,
trans[1].tx_buffer = data_dram;
trans[1].rx_buffer = data_iram;
trans[0].tx_buffer = data_malloc + 2;
trans[0].rx_buffer = data_dram;

trans[2].length = 320 * 8,
trans[2].tx_buffer = data_drom;
trans[2].rx_buffer = data_iram;
#endif

trans[3].length = 320 * 8,
trans[3].tx_buffer = data_malloc + 2;
trans[3].rx_buffer = data_dram;

trans[4].length = 4 * 8,
trans[4].flags = SPI_TRANS_USE_RXDATA | SPI_TRANS_USE_TXDATA;
uint32_t *ptr = (uint32_t *)trans[4].rx_data;
trans[1].length = 4 * 8,
trans[1].flags = SPI_TRANS_USE_RXDATA | SPI_TRANS_USE_TXDATA;
uint32_t *ptr = (uint32_t *)trans[1].rx_data;
*ptr = 0x54545454;
ptr = (uint32_t *)trans[4].tx_data;
ptr = (uint32_t *)trans[1].tx_data;
*ptr = 0xbc124960;

//Queue all transactions.
#ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
for (x = 0; x < TEST_REGION_SIZE; x++) {
#else
for (x = 3; x < TEST_REGION_SIZE; x++) {
#endif
ESP_LOGI(TAG, "transmitting %d...", x);
ret = spi_device_transmit(spi, &trans[x]);
TEST_ASSERT(ret == ESP_OK);
Expand All @@ -708,11 +678,7 @@ TEST_CASE("SPI Master DMA test, TX and RX in different regions", "[spi]")
TEST_ASSERT(spi_bus_remove_device(spi) == ESP_OK);
TEST_ASSERT(spi_bus_free(TEST_SPI_HOST) == ESP_OK);
free(data_malloc);
#ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
free(data_iram);
#endif
}
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)

//this part tests 3 DMA issues in master mode, full-duplex in IDF2.1
// 1. RX buffer not aligned (start and end)
Expand Down Expand Up @@ -1459,7 +1425,7 @@ TEST_CASE("spi_speed", "[spi]")
#define DUMMY_CS_PINS() {0, 1, 4, 5, 8, 9}
#endif //CONFIG_IDF_TARGET_ESP32

#define CS_REAL_DEV SPI2_IOMUX_PIN_NUM_CS
#define CS_REAL_DEV PIN_NUM_CS
#define TEST_TRANS_LEN 48

void test_add_device_master(void)
Expand Down Expand Up @@ -1559,4 +1525,3 @@ void test_add_device_slave(void)
}

TEST_CASE_MULTIPLE_DEVICES("SPI_Master:Test multiple devices", "[spi_ms][test_env=generic_multi_device]", test_add_device_master, test_add_device_slave);
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C6)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


# If `test_env` is define, should not run on generic runner
@pytest.mark.esp32c6
@pytest.mark.supported_targets
@pytest.mark.generic
def test_master_single_dev(case_tester) -> None: # type: ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
CONFIG_XTAL_FREQ_AUTO=y
CONFIG_SPI_FLASH_SHARE_SPI1_BUS=y
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y

CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partition_table_esp32_flash.csv"
CONFIG_PARTITION_TABLE_FILENAME="partition_table_esp32_flash.csv"
Expand Down
4 changes: 2 additions & 2 deletions components/driver/test_apps/spi/slave/main/test_spi_slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ TEST_CASE("test slave send unaligned","[spi]")

#endif // #if (TEST_SPI_PERIPH_NUM >= 2)

#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2, ESP32C6)
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
#if (TEST_SPI_PERIPH_NUM == 1)
//These tests are for chips which only have 1 SPI controller
/********************************************************************************
Expand Down Expand Up @@ -386,4 +386,4 @@ static void unaligned_test_slave(void)
TEST_CASE_MULTIPLE_DEVICES("SPI_Slave_Unaligned_Test", "[spi_ms][test_env=generic_multi_device][timeout=120]", unaligned_test_master, unaligned_test_slave);

#endif //#if (TEST_SPI_PERIPH_NUM == 1)
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(...)
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#define TEST_BUF_SIZE 32
#define TEST_TIMES 4

#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C6)

static void test_master(void)
{
Expand Down Expand Up @@ -216,4 +215,3 @@ static void test_slave(void)
}

TEST_CASE_MULTIPLE_DEVICES("SPI_Slave_Reset_Queue_Test", "[spi_ms][timeout=120]", test_master, test_slave);
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C6)
1 change: 1 addition & 0 deletions components/driver/test_apps/spi/slave/pytest_spi_slave.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


# If `test_env` is define, should not run on generic runner
@pytest.mark.esp32c6
@pytest.mark.supported_targets
@pytest.mark.generic
def test_slave_single_dev(case_tester) -> None: # type: ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ TEST_CASE("test spi slave hd segment mode, master too long", "[spi][spi_slv_hd]"

#endif //#if (TEST_SPI_PERIPH_NUM >= 2)

#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C6)

#if (TEST_SPI_PERIPH_NUM == 1)
//These tests are for chips which only have 1 SPI controller
/********************************************************************************
Expand Down Expand Up @@ -883,6 +883,4 @@ TEST_CASE_MULTIPLE_DEVICES("SPI quad hd test ", "[spi_ms][test_env=generic_multi

#endif // #if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2)

#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C6)

#endif //SOC_SPI_SUPPORT_SLAVE_HD_VER2
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


# If `test_env` is define, should not run on generic runner
@pytest.mark.esp32c6
@pytest.mark.supported_targets
@pytest.mark.generic
def test_slave_hd_single_dev(case_tester) -> None: # type: ignore
Expand Down
10 changes: 5 additions & 5 deletions components/hal/esp32c6/include/hal/spi_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "hal/assert.h"
#include "hal/misc.h"
#include "hal/spi_types.h"
#include "soc/pcr_struct.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -111,9 +112,8 @@ static inline void spi_ll_master_init(spi_dev_t *hw)
hw->slave.val = 0;
hw->user.val = 0;

hw->clk_gate.clk_en = 1;
hw->clk_gate.mst_clk_active = 1;
hw->clk_gate.mst_clk_sel = 1;
PCR.spi2_clkm_conf.spi2_clkm_en = 1;
PCR.spi2_clkm_conf.spi2_clkm_sel = 1;

hw->dma_conf.val = 0;
hw->dma_conf.slv_tx_seg_trans_clr_en = 1;
Expand Down Expand Up @@ -1044,7 +1044,7 @@ static inline void spi_ll_disable_int(spi_dev_t *hw)
*/
static inline void spi_ll_clear_int_stat(spi_dev_t *hw)
{
hw->dma_int_raw.trans_done = 0;
hw->dma_int_clr.trans_done = 1;
}

/**
Expand All @@ -1054,7 +1054,7 @@ static inline void spi_ll_clear_int_stat(spi_dev_t *hw)
*/
static inline void spi_ll_set_int_stat(spi_dev_t *hw)
{
hw->dma_int_raw.trans_done = 1;
hw->dma_int_set.trans_done_int_set = 1;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions components/idf_test/include/esp32c6/idf_performance_target.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@

#define IDF_PERFORMANCE_MAX_ECDSA_P192_VERIFY_OP 18000
#define IDF_PERFORMANCE_MAX_ECDSA_P256_VERIFY_OP 27000

#define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_POLLING 45
#define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_POLLING_NO_DMA 40
#define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING 115
#define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING_NO_DMA 110
14 changes: 7 additions & 7 deletions components/soc/esp32c6/include/soc/spi_pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
#define _SOC_SPI_PINS_H_

#define SPI_FUNC_NUM 0
#define SPI_IOMUX_PIN_NUM_HD 12
#define SPI_IOMUX_PIN_NUM_CS 14
#define SPI_IOMUX_PIN_NUM_MOSI 16
#define SPI_IOMUX_PIN_NUM_CLK 15
#define SPI_IOMUX_PIN_NUM_MISO 17
#define SPI_IOMUX_PIN_NUM_WP 13
#define SPI_IOMUX_PIN_NUM_CS 24
#define SPI_IOMUX_PIN_NUM_CLK 29
#define SPI_IOMUX_PIN_NUM_MOSI 30
#define SPI_IOMUX_PIN_NUM_MISO 25
#define SPI_IOMUX_PIN_NUM_WP 26
#define SPI_IOMUX_PIN_NUM_HD 28

#define SPI2_FUNC_NUM 2
#define SPI2_IOMUX_PIN_NUM_MISO 2
#define SPI2_IOMUX_PIN_NUM_HD 4
#define SPI2_IOMUX_PIN_NUM_WP 5
#define SPI2_IOMUX_PIN_NUM_CLK 6
#define SPI2_IOMUX_PIN_NUM_MOSI 7
#define SPI2_IOMUX_PIN_NUM_CS 10
#define SPI2_IOMUX_PIN_NUM_CS 16

#endif
4 changes: 0 additions & 4 deletions docs/docs_not_updated/esp32c6.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,20 @@ api-reference/peripherals/hmac
api-reference/peripherals/usb_device
api-reference/peripherals/sdspi_host
api-reference/peripherals/dac
api-reference/peripherals/spi_slave
api-reference/peripherals/gptimer
api-reference/peripherals/touch_element
api-reference/peripherals/lcd
api-reference/peripherals/secure_element
api-reference/peripherals/ledc
api-reference/peripherals/temp_sensor
api-reference/peripherals/spi_features
api-reference/peripherals/sdio_slave
api-reference/peripherals/clk_tree
api-reference/peripherals/sdm
api-reference/peripherals/touch_pad
api-reference/peripherals/adc_calibration
api-reference/peripherals/spi_slave_hd
api-reference/peripherals/ds
api-reference/peripherals/dedic_gpio
api-reference/peripherals/sd_pullup_requirements
api-reference/peripherals/spi_master
api-reference/peripherals/index
api-reference/peripherals/sdmmc_host
api-reference/peripherals/uart
Expand Down
Loading

0 comments on commit 65c0b2b

Please sign in to comment.