1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-21 21:22:31 +03:00

Prefer Serial1 logging in examples (#9079)

This commit is contained in:
Max Prokhorov
2024-02-09 20:22:49 +03:00
committed by GitHub
parent e6df345584
commit d7d50ffc6f
4 changed files with 31 additions and 29 deletions

View File

@ -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
@ -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

View File

@ -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()
@ -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;
@ -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());
@ -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);
}
}

View File

@ -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);

View File

@ -20,7 +20,6 @@
#include <lwip/dns.h>
#include <PPPServer.h>
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#ifndef STASSID
#define STASSID "your-ssid"
@ -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) {
@ -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");