Author Topic: ESP32: Cannot make HSPI work faster than 8MHz clock  (Read 329 times)

0 Members and 1 Guest are viewing this topic.

Offline rglory

  • Contributor
  • Posts: 15
  • Country: us
ESP32: Cannot make HSPI work faster than 8MHz clock
« on: May 02, 2021, 06:42:27 pm »
Hi there,

I am trying to make ESP32-CAM to stream video over ethernet, using ENC28J60 over SPI. I tried to use couple libraries, managed to make UIPEthernet work, but very very slow. So I decided to write my own simple implementation of IP/UDP stack. So far it works but I realized that if I try to use SPI freq higher than 8MHz I am getting data corruption. I am using HSPI with default pins. Is there limit for HSPI or I am missing something?

Thanks

PS I found this topic https://www.esp32.com/viewtopic.php?t=4688#:~:text=It%20is%20in%20fact%20capable,clock%20a%20lot%2C%20and%20impedance. which says:

Quote
My result:
in case use HSPI & VSPI mapped like this:
HSPI_CLK = 14 or 25 GPIO
HSPI_MOSI = 13 or 26 GPIO
HSPI_MISO = 12 or 32 GPIO
HSPI_CS = 15 or 33 GPIO

VSPI_CLK = 18 or 21 GPIO
VSPI_MOSI = 23 or 22 GPIO
VSPI_MISO = 19 or 19 GPIO
VSPI_CS = 05 or 23 GPIO

the maximum speed of CLK is 9 MHz.
So is it hardware limitation on HSPI interface?

PS sorry if offtopic, is this espressif company always that unfriendly? I tried to download their app to select ST23 chip - STM32Cube - it is convoluted process made so just so you cannot download it without registration. I can register fine but it does not work, so program which is in their interest to share is difficult to get. I tried to ask this question on their forum - it stays more than 24 hour for premoderation. I asked if it always so and they do not care about new people - they simply deleted my topic. Price for their devices is quite nice, but such attitude can easily compensate that.  |O
« Last Edit: May 02, 2021, 09:11:05 pm by rglory »
 

Offline pigrew

  • Frequent Contributor
  • **
  • Posts: 617
  • Country: us
Re: ESP32: Cannot make HSPI work faster than 8MHz clock
« Reply #1 on: May 02, 2021, 08:56:34 pm »
Your title shows STM32, so I started to think about them, but I think you're actually using an ESP32?

With the default pins (and good PCB layout), you should be able to get up to 80 MHz, or 40 MHz with the pin mux involved (according to the ESP-IDF documentation). I have not done it, but it should work.

It'd also be helpful for you to post a photo of your test setup.

Since I don't know many details of your setup, these are the things I'd first investigate. It's likely you are running into signal integrity issues.

  • Do you have good signal signal transmission lines/GND? You should have a GND net in parallel to your signal lines.
  • Maybe you need series termination resistors. Add a 22 or 33 ohm resistor in series to your signal line, close to the OUTPUT pin.
  • Is your clock polarity set properly? Confirm with an oscilloscope that the polarity of your clock is consistent with the Ethernet IC's datasheet.
  • Do you have a passive oscilloscope probe connected to your data or clock nets? If so, their extra 15 pF load can cause issues.
  • Do you have sufficient decoupling capacitors close to your ESP32 and SPI device power pins?

Use an active oscilloscope probe if you need to debug SI issues. Your oscilloscope preferably would have bandwidth >10 your clock rate. A logic analyzer (with low capacitance probes) could also be helpful.
 

Offline rglory

  • Contributor
  • Posts: 15
  • Country: us
Re: ESP32: Cannot make HSPI work faster than 8MHz clock
« Reply #2 on: May 02, 2021, 09:26:22 pm »
Your title shows STM32, so I started to think about them, but I think you're actually using an ESP32?
Ups, sorry, I've been playing with AVR and arduino before, so these names are new for me, so I get confused, fixed.

Quote
With the default pins (and good PCB layout), you should be able to get up to 80 MHz, or 40 MHz with the pin mux involved (according to the ESP-IDF documentation). I have not done it, but it should work.
I use already made PCBs:

ESP32-CAM I guess it is AI-Thinker variant: https://randomnerdtutorials.com/esp32-cam-ai-thinker-pinout/
HiLetgo ENC28J60 ENC28J60-I/SO HR911105A Ethernet LAN Network Module - https://www.amazon.com/gp/product/B00WX1NRO0/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

So I guess I do not have much choice on how good would be PCB Layout.


Quote
It'd also be helpful for you to post a photo of your test setup.

I have quite a mess on my table, but here it is

Quote
Since I don't know many details of your setup, these are the things I'd first investigate. It's likely you are running into signal integrity issues.

  • Do you have good signal signal transmission lines/GND? You should have a GND net in parallel to your signal lines.
  • Maybe you need series termination resistors. Add a 22 or 33 ohm resistor in series to your signal line, close to the OUTPUT pin.
  • Is your clock polarity set properly? Confirm with an oscilloscope that the polarity of your clock is consistent with the Ethernet IC's datasheet.
  • Do you have a passive oscilloscope probe connected to your data or clock nets? If so, their extra 15 pF load can cause issues.
  • Do you have sufficient decoupling capacitors close to your ESP32 and SPI device power pins?

Use an active oscilloscope probe if you need to debug SI issues. Your oscilloscope preferably would have bandwidth >10 your clock rate. A logic analyzer (with low capacitance probes) could also be helpful.
Ground connected through breadboard, where both PCBs gets power from.
I will try resistors.

Main thing disturbs me - I had them connected through breadboard, so I first thought about cables too. I connect them directly and no difference at all. If cables would be issue I could expect work 8MHz first case and maybe 10MHz on another, but no, it just works pretty well on 8 and works very bad - either hangs or a lot of errors on faster. And on topic I that person mentioned he also clains that HSPI cannot work faster than 9MHz.
 

Offline pigrew

  • Frequent Contributor
  • **
  • Posts: 617
  • Country: us
Re: ESP32: Cannot make HSPI work faster than 8MHz clock
« Reply #3 on: May 02, 2021, 10:42:26 pm »
The layout of that Ethernet module looks marginal. I would definitely try connecting the GND directly (without the breadboard), or route everything through the breadboard. How it is in the photo creates a large loop in the signal return path.

You are also operating somewhat close to the limits of those chips as you get closer to 20 MHz.

You want SPI mode 0. If you do 20 MHz, that's 50 ns per clock cycle. The controller outputs MOSI <10ns after the clocks falling edge. You're using the "IO mux pins" (the "default ones").

The ESP-IDF documentation states a Freq limit [MHz] = 80 / (floor(MISO delay[ns]/12.5) + 1). In your case the MISO delay would be (positive duration of the clock)+(10ns)+(a bit more, perhaps 10 ns?). With a symmetrical clock, this would be 20 MHz. So, it should work. You might be able to make the timing converge better if you use an asymmetric clock (with HIGH perhaps 25% of the clock period).

The ESP-IDF suggests that you also set the input_delay_ns parameter for your SPI config if you try to use >8MHz. I'd set it to (15ns + CLK_HIGH_TIME).
« Last Edit: May 02, 2021, 10:46:02 pm by pigrew »
 

Offline rglory

  • Contributor
  • Posts: 15
  • Country: us
Re: ESP32: Cannot make HSPI work faster than 8MHz clock
« Reply #4 on: May 03, 2021, 03:49:13 pm »
The layout of that Ethernet module looks marginal. I would definitely try connecting the GND directly (without the breadboard), or route everything through the breadboard. How it is in the photo creates a large loop in the signal return path.

That's where I started, connection was through breadboard, I thought maybe wires are too long plus breadboard has some parasitic capacity, so connected directly.

Quote
You are also operating somewhat close to the limits of those chips as you get closer to 20 MHz.
Yea, but it is less than a half, not even close :)

Quote
The ESP-IDF documentation states a Freq limit [MHz] = 80 / (floor(MISO delay[ns]/12.5) + 1). In your case the MISO delay would be (positive duration of the clock)+(10ns)+(a bit more, perhaps 10 ns?). With a symmetrical clock, this would be 20 MHz. So, it should work. You might be able to make the timing converge better if you use an asymmetric clock (with HIGH perhaps 25% of the clock period).

The ESP-IDF suggests that you also set the input_delay_ns parameter for your SPI config if you try to use >8MHz. I'd set it to (15ns + CLK_HIGH_TIME).

Will try thanks, though it is not too easy as I am using rduino framework and SPIClass interface, and those things not exposed directly.

The thing is - even on 8MHz on oscilloscope signal looks like analog, not digital. Similar way it was shown on the link I posted before.

Another thing on schematic you can see that those pins for HSPI also connected to SD Card module. That should not affecte them if there is no card inserted, should it?

https://www.reddit.com/r/esp32/comments/b6wyjt/aithinker_esp32cam_schematic/
 

Offline pigrew

  • Frequent Contributor
  • **
  • Posts: 617
  • Country: us
Re: ESP32: Cannot make HSPI work faster than 8MHz clock
« Reply #5 on: May 04, 2021, 12:50:53 am »
The thing is - even on 8MHz on oscilloscope signal looks like analog, not digital. Similar way it was shown on the link I posted before.

Another thing on schematic you can see that those pins for HSPI also connected to SD Card module. That should not affecte them if there is no card inserted, should it?

https://www.reddit.com/r/esp32/comments/b6wyjt/aithinker_esp32cam_schematic/

I'll assume that you have a <15pF probe and >100 MHz oscilloscope. It should look a bit better than that other post.

Another trick you could try (if your framework supports it) is to increase the pin drive strength (the ESP-IDF function is gpio_set_drive_capability(...)). With higher drive strength, it'll decrease the fall and rise times, but would be more likely to "ring".

I tend to suggest giving priority to making sure that your GND runs roughly parallel to your signal wires, leaving shortening wires as a secondary goal.

I probably should grab a ESP32 and see how it looks over here, and measure rise-fall times....
 

Offline rglory

  • Contributor
  • Posts: 15
  • Country: us
Re: ESP32: Cannot make HSPI work faster than 8MHz clock
« Reply #6 on: May 04, 2021, 09:18:21 pm »
I'll assume that you have a <15pF probe and >100 MHz oscilloscope. It should look a bit better than that other post.
No, I do not  :'( Little bit expensive toy for a hobby project.

Quote from: pigrew
Another trick you could try (if your framework supports it) is to increase the pin drive strength (the ESP-IDF function is gpio_set_drive_capability(...)). With higher drive strength, it'll decrease the fall and rise times, but would be more likely to "ring".
Will try, thanks, but it looks like more and more that it would be easier to use raspberry PI instead, it has camera and ethernet interface already, and I can use gpio to control LEDs. I thought it would be not bad idea to use this one as it is quite cheap and functional but underestimated luck of support...
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf