user86069: Learning C with the Freenove WSP32-WROVER starter kit and there's an issue I cannot find an answer to. Using the provided code to input some data with UART, it would seem to have a strange behavior whenever I input string that is larger than 12 characters. Under 12, everything is fine.
/**********************************************************************
  Filename    : SerialRW
  Description : Use UART read and write data between ESP32 and PC.
  Auther      : www.freenove.com
  Modification: 2020/07/11
**********************************************************************/
String inputString = "";      //a String to hold incoming data
bool stringComplete = false;  // whether the string is complete

void setup() {
  Serial.begin(9600);
  Serial.println(String("\nESP32 initialization completed!\n")
                + String("Please input some characters,\n")
                + String("select \"Newline\" below and click send button. \n"));
}

void loop() {
  if (Serial.available()) {         // judge whether data has been received
    char inChar = Serial.read();         // read one character
    inputString += inChar;
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
  if (stringComplete) {
    Serial.printf("inputString: %s \n", inputString);
    inputString = "";
    stringComplete = false;
  }
}

The output of any larger than 12 characters string is sometimes a little bit different, but always seems to follow a similar pattern. For any 13 characters long string, I get :

⸮⸮?

The ouput changes if I add characters, for example 20 characters is this :

D⸮⸮?

I assume the unprintable character is a new line.
The baud rate is set at the same value both in the code and in the serial monitor and I get the same results if I change the baud rate.
Any explanation regarding this behaviour and how to avoid it would be most welcomed.

user70020: Change:
Serial.printf("inputString: %s \n", inputString);

to:
Serial.printf("inputString: %s \n", inputString.c_str());

%s expects a const char * which is not what inputString yields.
What you're seeing in the difference between strings larger and smaller than 12 characters is down to whether or not small string optimization is in use and how structures are passed in the ESP32's calling convention.

86069: <p>Learning C with the Freenove WSP32-WROVER starter kit and there's an issue I cannot find an answer to. Using the provided code to input some data with UART, it would seem to have a strange behavior whenever I input string that is larger than 12 characters. Under 12, everything is fine.</p>
<pre><code>/**********************************************************************
  Filename    : SerialRW
  Description : Use UART read and write data between ESP32 and PC.
  Auther      : www.freenove.com
  Modification: 2020/07/11
**********************************************************************/
String inputString = &quot;&quot;;      //a String to hold incoming data
bool stringComplete = false;  // whether the string is complete

void setup() {
  Serial.begin(9600);
  Serial.println(String(&quot;\nESP32 initialization completed!\n&quot;)
                + String(&quot;Please input some characters,\n&quot;)
                + String(&quot;select \&quot;Newline\&quot; below and click send button. \n&quot;));
}

void loop() {
  if (Serial.available()) {         // judge whether data has been received
    char inChar = Serial.read();         // read one character
    inputString += inChar;
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
  if (stringComplete) {
    Serial.printf(&quot;inputString: %s \n&quot;, inputString);
    inputString = &quot;&quot;;
    stringComplete = false;
  }
}
</code></pre>
<p>The output of any larger than 12 characters string is sometimes a little bit different, but always seems to follow a similar pattern. For any 13 characters long string, I get :</p>
<blockquote>
<p>⸮⸮?</p>
</blockquote>
<p>The ouput changes if I add characters, for example 20 characters is this :</p>
<blockquote>
<p>D⸮⸮?</p>
</blockquote>
<p>I assume the unprintable character is a new line.</p>
<p>The baud rate is set at the same value both in the code and in the serial monitor and I get the same results if I change the baud rate.</p>
<p>Any explanation regarding this behaviour and how to avoid it would be most welcomed.</p>
 70020: <p>Change:</p>
<pre class="lang-cpp prettyprint-override"><code>Serial.printf(&quot;inputString: %s \n&quot;, inputString);
</code></pre>
<p>to:</p>
<pre class="lang-cpp prettyprint-override"><code>Serial.printf(&quot;inputString: %s \n&quot;, inputString.c_str());
</code></pre>
<p><code>%s</code> expects a <code>const char *</code> which is not what <code>inputString</code> yields.</p>
<p>What you're seeing in the difference between strings larger and smaller than 12 characters is down to whether or not <a href="https://github.com/espressif/arduino-esp32/blob/2.0.4/cores/esp32/WString.h#L307-L313" rel="nofollow noreferrer">small string optimization</a> is in use and how structures are passed in the ESP32's calling convention.</p>
