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

Support for SPI0 in SPI library #1062

Closed
Shibonja opened this issue Nov 20, 2015 · 22 comments
Closed

Support for SPI0 in SPI library #1062

Shibonja opened this issue Nov 20, 2015 · 22 comments

Comments

@Shibonja
Copy link

Shibonja commented Nov 20, 2015

Hi guys,

First of all Thanks for the good work, you made development much easier with esp integration with Arduino IDE.
I have one question if someone can answer on them.

  1. are the extra SPI pins on esp-12e supported in Arduino IDE and if yes are they using bit-banging.

ESP8226-12E https://www.adafruit.com/products/2491

Thanks in advance, Haris.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@Shibonja Shibonja changed the title Hardware SPI Hardware SPI on esp8266-12e Nov 20, 2015
@igrr
Copy link
Member

igrr commented Nov 20, 2015

SPI library uses hardware HSPI (a.k.a. SPI1) peripheral (pins 12-15).
Extra pins on ESP-12E are connected to SPI0 peripheral, which is not supported by SPI0 library at the moment.

@Shibonja
Copy link
Author

Hi @igrr ,
Thanks for quick answer.
Are you planning to add support for them in future releases?

@igrr
Copy link
Member

igrr commented Nov 20, 2015

Actually I did implement this in a hacky manner about a month ago, need to revisit these changes and clean up the code.

@igrr igrr changed the title Hardware SPI on esp8266-12e Support for SPI0 in SPI library Nov 20, 2015
@igrr igrr added this to the 2.1.0 milestone Nov 20, 2015
@Shibonja
Copy link
Author

Hi @igrr ,
I ordered a few ESP8226-12E, so if u need any help, maybe I can be at your service, also I am not a C/C++ guru but I can find my way around.

@Links2004
Copy link
Collaborator

is SPI0 not shared with the flash?
so all the SPI code need to be in ram,
may gives problems with other interrupts too?

@igrr
Copy link
Member

igrr commented Nov 20, 2015

Actually this is done as follows: you are still using SPI1 peripheral (i.e. registers are the same), but its pins are mapped to the same pins as SPI0. There is a hardware arbiter which can demultiplex two SPI peripherals to the same physical set of pins, controlling two CS lines automatically. SPI0 has higher priority, so flash requests are still serviced, and you can use cached code. Access times via SPI1 become a bit unpredictable in this mode, but you can have an SPI peripheral and keep pins 12-15 free at the same time.

@reaper7
Copy link
Contributor

reaper7 commented Nov 22, 2015

@igrr - very interesting...is there any chance for tests this solution?

@steffenmauch
Copy link

@igrr Is there any possiblity to test your solution?

@KaloNK
Copy link
Contributor

KaloNK commented Dec 23, 2015

+1 for this feature.

Will it be possible to switch SPI1 between hardware and pins 12-15 at runtime?

I was looking for something similar to https://github.com/espressif/esp8266_mp3_decoder implementation for SPI SRAM (or FRAM ) chip access.
The idea is to use the same pins in SQI mode or better yet in SDI mode with the CS0 attached to the HOLD, so flash access will not interfere with a RAM stream if interrupted and still have the pins 12-15 as dedicated SPI for other devices ... as if there are 3 SPI:
SPI0 - flash
SPI1 - user (pins 12-15)
SPI2 - RAM in SDI mode, paralel to the flash, but with user defined CS

@KaloNK
Copy link
Contributor

KaloNK commented Jan 13, 2016

Actually I did implement this in a hacky manner about a month ago, need to revisit these changes and clean up the code.

@igrr shouldn't it be enough to call hspi_dev_sel() ( esp_iot_sdk
\examples\driver_lib\driver\spi_overlap.c ) inside beginTransaction()?
It can actually replace the while(SPI1CMD & SPIBUSY) {} call as it uses WAIT_HSPI_IDLE() macro which does the same.
So when we use HSPI we call hspi_dev_sel(0) and for RAM we call hspi_dev_sel(2) which will use GPIO0 (1 for GPIO1 is an option, but as it is TX0 can't be used). Settings should be extended with the mode (DIO or QIO) in addition to the spi dev used.

If such approach is acceptable I can try to modify the SPI driver in a backward compatible way and post a pull request with the changes.

EDIT: CS1 can also be used by moving TX0 to GPIO2 - #1424

@KaloNK
Copy link
Contributor

KaloNK commented Jan 26, 2016

I have made a patch to implement this based on the SDK example code e011d38 but it is not tested yet, because I am still waiting for the SRAM chip.
I am about to add support for (S/F/M)RAM attached parallel to the flash in (S/D/Q)IO modes too, but i guess it should be separate patch.

EDIT: created dedicated branches for the changes. SPI_RAM library is also added, but still untested

@igrr igrr modified the milestones: 2.2.0, 2.1.0 Feb 27, 2016
@igrr igrr modified the milestones: 2.2.0, 2.3.0 Apr 18, 2016
@igrr igrr modified the milestones: 2.3.0, 2.4.0 Jun 3, 2016
@igrr igrr added the bounty label Jun 22, 2016
@whhsn
Copy link

whhsn commented Jul 19, 2016

@KaloNK
Copy link
Contributor

KaloNK commented Jul 19, 2016

I have some code here and here, but couldn't make it work with SRAM ( 23LC1024 ) attached to the same bus as flash (it does not read anything from SPI0 for some reason). I do not have a logic analyzer, so it is difficult to debug what is happening.
I will come back to this some time later, but if someone can review the code and see a mistake there causing it not to work, will help a lot

@igrr
Copy link
Member

igrr commented Jul 19, 2016

@KaloNK, thank you for your work.
FYI, there is a $250 bounty on this issue.

@mkeyno
Copy link

mkeyno commented Jul 20, 2016

@igrr can you elaborate, regards to this topic, what feature will be added to the ESP8266? if new HW SPI will be available for user , it is only break out on ESP-12E and not break out for most current available module in market

@boks21
Copy link

boks21 commented Jan 3, 2017

Hi,
im' new using esp8266 with spi( i used it with uart)

Now i need use esp12E with (H)SPI and im doing first steps and have some doubts:

Its factory ready to use HSPI? or i need to reprogram?
Some special pin conections to use HSPI?

Someone knows registers adress to write/read data to Wi-Fi?

Thanks a lot,

Loureiro

@igrr
Copy link
Member

igrr commented May 8, 2017

Implemented in #3189.

@riataman please go to bountysource to claim your bounty.

@igrr igrr closed this as completed May 8, 2017
igrr added a commit that referenced this issue May 14, 2017
- 9fd270f Documenting a few Esp.cpp methods (#3057)
- 2881e91 Fix typo in client-class.md (#3045)
- 97373e7 Add instructions how to re-enable DHCP (#2600)
- af0f5ed Issue #1062: Implement support for HSPI overlap mode.
- ca3a172 Addition of gen4-IoD Range boards (#3202)
- d2b370b add AsyncPing library to libraries.md (#2889)
- adeed6b Updated arduino-esp8266fs-plugin link to 0.3.0 (#2846)
- b701b98 Update libraries.md (#2808)
- 898d280 Update readme.md (#2809)
- remove newlines from ota_updates/readme.rst
@WillyKirsch
Copy link

Hi, I'm trying to use the SPI library to read an SD card, with the previous version (without the PSI.pins() method) and worked fine, now with the SPI.Pins() method, I'm having this error when compile:

...esp8266\2.3.0\libraries\SPI\SPI.cpp:132:52: error: 'SPIPCS2DIS' was not declared in this scope

             SPI1P |= SPIPCS1DIS | SPIPCS0DIS | SPIPCS2DIS;

in any line where that names are used.

can anybody help me?

thanks!!

@usonix
Copy link

usonix commented Feb 5, 2018

Hi, I'm new here and also not very experienced in programming, I read what is described above, but it was not very clear to me. What I need is to use the SD card on the SPI0 pins, leaving the SPI1 pins free for other applications, if not ask too much, could someone publish an example code how to do this?

@pablo-mendoza
Copy link
Contributor

I never got around getting a SD card working in SPI0 (I did got a SPI memory workking), I think the sd card library would need changes to make it work.

I didn't had the proper tools at the time to try and debug this and right now I lack to time :(

@javadhabibi1500
Copy link

Except power-up, when the esp needs to use flash memory through SPi0? In other words, when my overlaped SPI is busy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests