Baudrate changes after boot

asqwas
Posts: 4
Joined: Mon Jan 06, 2025 5:26 pm

Baudrate changes after boot

Postby asqwas » Mon Jan 06, 2025 5:41 pm

Hello there,

I am using an ESP32 TTGO Lora Oled V1 and uploaded this simple sketch

Code: Select all

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
  delay(5000);
}
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);  
  Serial.println("on");
  delay(1000);                      
  digitalWrite(LED_BUILTIN, LOW);  
    Serial.println("off");
  delay(1000);                       
}
The board boots and the serial monitor shows this:

rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:4604
ho 0 tail 12 room 4
load:0x40078000,len:15488
load:0x40080400,len:4

but then immediately after the serial monitor only shows gibberish.
Only after changing the baudrate in the serial monitor to 74880 the 'on'... 'off' shows up correctly.

I also tried setting the baudrate to a different value but the problem is the same.
The baudrate during boot stays 115200 but after it is one baudrate step lower than selected. With low baudrates like 9600 it doesn't work at all.
As a board I selected TTGO LoRa32-OLED in the Arduino IDE. There are 3 board revisions and I tried all of them.
I also tried different USB-Calbes. I have two of these boards and the problem is the same with both of them. 2 weeks ago both of them worked fine. I think it is pretty unlikely that both of them broke at the same time.

I tried the same code with a Heltec WIfi Lora32 V3.2 board an this one doesn't have any problems.
can anyone help? What's going on here?

lbernstone
Posts: 886
Joined: Mon Jul 22, 2019 3:20 pm

Re: Baudrate changes after boot

Postby lbernstone » Tue Jan 07, 2025 6:15 pm

Set your preferences in Arduino to show verbose output during upload. You should then be able to see where esptool connects to the device during an upload, and it will show the crystal frequency. 26MHz clock was deprecated in arduino-esp32 at some point (2.0.10?). These devices will still be functional with ESP-IDF.

asqwas
Posts: 4
Joined: Mon Jan 06, 2025 5:26 pm

Re: Baudrate changes after boot

Postby asqwas » Tue Jan 07, 2025 11:26 pm

Thank you for your help.
This is what I got during the upload with debugging
Sketch uses 306564 bytes (23%) of program storage space. Maximum is 1310720 bytes.
Global variables use 20048 bytes (6%) of dynamic memory, leaving 274864 bytes for local variables. Maximum is 294912 bytes.
esptool.py v4.8.1
Serial port COM3
Connecting....
Chip is ESP32-D0WDQ6 (revision v1.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 26MHz
MAC: ac:67:b2:1a:6e:f0
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Flash will be erased from 0x00001000 to 0x00006fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x0005afff...
Compressed 23440 bytes to 15065...
Writing at 0x00001000... (100 %)
Wrote 23440 bytes (15065 compressed) at 0x00001000 in 0.6 seconds (effective 321.1 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 146...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (146 compressed) at 0x00008000 in 0.1 seconds (effective 184.4 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.2 seconds (effective 419.4 kbit/s)...
Hash of data verified.
Compressed 306928 bytes to 162577...
Writing at 0x00010000... (10 %)
Writing at 0x0001c671... (20 %)
Writing at 0x000297ed... (30 %)
Writing at 0x0002ed92... (40 %)
Writing at 0x0003491d... (50 %)
Writing at 0x00039dbe... (60 %)
Writing at 0x0003f3d2... (70 %)
Writing at 0x00044a0d... (80 %)
Writing at 0x0004c0df... (90 %)
Writing at 0x00055672... (100 %)
Wrote 306928 bytes (162577 compressed) at 0x00010000 in 3.8 seconds (effective 639.2 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

So this ESP32 doesn't work with Arduino IDE?
Would it still work if I use an older version?

lbernstone
Posts: 886
Joined: Mon Jul 22, 2019 3:20 pm

Re: Baudrate changes after boot

Postby lbernstone » Wed Jan 08, 2025 4:28 am

Try adding `#define F_XTAL_MHZ 26` at the beginning of your code.
If that doesn't work then try using v2.0.17.

asqwas
Posts: 4
Joined: Mon Jan 06, 2025 5:26 pm

Re: Baudrate changes after boot

Postby asqwas » Wed Jan 08, 2025 12:16 pm

Here is the new code:

Code: Select all

#define F_XTAL_MHZ 26

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
  delay(5000);
}
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);  
  Serial.println("on");
  delay(1000);                      
  digitalWrite(LED_BUILTIN, LOW);  
    Serial.println("off");
  delay(1000);                       
}

and this is what I get during upload

Sketch uses 296068 bytes (22%) of program storage space. Maximum is 1310720 bytes.
Global variables use 20048 bytes (6%) of dynamic memory, leaving 274864 bytes for local variables. Maximum is 294912 bytes.
esptool.py v4.8.1
Serial port COM3
Connecting....
Chip is ESP32-D0WDQ6 (revision v1.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 26MHz
MAC: ac:67:b2:1a:6e:f0
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Flash will be erased from 0x00001000 to 0x00006fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x00058fff...
Compressed 23440 bytes to 15065...
Writing at 0x00001000... (100 %)
Wrote 23440 bytes (15065 compressed) at 0x00001000 in 0.6 seconds (effective 325.2 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 146...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (146 compressed) at 0x00008000 in 0.1 seconds (effective 185.9 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.2 seconds (effective 319.1 kbit/s)...
Hash of data verified.
Compressed 296432 bytes to 158176...
Writing at 0x00010000... (10 %)
Writing at 0x0001bd6d... (20 %)
Writing at 0x0002884d... (30 %)
Writing at 0x0002decc... (40 %)
Writing at 0x00033a1a... (50 %)
Writing at 0x00038e78... (60 %)
Writing at 0x0003e4fa... (70 %)
Writing at 0x00043ba5... (80 %)
Writing at 0x0004b218... (90 %)
Writing at 0x00054738... (100 %)
Wrote 296432 bytes (158176 compressed) at 0x00010000 in 3.7 seconds (effective 643.1 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
The serial monitor still shows the messages at 74880

asqwas
Posts: 4
Joined: Mon Jan 06, 2025 5:26 pm

Re: Baudrate changes after boot

Postby asqwas » Wed Jan 08, 2025 12:57 pm

I now downgraded the esp32 library to the version you mentioned and that did the trick. Thank you very much.

I also want to link this post here: https://forum.arduino.cc/t/downgrade-fr ... /1272211/2
it explains how to downgrade the version and how to turn off the automatic upgrade suggestions, which is probably how I got into this mess.

lbernstone
Posts: 886
Joined: Mon Jul 22, 2019 3:20 pm

Re: Baudrate changes after boot

Postby lbernstone » Wed Jan 08, 2025 4:39 pm

It seems like the timing is not right for the fix with F_XTAL_MHZ (using board_opt.h). The easiest way that I can see to do this is to select CPU Frequency of 26MHz in the board menu, then add `setCpuFrequencyMhz(240);` at the top of your setup. That should work in both 2.0.17 and 3.x (and hopefully 4.x too :) )

Who is online

Users browsing this forum: Google [Bot] and 26 guests