Skip to content

Commit

Permalink
Prefer Serial1 logging in examples (#9079)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcspr authored Feb 9, 2024
1 parent e6df345 commit d7d50ff
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

/*
SWAP_PINS:
0: use Serial1 for logging (legacy example)
0: use Serial1 for logging
1: configure Hardware Serial port on RX:GPIO13 TX:GPIO15
and use EspSoftwareSerial for logging on
standard Serial pins RX:GPIO3 and TX:GPIO1
Expand Down Expand Up @@ -90,6 +90,8 @@ void setup() {
logger->enableIntTx(false);
logger->println("\n\nUsing EspSoftwareSerial for logging");
#else
// Hardware serial0 is on RX(3)/TX(1)
// Hardware serial1 is on (no RX)/TX(2)
logger->begin(BAUD_LOGGER);
logger->println("\n\nUsing Serial1 for logging");
#endif
Expand Down
44 changes: 22 additions & 22 deletions libraries/esp8266/examples/SerialStress/SerialStress.ino
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@

/*
Serial read/write/verify/benchmark
Using internal loopback
Using EspSoftwareSerial library for logging
Using Serial0 for internal loopback
Using Serial1 for logging
Sketch meant for debugging only
Released to public domain
*/

#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>

#define SSBAUD 115200 // logger on console for humans
#define LOGBAUD 115200 // logger on console for humans
#define BAUD 3000000 // hardware serial stress test
#define BUFFER_SIZE 4096 // may be useless to use more than 2*SERIAL_SIZE_RX
#define SERIAL_SIZE_RX 1024 // Serial.setRxBufferSize()
Expand All @@ -21,6 +20,9 @@
#define TIMEOUT 5000
#define DEBUG(x...) // x

#define READING_PIN 4
#define TIMEOUT_PIN 5

uint8_t buf[BUFFER_SIZE];
uint8_t temp[BUFFER_SIZE];
bool reading = true;
Expand Down Expand Up @@ -51,18 +53,18 @@ void error(const char* what) {
void setup() {
pinMode(LED_BUILTIN, OUTPUT);

pinMode(READING_PIN, INPUT);
pinMode(TIMEOUT_PIN, INPUT);

Serial.begin(BAUD);
Serial.swap(); // RX=GPIO13 TX=GPIO15
Serial.setRxBufferSize(SERIAL_SIZE_RX);

// using HardwareSerial0 pins,
// so we can still log to the regular usbserial chips
SoftwareSerial* ss = new SoftwareSerial(3, 1);
ss->begin(SSBAUD);
ss->enableIntTx(false);
logger = ss;
Serial1.begin(LOGBAUD); // RX=NONE TX=GPIO2
logger = &Serial1;

logger->println();
logger->printf("\n\nOn Software Serial for logging\n");
logger->printf("\n\nOn Serial1 for logging\n");

int baud = Serial.baudRate();
logger->printf(ESP.getFullVersion().c_str());
Expand Down Expand Up @@ -140,15 +142,13 @@ void loop() {
timeout = (last_ms = now_ms) + TIMEOUT;
}

if (logger->available()) switch (logger->read()) {
case 's':
logger->println("now stopping reading, keeping writing");
reading = false;
break;
case 't':
testReadBytesTimeout ^= FAKE_INCREASED_AVAILABLE;
logger->printf("testing readBytes timeout: %d\n", !!testReadBytesTimeout);
break;
default:;
}
if (reading && (digitalRead(READING_PIN) == 0)) {
logger->println("now stopping reading, keeping writing");
reading = false;
}

if (digitalRead(TIMEOUT_PIN) == 0) {
testReadBytesTimeout ^= FAKE_INCREASED_AVAILABLE;
logger->printf("testing readBytes timeout: %d\n", !!testReadBytesTimeout);
}
}
4 changes: 2 additions & 2 deletions libraries/esp8266/examples/TestEspApi/TestEspApi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ extern "C" {
}
#endif

// Set up output serial port (could be a SoftwareSerial
// if really wanted).
// Set up output on the first serial port
// (can be any Stream, if needed)

Stream& ehConsolePort(Serial);

Expand Down
8 changes: 4 additions & 4 deletions libraries/lwIP_PPP/examples/PPPServer/PPPServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <lwip/dns.h>
#include <PPPServer.h>
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>

#ifndef STASSID
#define STASSID "your-ssid"
Expand All @@ -36,8 +35,8 @@
#define RX 13 // d1mini D7
#define TX 15 // d1mini D8

SoftwareSerial ppplink(RX, TX);
HardwareSerial& logger = Serial;
HardwareSerial& ppplink = Serial;
HardwareSerial& logger = Serial1;
PPPServer ppp(&ppplink);

void PPPConnectedCallback(netif* nif) {
Expand Down Expand Up @@ -74,7 +73,8 @@ void setup() {
logger.printf("\nSTA: %s (dns: %s / %s)\n", WiFi.localIP().toString().c_str(), WiFi.dnsIP(0).toString().c_str(), WiFi.dnsIP(1).toString().c_str());

ppplink.begin(PPPLINKBAUD);
ppplink.enableIntTx(true);
ppplink.swap(); // RX=GPIO13 TX=GPIO15

logger.println();
logger.printf("\n\nhey, trying to be a PPP server here\n\n");
logger.printf("Now try this on your linux host:\n\n");
Expand Down

0 comments on commit d7d50ff

Please sign in to comment.