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: SWAP_PINS:
0: use Serial1 for logging (legacy example) 0: use Serial1 for logging
1: configure Hardware Serial port on RX:GPIO13 TX:GPIO15 1: configure Hardware Serial port on RX:GPIO13 TX:GPIO15
and use EspSoftwareSerial for logging on and use EspSoftwareSerial for logging on
standard Serial pins RX:GPIO3 and TX:GPIO1 standard Serial pins RX:GPIO3 and TX:GPIO1
@ -90,6 +90,8 @@ void setup() {
logger->enableIntTx(false); logger->enableIntTx(false);
logger->println("\n\nUsing EspSoftwareSerial for logging"); logger->println("\n\nUsing EspSoftwareSerial for logging");
#else #else
// Hardware serial0 is on RX(3)/TX(1)
// Hardware serial1 is on (no RX)/TX(2)
logger->begin(BAUD_LOGGER); logger->begin(BAUD_LOGGER);
logger->println("\n\nUsing Serial1 for logging"); logger->println("\n\nUsing Serial1 for logging");
#endif #endif

View File

@ -1,17 +1,16 @@
/* /*
Serial read/write/verify/benchmark Serial read/write/verify/benchmark
Using internal loopback Using Serial0 for internal loopback
Using EspSoftwareSerial library for logging Using Serial1 for logging
Sketch meant for debugging only Sketch meant for debugging only
Released to public domain Released to public domain
*/ */
#include <ESP8266WiFi.h> #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 BAUD 3000000 // hardware serial stress test
#define BUFFER_SIZE 4096 // may be useless to use more than 2*SERIAL_SIZE_RX #define BUFFER_SIZE 4096 // may be useless to use more than 2*SERIAL_SIZE_RX
#define SERIAL_SIZE_RX 1024 // Serial.setRxBufferSize() #define SERIAL_SIZE_RX 1024 // Serial.setRxBufferSize()
@ -21,6 +20,9 @@
#define TIMEOUT 5000 #define TIMEOUT 5000
#define DEBUG(x...) // x #define DEBUG(x...) // x
#define READING_PIN 4
#define TIMEOUT_PIN 5
uint8_t buf[BUFFER_SIZE]; uint8_t buf[BUFFER_SIZE];
uint8_t temp[BUFFER_SIZE]; uint8_t temp[BUFFER_SIZE];
bool reading = true; bool reading = true;
@ -51,18 +53,18 @@ void error(const char* what) {
void setup() { void setup() {
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
pinMode(READING_PIN, INPUT);
pinMode(TIMEOUT_PIN, INPUT);
Serial.begin(BAUD); Serial.begin(BAUD);
Serial.swap(); // RX=GPIO13 TX=GPIO15 Serial.swap(); // RX=GPIO13 TX=GPIO15
Serial.setRxBufferSize(SERIAL_SIZE_RX); Serial.setRxBufferSize(SERIAL_SIZE_RX);
// using HardwareSerial0 pins, Serial1.begin(LOGBAUD); // RX=NONE TX=GPIO2
// so we can still log to the regular usbserial chips logger = &Serial1;
SoftwareSerial* ss = new SoftwareSerial(3, 1);
ss->begin(SSBAUD);
ss->enableIntTx(false);
logger = ss;
logger->println(); logger->println();
logger->printf("\n\nOn Software Serial for logging\n"); logger->printf("\n\nOn Serial1 for logging\n");
int baud = Serial.baudRate(); int baud = Serial.baudRate();
logger->printf(ESP.getFullVersion().c_str()); logger->printf(ESP.getFullVersion().c_str());
@ -140,15 +142,13 @@ void loop() {
timeout = (last_ms = now_ms) + TIMEOUT; timeout = (last_ms = now_ms) + TIMEOUT;
} }
if (logger->available()) switch (logger->read()) { if (reading && (digitalRead(READING_PIN) == 0)) {
case 's':
logger->println("now stopping reading, keeping writing"); logger->println("now stopping reading, keeping writing");
reading = false; reading = false;
break; }
case 't':
if (digitalRead(TIMEOUT_PIN) == 0) {
testReadBytesTimeout ^= FAKE_INCREASED_AVAILABLE; testReadBytesTimeout ^= FAKE_INCREASED_AVAILABLE;
logger->printf("testing readBytes timeout: %d\n", !!testReadBytesTimeout); logger->printf("testing readBytes timeout: %d\n", !!testReadBytesTimeout);
break;
default:;
} }
} }

View File

@ -15,8 +15,8 @@ extern "C" {
} }
#endif #endif
// Set up output serial port (could be a SoftwareSerial // Set up output on the first serial port
// if really wanted). // (can be any Stream, if needed)
Stream& ehConsolePort(Serial); Stream& ehConsolePort(Serial);

View File

@ -20,7 +20,6 @@
#include <lwip/dns.h> #include <lwip/dns.h>
#include <PPPServer.h> #include <PPPServer.h>
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#ifndef STASSID #ifndef STASSID
#define STASSID "your-ssid" #define STASSID "your-ssid"
@ -36,8 +35,8 @@
#define RX 13 // d1mini D7 #define RX 13 // d1mini D7
#define TX 15 // d1mini D8 #define TX 15 // d1mini D8
SoftwareSerial ppplink(RX, TX); HardwareSerial& ppplink = Serial;
HardwareSerial& logger = Serial; HardwareSerial& logger = Serial1;
PPPServer ppp(&ppplink); PPPServer ppp(&ppplink);
void PPPConnectedCallback(netif* nif) { 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()); 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.begin(PPPLINKBAUD);
ppplink.enableIntTx(true); ppplink.swap(); // RX=GPIO13 TX=GPIO15
logger.println(); logger.println();
logger.printf("\n\nhey, trying to be a PPP server here\n\n"); logger.printf("\n\nhey, trying to be a PPP server here\n\n");
logger.printf("Now try this on your linux host:\n\n"); logger.printf("Now try this on your linux host:\n\n");