mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 10:47:19 +02:00
Merge branch 'bugfix/fix_micro_error_SPI_HOST_MAX_v4.4' into 'release/v4.4'
spi: fix micro SPI_HOST_MAX error (v4.4) See merge request espressif/esp-idf!22148
This commit is contained in:
@ -27,7 +27,9 @@ typedef enum {
|
|||||||
//SPI1 can be used as GPSPI only on ESP32
|
//SPI1 can be used as GPSPI only on ESP32
|
||||||
SPI1_HOST=0, ///< SPI1
|
SPI1_HOST=0, ///< SPI1
|
||||||
SPI2_HOST=1, ///< SPI2
|
SPI2_HOST=1, ///< SPI2
|
||||||
|
#if SOC_SPI_PERIPH_NUM > 2
|
||||||
SPI3_HOST=2, ///< SPI3
|
SPI3_HOST=2, ///< SPI3
|
||||||
|
#endif
|
||||||
} spi_host_device_t;
|
} spi_host_device_t;
|
||||||
|
|
||||||
/// SPI Events
|
/// SPI Events
|
||||||
|
@ -236,33 +236,39 @@ esp_err_t esp_flash_init_os_functions(esp_flash_t *chip, int host_id, int* out_d
|
|||||||
dev_handle = register_dev(host_id);
|
dev_handle = register_dev(host_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (host_id == SPI1_HOST) {
|
switch (host_id)
|
||||||
//SPI1
|
{
|
||||||
chip->os_func = &esp_flash_spi1_default_os_functions;
|
case SPI1_HOST:
|
||||||
chip->os_func_data = heap_caps_malloc(sizeof(spi1_app_func_arg_t),
|
//SPI1
|
||||||
MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
chip->os_func = &esp_flash_spi1_default_os_functions;
|
||||||
if (chip->os_func_data == NULL) {
|
chip->os_func_data = heap_caps_malloc(sizeof(spi1_app_func_arg_t),
|
||||||
return ESP_ERR_NO_MEM;
|
MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||||
}
|
if (chip->os_func_data == NULL) {
|
||||||
*(spi1_app_func_arg_t*) chip->os_func_data = (spi1_app_func_arg_t) {
|
return ESP_ERR_NO_MEM;
|
||||||
.common_arg = {
|
}
|
||||||
|
*(spi1_app_func_arg_t*) chip->os_func_data = (spi1_app_func_arg_t) {
|
||||||
|
.common_arg = {
|
||||||
|
.dev_lock = dev_handle,
|
||||||
|
},
|
||||||
|
.no_protect = true,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case SPI2_HOST:
|
||||||
|
#if SOC_SPI_PERIPH_NUM > 2
|
||||||
|
case SPI3_HOST:
|
||||||
|
#endif
|
||||||
|
//SPI2, SPI3
|
||||||
|
chip->os_func = &esp_flash_spi23_default_os_functions;
|
||||||
|
chip->os_func_data = heap_caps_malloc(sizeof(app_func_arg_t),
|
||||||
|
MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||||
|
if (chip->os_func_data == NULL) {
|
||||||
|
return ESP_ERR_NO_MEM;
|
||||||
|
}
|
||||||
|
*(app_func_arg_t*) chip->os_func_data = (app_func_arg_t) {
|
||||||
.dev_lock = dev_handle,
|
.dev_lock = dev_handle,
|
||||||
},
|
};
|
||||||
.no_protect = true,
|
break;
|
||||||
};
|
default: return ESP_ERR_INVALID_ARG;
|
||||||
} else if (host_id == SPI2_HOST || host_id == SPI3_HOST) {
|
|
||||||
//SPI2, SPI3
|
|
||||||
chip->os_func = &esp_flash_spi23_default_os_functions;
|
|
||||||
chip->os_func_data = heap_caps_malloc(sizeof(app_func_arg_t),
|
|
||||||
MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
|
||||||
if (chip->os_func_data == NULL) {
|
|
||||||
return ESP_ERR_NO_MEM;
|
|
||||||
}
|
|
||||||
*(app_func_arg_t*) chip->os_func_data = (app_func_arg_t) {
|
|
||||||
.dev_lock = dev_handle,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return ESP_ERR_INVALID_ARG;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bus lock not initialized, the device ID should be directly given by application.
|
// Bus lock not initialized, the device ID should be directly given by application.
|
||||||
|
@ -329,7 +329,8 @@ static void setup_bus(spi_host_device_t host_id)
|
|||||||
gpio_iomux_out(hd_pin, spi_periph_signal[host_id].func, false);
|
gpio_iomux_out(hd_pin, spi_periph_signal[host_id].func, false);
|
||||||
#endif //CONFIG_ESPTOOLPY_FLASHMODE_QIO || CONFIG_ESPTOOLPY_FLASHMODE_QOUT
|
#endif //CONFIG_ESPTOOLPY_FLASHMODE_QIO || CONFIG_ESPTOOLPY_FLASHMODE_QOUT
|
||||||
//currently the SPI bus for main flash chip is initialized through GPIO matrix
|
//currently the SPI bus for main flash chip is initialized through GPIO matrix
|
||||||
} else if (host_id == SPI2_HOST) {
|
}
|
||||||
|
else if (host_id == SPI2_HOST) {
|
||||||
ESP_LOGI(TAG, "setup flash on SPI%d (FSPI) CS0...\n", host_id + 1);
|
ESP_LOGI(TAG, "setup flash on SPI%d (FSPI) CS0...\n", host_id + 1);
|
||||||
spi_bus_config_t fspi_bus_cfg = {
|
spi_bus_config_t fspi_bus_cfg = {
|
||||||
.mosi_io_num = FSPI_PIN_NUM_MOSI,
|
.mosi_io_num = FSPI_PIN_NUM_MOSI,
|
||||||
@ -341,7 +342,9 @@ static void setup_bus(spi_host_device_t host_id)
|
|||||||
};
|
};
|
||||||
esp_err_t ret = spi_bus_initialize(host_id, &fspi_bus_cfg, 0);
|
esp_err_t ret = spi_bus_initialize(host_id, &fspi_bus_cfg, 0);
|
||||||
TEST_ESP_OK(ret);
|
TEST_ESP_OK(ret);
|
||||||
} else if (host_id == SPI3_HOST) {
|
}
|
||||||
|
#if SOC_SPI_PERIPH_NUM > 2
|
||||||
|
else if (host_id == SPI3_HOST) {
|
||||||
ESP_LOGI(TAG, "setup flash on SPI%d (HSPI) CS0...\n", host_id + 1);
|
ESP_LOGI(TAG, "setup flash on SPI%d (HSPI) CS0...\n", host_id + 1);
|
||||||
spi_bus_config_t hspi_bus_cfg = {
|
spi_bus_config_t hspi_bus_cfg = {
|
||||||
.mosi_io_num = HSPI_PIN_NUM_MOSI,
|
.mosi_io_num = HSPI_PIN_NUM_MOSI,
|
||||||
@ -360,7 +363,9 @@ static void setup_bus(spi_host_device_t host_id)
|
|||||||
|
|
||||||
gpio_set_direction(HSPI_PIN_NUM_WP, GPIO_MODE_OUTPUT);
|
gpio_set_direction(HSPI_PIN_NUM_WP, GPIO_MODE_OUTPUT);
|
||||||
gpio_set_level(HSPI_PIN_NUM_WP, 1);
|
gpio_set_level(HSPI_PIN_NUM_WP, 1);
|
||||||
} else {
|
}
|
||||||
|
#endif
|
||||||
|
else {
|
||||||
ESP_LOGE(TAG, "invalid bus");
|
ESP_LOGE(TAG, "invalid bus");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -369,7 +374,12 @@ static void setup_bus(spi_host_device_t host_id)
|
|||||||
static void release_bus(int host_id)
|
static void release_bus(int host_id)
|
||||||
{
|
{
|
||||||
//SPI1 bus can't be deinitialized
|
//SPI1 bus can't be deinitialized
|
||||||
if (host_id == SPI2_HOST || host_id == SPI3_HOST) {
|
#if SOC_SPI_PERIPH_NUM > 2
|
||||||
|
if (host_id == SPI2_HOST || host_id == SPI3_HOST)
|
||||||
|
#else
|
||||||
|
if (host_id == SPI2_HOST)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
spi_bus_free(host_id);
|
spi_bus_free(host_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user