[求助]ESP32S3无法使用GPIO32/31/30初始化SPI2总线?

unreal
Posts: 1
Joined: Tue Feb 21, 2023 9:03 am

[求助]ESP32S3无法使用GPIO32/31/30初始化SPI2总线?

Postby unreal » Tue Feb 21, 2023 9:14 am

芯片型号为ESP32S3FN,我使用了SPICLK(GPIO30)、SPIQ(GPIO31)、SPID(GPIO32)等IO连接了一个1GBit WINBOND NAND FLASH,当我调用spi_bus_initialize()初始化SPI2总线时,程序卡死了,我的初始化设置如下:
spi_bus_config_t cfg_bus = {0};
cfg_bus.mosi_io_num = 32;
cfg_bus.miso_io_num = 31;
cfg_bus.sclk_io_num = 30;
cfg_bus.quadwp_io_num = -1;
cfg_bus.quadhd_io_num = -1;
cfg_bus.data3_io_num = -1;
cfg_bus.data4_io_num = -1;
cfg_bus.data5_io_num = -1;
cfg_bus.data6_io_num = -1;
cfg_bus.data7_io_num = -1;
cfg_bus.max_transfer_sz = 64;
cfg_bus.flags = SPICOMMON_BUSFLAG_MASTER|SPICOMMON_BUSFLAG_SCLK|SPICOMMON_BUSFLAG_MISO|SPICOMMON_BUSFLAG_MOSI|SPICOMMON_BUSFLAG_GPIO_PINS;
cfg_bus.intr_flags = 0;
if(ESP_OK != spi_bus_initialize(SPI2_HOST, &cfg_bus, SPI_DMA_CH_AUTO))
{
printf("spi bus init failed!\r\n");
return -1;
}
以上代码将不会返回并打印信息。然后我尝试使用SPI1总线,但是提示我总线已经初始化。
所以我推测是SPI1总线已经占用了以上IO,导致SPI2无法使用这几个IO初始化,这样的猜想是否正确?

之后我尝试跳过spi_bus_initialize()并使用spi_bus_add_device()在SPI1总线挂载SPI Device,初始化配置如下:
spi_device_interface_config_t cfg_dev = {0};
cfg_dev.command_bits = 0;
cfg_dev.address_bits = 0;
cfg_dev.dummy_bits = 0;
cfg_dev.mode = 0;
cfg_dev.duty_cycle_pos = 128;
cfg_dev.cs_ena_pretrans = 3;
cfg_dev.cs_ena_posttrans = 3;
cfg_dev.clock_speed_hz = SPI_MASTER_FREQ_10M;
cfg_dev.input_delay_ns = 0;
cfg_dev.spics_io_num = 26;
cfg_dev.flags = SPI_DEVICE_NO_DUMMY;
cfg_dev.queue_size = 7;
cfg_dev.pre_cb = NULL;
cfg_dev.post_cb = NULL;
if(ESP_OK != spi_bus_add_device(SPI1_HOST, &cfg_dev, &handle->hspi))
{
printf("spi dev add failed!\r\n");
return -1;
}
以上代码打印信息为 invalid host。
之后我了解到同一个总线上不能同时挂载flash和device,所以我推测是SPI1总线已经有了flash(内部)被挂载,所以造成无法挂载SPI Device?

然后我尝试使用spi_bus_add_flash_device()在SPI1总线上挂载flash,配置如下:
esp_flash_spi_device_config_t cfg_fdev = {0};
cfg_fdev.host_id = SPI1_HOST;
cfg_fdev.cs_io_num = 26;
cfg_fdev.io_mode = SPI_FLASH_DIO;
cfg_fdev.speed = ESP_FLASH_10MHZ;
cfg_fdev.input_delay_ns = 0;
cfg_fdev.cs_id = 1;
cfg_fdev.freq_mhz = ESP_FLASH_80MHZ;
if(ESP_OK != spi_bus_add_flash_device(&hfspi, &cfg_fdev))
{
printf("spi flash add failed!\r\n");
return -1;
}

if(ESP_OK != esp_flash_init(hfspi))
{
printf("spi flash init failed!\r\n");
return -1;
}
以上代码会返回:
I (10602) spi_flash: detected chip: generic
W (10602) spi_flash: Detected flash size > 16 MB, but access beyond 16 MB is not supported for this flash model yet.
I (10612) spi_flash: flash io: dio
之后我了解到ESP32并不支持NAND FLASH,这样的信息是否表示SPI FLASH驱动已经正确运行并检测到了NAND FLASH?

所以根据以上测试,是否说明,SPICLK(GPIO30)、SPIQ(GPIO31)、SPID(GPIO32)这三个IO并不适合连接NAND FLASH,如果要连接NAND FLASH,应该使用其他IO并使用SPI2/3总线,这样的结论是否正确?是否有其他办法在SPI1总线上使用NAND FLASH?

Who is online

Users browsing this forum: No registered users and 60 guests