espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.42k stars 7.37k forks source link

UART initialisation from cold boot sets crystal clock wrong #10388

Open emilfihlman opened 4 days ago

emilfihlman commented 4 days ago

Board

Sparkfun Thing Plus

Device Description

Just the breakout board without nothing (except oscilloscope probes on 16, 17 and gnd) on it and connected to the computer via usb

Hardware Configuration

Just the breakout board without nothing (except oscilloscope probes on 16, 17 and gnd) on it and connected to the computer via usb

Version

3.0.5

IDE Name

arduino-ide_nightly-20240928_Linux_64bit

Operating System

Debian 12.7 Linux hostname 6.1.0-25-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.106-3 (2024-08-26) x86_64 GNU/Linux

Flash frequency

80 MHz

PSRAM enabled

no

Upload speed

921600

Description

When connected to computer from no power, device initially starts with 3u period and then immediately switches to 4.5u

On reset button press (ie warm reboot), device stays at 3u period.

When connected to just a power plug from no power, device also stays at 3u period.

RMT is probably just a red herring here, it allows us to easily see a stable frequency at least.

Sketch

#define PIN 16

void setup()
{
    rmt_data_t rawData[]={{.duration0=1, .level0=0, .duration1=1, .level1=1}};
    pinMode(PIN, OUTPUT);
    rmtInit(PIN, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 1000000);
    rmtWriteLooping(PIN, rawData, RMT_SYMBOLS_OF(rawData));
}

void loop(){}

Debug Message

No messages

Other Steps to Reproduce

Tried multiple of the same device, unopened.

https://youtu.be/8VOk3C6BlFE video of issue

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

emilfihlman commented 4 days ago

And just to make it clear: I have rebooted my computer and reinstalled the esp32 package.

TD-er commented 4 days ago

What crystal frequency does your board use? 26 or 40 MHz?

emilfihlman commented 4 days ago

What crystal frequency does your board use? 26 or 40 MHz?

According to the datasheet (ESP32-WROOM-32D) it's supposed to be 40 MHz, but indeed this has some same characteristics as that bug that's supposedly fixed.

Even if it was 26 MHz, there's still another bug because it doesn't stay at one frequency.

emilfihlman commented 4 days ago

You also asked about PSRAM and pins 16 and 17.

No PSRAM and also I was under the impression that 16 and 17 were clean https://randomnerdtutorials.com/esp32-pinout-reference-gpios/

emilfihlman commented 4 days ago

And I should say I'm getting data at 74880 (well that works so it's close enough) when setting 115200 on Serial if using Serial.

TD-er commented 4 days ago

You also asked about PSRAM and pins 16 and 17.

No PSRAM and also I was under the impression that 16 and 17 were clean https://randomnerdtutorials.com/esp32-pinout-reference-gpios/

I did ask about PSRAM as it is my Pavlov reaction when I see ESP32-classic and GPIO-16/-17 being mentioned. (have been bitten by it myself several times) But then I noticed you had ticked the "no PSRAM" in the template, so I removed it from my post.

TD-er commented 4 days ago

And I should say I'm getting data at 74880 (well that works so it's close enough) when setting 115200 on Serial if using Serial.

Yep, 115200 ÷ 40 × 26 = 74880, which supports my hypothesis your board may be using a 26 MHz crystal.

emilfihlman commented 4 days ago

And I should say I'm getting data at 74880 (well that works so it's close enough) when setting 115200 on Serial if using Serial.

Yep, 115200 ÷ 40 × 26 = 74880, which supports my hypothesis your board may be using a 26 MHz crystal.

I mean yeah, but I can't for the life of me figure out how to definitely tell the software that it's 26 MHz. I tried putting that everywhere I could for many hours.

And in any case there are bloody 2 frequencies, both 74880 and 115200 depending on how it is rebooted AND how it is connected :D

I really don't know how I can run into issues like these T.T

emilfihlman commented 3 days ago

Like, I tried applying the fix from the mentioned issues, the only difference being adding the one define to the pins file in variants since everything else was already there.

But it still has the same behaviour.

me-no-dev commented 3 days ago

just to clarify: the only case where it switches to 4.5u is when you connect it to your computer? every other case results to 3u?

emilfihlman commented 2 days ago

just to clarify: the only case where it switches to 4.5u is when you connect it to your computer? every other case results to 3u?

As far as I can tell, yeah, that's the case. But like I didn't test mega extensively since it was already like 9 in the morning after a whole evening and night of debugging.

emilfihlman commented 2 days ago

You can see in the video my setup in case you didn't already watch it, it shows the extent and limits of my test.