November 07, 2024, 08:55:14 PM

How to get started with the ESP32-Pro

Started by Bumbum, November 19, 2021, 06:46:06 PM

Previous topic - Next topic

Bumbum

Hello Lub,

thank you. On my journey until here I have learned a lot about the board and have understood the combination of the PIC and the ESP. But I have one question. I took a look on the PIC32-default-firmware example in the Arduino IDE. I guess this is the one you mention the serial bridge. I cannot see there in the code why I have to press "Enter" the first time (or receiving any data from PC-side) to activate the Serial communication.

Can you please explain why this step is neccessarry? I have fallen into the trap several times now during my development and wondered why I don't see any debug messages as I am used to with other Arduino projects. It is also illogical because the PIC is not restarted during a programming operation of the ESP32, yet you have to press Enter to restart communication after an update?

best regards
Bumbum

Bumbum

Hello Lub,

I have done some more investigatin. I guess I have found the reason:

Serial.begin(1000000);

Is this neccessarry for programming the ESP32? If not, can you please make me a combined bootloader with serial-bridge with the following code? I guess this will solve all my problems:

int DTR=5; // PIC32 UART1 DTR pin
int RTS=4; // PIC32 UART1 RTS pin

bool dtr; // old DTR value
bool rts; // old RTS value

int baud=115200; //Default baudrate to start communication with

/* Read DTR/RTS signals sent from PC and toggle PIC32's DTR/RTS pins */
void readback()
{
  if (dtr != Serial.getDTR())
    {
      dtr = Serial.getDTR();
      if (dtr)
        digitalWrite(DTR, LOW);
      else
        digitalWrite(DTR, HIGH);

    }

  if (rts != Serial.getRTS())
    {
       rts = Serial.getRTS();

       if(rts)
          digitalWrite(RTS,LOW);
       else
          digitalWrite(RTS,HIGH);
    }
 
}


void setup() {

 //GPIO Setup:
 pinMode(DTR,OUTPUT);
 pinMode(RTS,OUTPUT);
 digitalWrite(RTS, LOW);
 digitalWrite(DTR, HIGH);
 delay(100);
 digitalWrite(RTS, HIGH);

 ANSELC = 0x00;
 LATC = LATC & (~0x04);
 TRISC |= 0x04;
// CNPUC = CNPUC & (~0x04);
 
 // Get USB DTR/RTS levels and store them for now
 dtr = Serial.getDTR();
 rts = Serial.getRTS();

 //Check for any level changes
 if (dtr) digitalWrite(DTR, LOW);
 else digitalWrite(DTR,HIGH);

 if(rts) digitalWrite(RTS, LOW);
 else digitalWrite(RTS,HIGH);

 //Set-up USB Serial port
 Serial.begin(baud);
 delay(100);
 //Setup UART1
 Serial0.begin(baud);
 delay(100);
}

void loop()
{
  /* First read the RTS/DTR levels of USB communication with PC
     Then toggle the RTS/DTR pins if any change */
     
     readback();
 
  while(Serial.available() || Serial0.available())
  {
    if (Serial.available())
    {
      Serial0.write(Serial.read());
    }
   
    if (Serial0.available())
    {
      Serial.write(Serial0.read());
    }
 
  }

  // Check if any baud changes on the USB side and change the UART1's baudrate
    if (Serial.getBaudRate() != baud)
    {
        baud = Serial.getBaudRate(); 
        Serial0.begin(baud);
               
    }
   
}

best regards
Andreas

LubOlimex

I have no idea why this happens and we will investigate. However, what you proposed doesn't fix it, I tested today.

Maybe the problem is either in the reset after programming or of the PIC32 pins are set improperly and affect bootstrap of ESP32.
Technical support and documentation manager at Olimex

Bumbum

Hello Lub,

thank you for testing. Will you update this topic if you have found the reason?

best regards
Andreas

LubOlimex

For the moment, can you try using RTS or RTS/CTS flow control and let me know how it goes.
Technical support and documentation manager at Olimex

LubOlimex

#20
I believe the firmware of the PIC32 that acts as serial bridge is made with RTS flow control in mind. You need to use another serial monitor software not the Arduino Serial Monitor (since I can't figure out how to change hardware flow control in Arduino Serial Monitor, maybe it is possible tho). Important! Opening Arduino IDE Serial Monitor and then closing it will probably bug the ESP32-PRO USB. My advice is to completly avoid opening or closing it when using ESP32-PRO. Just use another terminal (like PuTTY) and make sure to set RTS/CTS hardware flow control of the COM port.

Unfortunately, I don't think it would be good idea to try to fix that in the firmware of the PIC32 since this would also require changing the USB libraries for Arduino and changing those will make all other Arduino boards not working via USB.
Technical support and documentation manager at Olimex

Bumbum

Hello,

sorry for my late reply. I have tested with Hyperterminal. If I set flow control to hardware it is working. After I connect I immediately receive data from the Olimex-Board. If I set flow control to "none" I get no data at all, also not after I press enter. I have to restart the Olimex board after this try to receive any data at all.

But I have not found an option to reconfigure the Arduino serial monitor to use hardware flow control. Can somebody help?

Using another terminal for debugging is of course no solution, it makes the problem even more complex. Just pressing enter in the Arduion Serial is way simpler then disconnecting from the terminal, flashing the board with the Arduino IDE and then reconnecting the terminal.

best regards
Bumbum

donwynne

Thank you, I have learned a lot of your board.