espressif / arduino-esp32

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

HardwareSerial at 460800 BAUD not working #10161

Closed mettatec closed 3 months ago

mettatec commented 3 months ago

Board

ESP32 Dev Module

Device Description

Custom hardware

Hardware Configuration

GPIO 16 and 17 used as UART HardwareSerial

Version

v3.0.4

IDE Name

Visual Studio Code

Operating System

Windows 11

Flash frequency

80MHz

PSRAM enabled

no

Upload speed

921600

Description

HardwareSerial at 460800 does not read data correctly when using ESP32-Arduino Core v3.

Sketch

#include <HardwareSerial.h>

HardwareSerial MySerial(1);
const int MySerialRX = 16;
const int MySerialTX = 17;

uint8_t rBuffer[2048]; 

void setup() 
{
    MySerial.begin(230400, SERIAL_8N1, MySerialRX, MySerialTX);
    Serial.begin(115200);
}

void loop() 
{
    while (MySerial.available() > 0) {
        int s = MySerial.readBytes(rBuffer, sizeof(rBuffer));
          Serial.write(rBuffer, s);
    }
}

Debug Message

ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x13 (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:4832
load:0x40078000,len:16460
load:0x40080400,len:4
load:0x40080404,len:3504
entry 0x400805cc
[     3][D][esp32-hal-cpu.c:264] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
=========== Before Setup Start ===========
Chip Info:
------------------------------------------
  Model             : ESP32
  Package           : D0WD-Q5
  Revision          : 1.44
  Cores             : 2
  CPU Frequency     : 240 MHz
  XTAL Frequency    : 40 MHz
  Features Bitfield : 0x00000032
  Embedded Flash    : No
  Embedded PSRAM    : No
  2.4GHz WiFi       : Yes
  Classic BT        : Yes
  BT Low Energy     : Yes
  IEEE 802.15.4     : No
------------------------------------------
INTERNAL Memory Info:
------------------------------------------
  Total Size        :   382312 B ( 373.4 KB)
  Free Bytes        :   351384 B ( 343.1 KB)
  Allocated Bytes   :    23716 B (  23.2 KB)
  Minimum Free Bytes:   346008 B ( 337.9 KB)
  Largest Free Block:   114676 B ( 112.0 KB)
------------------------------------------
Flash Info:
------------------------------------------
  Chip Size         : 16777216 B (16 MB)
  Block Size        :    65536 B (  64.0 KB)
  Sector Size       :     4096 B (   4.0 KB)
  Page Size         :      256 B (   0.2 KB)
  Bus Speed         : 80 MHz
  Bus Mode          : QIO
------------------------------------------
Partitions Info:
------------------------------------------
                nvs : addr: 0x00009000, size:    20.0 KB, type: DATA, subtype: NVS
            otadata : addr: 0x0000E000, size:     8.0 KB, type: DATA, subtype: OTA
               app0 : addr: 0x00010000, size:  3072.0 KB, type:  APP, subtype: OTA_0
               app1 : addr: 0x00310000, size:  3072.0 KB, type:  APP, subtype: OTA_1
               ffat : addr: 0x00610000, size: 10112.0 KB, type: DATA, subtype: FAT
           coredump : addr: 0x00FF0000, size:    64.0 KB, type: DATA, subtype: COREDUMP
------------------------------------------
Software Info:
------------------------------------------
  Compile Date/Time : Aug 14 2024 11:16:35
  Compile Host OS   : windows
  ESP-IDF Version   : v5.1.4-586-gb6b4727c58-dirty
  Arduino Version   : 3.0.4
------------------------------------------
Board Info:
------------------------------------------
  Arduino Board     : ESP32_DEV
  Arduino Variant   : esp32
  Arduino FQBN      : esp32:esp32:esp32:JTAGAdapter=default,PSRAM=disabled,PartitionScheme=app3M_fat9M_16MB,CPUFreq=240,FlashMode=qio,FlashFreq=80,FlashSize=16M,UploadSpeed=921600,LoopCore=1,EventsCore=0,DebugLevel=debug,EraseFlash=none,ZigbeeMode=default
============ Before Setup End ============
=========== After Setup Start ============
INTERNAL Memory Info:
------------------------------------------
  Total Size        :   382312 B ( 373.4 KB)
  Free Bytes        :   347616 B ( 339.5 KB)
  Allocated Bytes   :    26972 B (  26.3 KB)
  Minimum Free Bytes:   342240 B ( 334.2 KB)
  Largest Free Block:   114676 B ( 112.0 KB)
------------------------------------------
GPIO Info:
------------------------------------------
  GPIO : BUS_TYPE[bus/unit][chan]
  --------------------------------------  
     1 : UART_TX[0]
     3 : UART_RX[0]
    16 : UART_RX[1]
    17 : UART_TX[1]
============ After Setup End =============
$ÌVMCHhÖ,,,h((,,HhÎ,V*v7
$ÇGA,h((,,ph00,9z,99,Hh(,,*r4
$ÇSA,(1,,Hh(,,,h((,,z{.99,z;.99H{9.99h3.33

 GNGÃ(A,rh(,,,h((,,Hh(99.z;(99L{9,99l;9,2Lw0
$ÌGSAH(1,,h((,,Hh(,,,z;.99H{9.99h;9.9zh7*31

 GNÁ,A,r((,,Hh(,,,h((99L{9,99l;9,9zl99,4l76
@ÎGSAhÃ(1,Hh(,,,h((,,H{9.99h;9.9zh99.9z(1*3v
                                            $GP×V,1Hs(00,p,65
                                                             `ÇLGS(1,1Hp0,0*v;
$ÇSV,r(1,0ph0*74

 GBÖ,1,r(00,pl77
`ÇQGS´h1,1,p0(0*tp
$GÇWT,Hp.000p(918zs72,9r8953th0.00p0(37rp754,v7143rp(375p714*v
 GNR(,V,h((,,Hh(,N,,77
                      `ÇNGG((,,Hh0,00h;9.9zh(,,,h,16
                                                    `ÇNGS(A,1Hh(,,,h((,,Hh99.9z(99.z{(99.z;(1*vw
$GÇWA,h1,,,h((,,Hh(,,9z,99,z{.99,z;.99Ht.30
                                            GNG¶(A,1h((,,Hh(,,,h(99.z{(99.z;(99L{9,3*v3
$ÇSA,(1,,Hh(,,,h((,,z{.99,z;.99H{9.99h0.36

 GNGÃ(A,rh(,,,h((,,Hh(99.z;(99L{9,99l;9,5Lw7
$ÐGSVH3(1,0p(0*6r
                 $GL×V,1H3(00,p.79
                                   GAGS(1,1h00,0*w0
$ÄGSV,s(1,0p(0*77
                 $GQ×V,1,s(00,p,64
`ÇNGS(,V,h((,,Hh(,N,,77
                       `ÇNGG((,,Hh0,00h;9.9zh(,,,h,16
                                                     `ÇNGS(A,1Hh(,,,h((,,Hh99.9z(99.z{(99.z;(1*vw
$GÇWA,h1,,,h((,,Hh(,,9z,99,z{.99,z;.99Ht.30
                                            GNG¶(A,1h((,,Hh(,,,h(99.z{(99.z;(99L{9,3*v3
$ÇSA,(1,,Hh(,,,h((,,z{.99,z;.99H{9.99h0.36

 GNGÃ(A,rh(,,,h((,,Hh(99.z;(99L{9,99l;9,5Lw7
$ÐGSVHs(1,0p(0*6r
                 $GL×V,1Hs(00,p,79
                                  `ÇAGS(1,1Hp0,0*v0
$
 ÇSV,r(1,0ph0*77

 GQÖ,1,r(00,pl64
`ÇNGS°h(0.0p00,9rx9534h;189rw0,0.p000,vw1435p(775pw14,3v3035pl7E
$GÔIC,H(,,,h((,,H(V*3v
                      $GÇA,,h((,0Hp0,99l;9,,Hh(,*5t
                                                   $G×A,Ah3(,,Hh(,,,h((,9zl99,9z,99,z{.99,r,73
                                                                                              `ÇNGS(A,1Hh(,,,h((,,Hh99.9z(99.z{(99.z;(2*vp
$GÇWA,h1,,,h((,,Hh(,,9z,99,z{.99,z;.99Hw.31
                                            GNG¶(A,1h((,,Hh(,,,h(99.z{(99.z;(99L{9,4*v4
$ÇSA,(1,,Hh(,,,h((,,z{.99,z;.99H{9.99h3.37

 GPGÔ(1,rh00,0l41
@ÈGSVh3(1,pp(0*7z
                 $G×V,1h3(00Hp.74
                                  GBG¶(1,1h00,0Lw7
$ÓGSVHs(1,0p(0*6p
                 $GN×P,,pl0000h;189rw0,91x;134Hp.000p(775pw14,3v3035ph7754v30*7
                                                                                GN´Ç,,Vh((,,Hh(,,NhÔ.37

 GNGÃ(,,Hh(0,0p(99.z{(,,,h(.56

 GNGÃ(A,rh(,,,h((,,Hh(99.z;(99L{9,99l;9,1Lw7
$ÌGSAH(1,,h((,,Hh(,,,z9.99H;9.99h99.9z(6*30

 GN×A,A,s(,,,h((,,,h(,99l;9,99l99,9z,99,3l71
`ÇNGSAhÁ,1,h((,,,h(,,,h;9.99h99.9z(99.9{(4*3t
                                             $GN×A,Ah3(,,,h(,,,h((,99l99,9z,99,9{.99,r,77
`ÇPGS(1,1,p0,0*t3
$GÇSV,r(1,00h0*79

 GAGÖ,1,r(00,0l74
`ÇFGSVh1,1,p0(0*7w
$GÇWV,1h1,00h0.64
                  GNGÐ(,0.p000,z38953p(918z374,0l0000h7754vs0,37r0754Hw7543r0.7E

*t0
$GÇST,h0.000p(918z374,zs8953p(0.0pp0,37r0755Hw7543r3(37rp755*vÄ
@ÎRMCh(V,,Hh(,,,h(N,VLw7
$ÌGGAHh(,,,p(00,z{.99,h((,,Ls6
$ÌGSAH(1,,h((,,Hh(,,,z;.99H{9.99h;9.9zh1*33

 GNÁ,A,r((,,Hh(,,,h((99L{9,99l;9,9zl99,2l70
@ÎGSAhÃ(1,Hh(,,,h((,,H{9.99h;9.9zh99.9z(7*3r
                                            $GN×A,AHs(,,,h((,,Hh(,99l;9,9zl99,9z,99,pl76
`ÇNGShÁ,1,h((,,Hh(,,,h;9.9zh99.9z(99.z{(5*3v
                                            $G°×V,1h3(00Hp.65
                                                              GLG¶(1,1h00,0Lw9
$ÃGSVHs(1,0p(0*7p
                 $GB×V,1Hs(00,p,77
                                  `ÇQGS(1,1Hp0,0*t0
$ÇST,h0.00pp(918z374,zs8953p(0.0pp0,37r0755Hw7543r3(37rp755*vÄ
@ÎRMCh(V,,Hh(,,,h(N,VLw7
$ÌGGAHh(,,,p(00,z{.99,h((,,Ls6
$ÌGSAH(1,,h((,,Hh(,,,z;.99H{9.99h;9.9zh1*33

 GNÁ,A,r((,,Hh(,,,h((99L{9,99l;9,9zl99,2l70
@ÎGSAhÃ(1,Hh(,,,h((,,H{9.99h;9.9zh99.9z(7*3r
                                            $GN×A,AHs(,,,h((,,Hh(,99l;9,9zl99,9z,99,pl76
`ÇNGShÁ,1,h((,,Hh(,,,h;9.9zh99.9z(99.z{(5*3v
                                            $G°×V,1h3(00Hp.65
                                                              GLG¶(1,1h00,0Lw9
$ÃGSVHs(1,0p(0*7p
                 $GB×V,1Hs(00,p,77
                                  `ÇQGS(1,1Hp0,0*t0
$ÇST,h0.00pp(918z374,zs8953p(0.0pp0,37r0755Hw7543r3(37rp755*vÄ
`ÇNRM((V,Hh(,,,h((N,´l77
`ÇNGGh(,,,h0(00H{9.99h((,,Hl16
`ÇNGShÁ,1,h((,,Hh(,,,h;9.9zh99.9z(99.z{(1*3v
                                            $G×A,Ah3(,,Hh(,,,h((,9zl99,9z,99,z{.99,t,70
                                                                                       `ÇNGS(A,1Hh(,,,h((,,Hh99.9z(99.z{(99.z;(3*vs
$GÇWA,h1,,,h((,,Hh(,,9z,99,z{.99,z;.99Hp.36
                                            GNG¶(A,1h((,,Hh(,,,h(99.z{(99.z;(99L{9,5*v7
$SV,r(1,0ph0*65

 GLÖ,1,r(00,pl79
`ÇAGS´h1,1,p0(0*vp
$G
  ÇWV,rh1,00h0.77

 GQGÔ(1,rh00,0l40
@ÎGSTh(0.0pp0,91x;134H{1895v0(0.pp00,3v3035rh7754v31,3vs0355l7F
$GÔIC,H(,,,h((,,H(V*3v
                      $GÇGA,Hh(,,0h00,9zl99,,h((,*rt
$GÇWA,h1,,,h((,,Hh(,,9z,99,z{.99,z;.99Hs.33
                                            GNG¶(A,1h((,,Hh(,,,h(99.z{(99.z;(99L{9,2*v0
$ÇSA,(1,,Hh(,,,h((,,z{.99,z;.99H{9.99h7.31

 GNGÃ(A,rh(,,,h((,,Hh(99.z;(99L{9,99l;9,4Lw6
$ÌGSAH(1,,h((,,Hh(,,,z;.99H{9.99h;9.9zh1*37

 GPÖ,1,r(00,pl65
`ÇHGS´h1,1,p0(0*v{
$GÇWV,rh1,00h0.74

 GBGÔ(1,rh00,0l77
@ÑGSVh3(1,pp(0*6p
                 $G×T,,p,000ph9189r70,9rx9534h0.00pp(375p715,vw1435r(775pw15*7

                                                                               GNRÇ(,VHh(,,,h((,NH.37
                                                                                                      GNG(,,,h(0,0ph99.9z((,,Hh.56
  GNG¶(A,1h((,,Hh(,,,h(99.z{(99.z;(99L{9,1*v7
$ÇSA,(1,,Hh(,,,h((,,z{.99,z;.99H{9.99h4.30

 GNGÃ(A,rh(,,,h((,,Hh(99.z;(99L{9,99l;9,3Lw1
$ÌGSAH(1,,h((,,Hh(,,,z;.99H{9.99h;9.9*7v
                                        $GQ×V,1Hs(00,p,64
                                                         `ÇNGS(,V,h((,,,h(,N,,77
`ÇNGG((,,,h0,00h;9.99h(,,,h,1

---------------------------------
Correct Messages should be:
$GNGST,,0.0000,9189718,9189718,0.0000,3754429,3754429,3754429*73
$GNRMC,,V,,,,,,,,,,N,V*37
$GNGGA,,,,,,0,00,99.99,,,,,,*56
$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99,1*33
$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99,2*30
$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99,3*31
$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99,4*36
$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99,5*37
$GPGSV,1,1,00,0*65
$GLGSV,1,1,00,0*79
$GAGSV,1,1,00,0*74
$GBGSV,1,1,00,0*77
$GQGSV,1,1,00,0*64

Other Steps to Reproduce

Tried with ESP32-Arduino Core v2 and it works OK.

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

me-no-dev commented 3 months ago

What happens if you:

void loop() 
{
    while (MySerial.available() > 0) {
          Serial.write(MySerial.read());
    }
}
mettatec commented 3 months ago

Tried already. Same result

me-no-dev commented 3 months ago

I know for certain that the baudrates work fine. You can try with running Serial at that baud instead of 115200. Is it possible that your GPS requires maybe different UART config? Parity or Stop bits?

mettatec commented 3 months ago

Same code with esp32 core V2 works well.

me-no-dev commented 3 months ago

@SuGlider PTAL

mettatec commented 3 months ago

The program works OK at 230400 baud. Is there any change in the clock source for UART in new core v3?

SuGlider commented 3 months ago

The program works OK at 230400 baud. Is there any change in the clock source for UART in new core v3?

Yes, for 3.0.4 we changed the UART clock source to 2MHz (REF_TICK), which seems not to work correctly for 460800.

There is a test for the baud rate. When it is higher than 1 Mbps, it uses this clock source. I'll post a PR limiting it to 250 Kbps for the ESP32 and ESP32-S2, higher than that it shall use APB as clock source.

mettatec commented 3 months ago

I did the chage from the PR post (core 3.0.4 in my local files) and it works OK now. Thanks!