Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FSPI and ESP32-S2 #9210

Closed
1 task done
vincentfenet opened this issue Feb 5, 2024 · 10 comments · Fixed by #9216
Closed
1 task done

FSPI and ESP32-S2 #9210

vincentfenet opened this issue Feb 5, 2024 · 10 comments · Fixed by #9216
Assignees
Labels
Type: Question Only question

Comments

@vincentfenet
Copy link

Board

ESP32-S2FN4R2

Device Description

none

Hardware Configuration

none

Version

latest master (checkout manually)

IDE Name

none

Operating System

none

Flash frequency

none

PSRAM enabled

yes

Upload speed

115200

Description

looks like this is not vaild for ESP32S2.

when i look at the ESP32S2 documentation:
Ports of embedded flash correspond to pins of ESP32-S2FH2 and ESP32-S2FH4 as follows:
–CS# = SPICS0
–DI = SPID
–DO = SPIQ
–CLK = SPICLK
–WP# = SPIWP
–HOLD# = SPIHD
Ports of embedded PSRAM correspond to pins of ESP32-S2FN4R2 and ESP32-S2R2 as follows:
–CE# = SPICS1
–SI/SIO0 = SPID
–SO/SIO1 = SPIQ
–SCLK = SPICLK
–SIO2 = SPIWP
–SIO3 = SPIHD
These pins are not recommended for other uses

could you please fix this ?
thanks,
vincent

Sketch

none

Debug Message

none

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@vincentfenet vincentfenet added the Status: Awaiting triage Issue is waiting for triage label Feb 5, 2024
@lbernstone
Copy link
Contributor

Please explain better what the issue is, and what you believe the fix would be. The default for SPI is to use HSPI, which will not use the SPI flash pins. However, they are available if you have a valid use case.

@SuGlider SuGlider self-assigned this Feb 5, 2024
@SuGlider SuGlider added Type: Question Only question and removed Status: Awaiting triage Issue is waiting for triage labels Feb 5, 2024
@SuGlider
Copy link
Collaborator

SuGlider commented Feb 5, 2024

looks like this is not vaild for ESP32S2.

This is perfectly valid.
#define FSPI 1 is the index of SPI Class Structure, not the SPI1 port as described in the ESP32-S2 Datasheet.

From esp32-hal-spi.c Lines 129 to 133 - ESP32S2 maps the SPI peripherals.

static spi_t _spi_bus_array[] = {
#if CONFIG_IDF_TARGET_ESP32S2
    {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), 0, -1, -1, -1, -1},
    {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 1, -1, -1, -1, -1},
    {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 2, -1, -1, -1, -1}

From libraries/SPI/src/SPI.cpp Lines 74 to 85 - ESP32S2 maps SPI object to use FSPI (ESP32-S2 SPI2)

#if CONFIG_IDF_TARGET_ESP32
SPIClass SPI(VSPI);
#else
SPIClass SPI(FSPI);
#endif

@SuGlider
Copy link
Collaborator

SuGlider commented Feb 5, 2024

These pins are not recommended for other uses
could you please fix this ?
thanks,
vincent

I don't see anything to fix. Please let me know if you disagree and explain how is it wrong.

@vincentfenet
Copy link
Author

sorry, i was speaking about the comment: "SPI bus attached to the flash (can use the same data lines but different SS)"
on ESP32S2 the flash is not attached to the FSPI bus

@SuGlider
Copy link
Collaborator

SuGlider commented Feb 5, 2024

sorry, i was speaking about the comment: "SPI bus attached to the flash (can use the same data lines but different SS)" on ESP32S2 the flash is not attached to the FSPI bus

Yes, correct, but FSPI (ESP32-S2 SPI2) can be used to control external flash / psram, if necessary.
Arduino SPI class is just for General Purpose use with a MISO/MOSI/CLK/CS pins.

ESP32-S2N4R2 uses SPI0 for controlling internal SoC Flash (4MB) and the SPI1 for controlling the internal SoC (2MB) PSRAM.
The GPIOs for those 2 memories are not exposed to users in the chip.

In order to use SPI2 (Arduino FSPI) to access external memory, I'd suggest to use IDF calls instead and not use Arduino SPI Class.
Please check this discussion: #8479
A possible code for your application may be related to #8479 (comment)

IDF Flash SPI API is described here:
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/spi_flash/index.html
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/spi_flash/spi_flash_optional_feature.html

Related IDF examples:
https://github.com/espressif/esp-idf/tree/master/examples/storage/custom_flash_driver
https://github.com/espressif/esp-idf/tree/master/examples/storage/ext_flash_fatfs

In order to use IDF + Arduino, it would be necessary to create an Arduino as IDF Component Application.

@vincentfenet
Copy link
Author

vincentfenet commented Feb 5, 2024

i have no problem using it, it's just that the comments are wrong.

I expect something like this:

#define FSPI  1 //SPI bus. ESP32S2: for external flash only (can use the same data lines but different SS)
#define HSPI  2 //SPI bus. ESP32S2: external flash or device (normally mapped to pins 12 - 15, but can be matrixed to any pins)
#if CONFIG_IDF_TARGET_ESP32
#define VSPI  3 //SPI bus. ESP32S2: device only (normally attached to pins 5, 18, 19 and 23, but can be matrixed to any pins)

@SuGlider
Copy link
Collaborator

SuGlider commented Feb 5, 2024

OK. It sounds good for the ESP32-S2. I'll change the code to reflect this description and commentaries.
I'd just change it to say "external memory" instead of "external flash" given that it can be used for psram as well.

@SuGlider
Copy link
Collaborator

SuGlider commented Feb 5, 2024

We shall also consider that those code lines about FSPI and HSPI are valid for ESP32 too.

@SuGlider
Copy link
Collaborator

SuGlider commented Feb 5, 2024

@vincentfenet Check the changes in https://github.com/espressif/arduino-esp32/pull/9216/files and let me know if you agree to them. Thanks!

@vincentfenet
Copy link
Author

i totaly agree with this. thanks for your cooperation !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Question Only question
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants