|
1 | 1 |
|
2 | 2 | /* |
3 | 3 | Serial read/write/verify/benchmark |
4 | | - Using internal loopback |
5 | | - Using EspSoftwareSerial library for logging |
| 4 | + Using Serial0 for internal loopback |
| 5 | + Using Serial1 for logging |
6 | 6 |
|
7 | 7 | Sketch meant for debugging only |
8 | 8 | Released to public domain |
9 | 9 | */ |
10 | 10 |
|
11 | 11 | #include <ESP8266WiFi.h> |
12 | | -#include <SoftwareSerial.h> |
13 | 12 |
|
14 | | -#define SSBAUD 115200 // logger on console for humans |
| 13 | +#define LOGBAUD 115200 // logger on console for humans |
15 | 14 | #define BAUD 3000000 // hardware serial stress test |
16 | 15 | #define BUFFER_SIZE 4096 // may be useless to use more than 2*SERIAL_SIZE_RX |
17 | 16 | #define SERIAL_SIZE_RX 1024 // Serial.setRxBufferSize() |
|
21 | 20 | #define TIMEOUT 5000 |
22 | 21 | #define DEBUG(x...) // x |
23 | 22 |
|
| 23 | +#define READING_PIN 4 |
| 24 | +#define TIMEOUT_PIN 5 |
| 25 | + |
24 | 26 | uint8_t buf[BUFFER_SIZE]; |
25 | 27 | uint8_t temp[BUFFER_SIZE]; |
26 | 28 | bool reading = true; |
@@ -51,18 +53,18 @@ void error(const char* what) { |
51 | 53 | void setup() { |
52 | 54 | pinMode(LED_BUILTIN, OUTPUT); |
53 | 55 |
|
| 56 | + pinMode(READING_PIN, INPUT); |
| 57 | + pinMode(TIMEOUT_PIN, INPUT); |
| 58 | + |
54 | 59 | Serial.begin(BAUD); |
55 | 60 | Serial.swap(); // RX=GPIO13 TX=GPIO15 |
56 | 61 | Serial.setRxBufferSize(SERIAL_SIZE_RX); |
57 | 62 |
|
58 | | - // using HardwareSerial0 pins, |
59 | | - // so we can still log to the regular usbserial chips |
60 | | - SoftwareSerial* ss = new SoftwareSerial(3, 1); |
61 | | - ss->begin(SSBAUD); |
62 | | - ss->enableIntTx(false); |
63 | | - logger = ss; |
| 63 | + Serial1.begin(LOGBAUD); // RX=NONE TX=GPIO2 |
| 64 | + logger = &Serial1; |
| 65 | + |
64 | 66 | logger->println(); |
65 | | - logger->printf("\n\nOn Software Serial for logging\n"); |
| 67 | + logger->printf("\n\nOn Serial1 for logging\n"); |
66 | 68 |
|
67 | 69 | int baud = Serial.baudRate(); |
68 | 70 | logger->printf(ESP.getFullVersion().c_str()); |
@@ -140,15 +142,13 @@ void loop() { |
140 | 142 | timeout = (last_ms = now_ms) + TIMEOUT; |
141 | 143 | } |
142 | 144 |
|
143 | | - if (logger->available()) switch (logger->read()) { |
144 | | - case 's': |
145 | | - logger->println("now stopping reading, keeping writing"); |
146 | | - reading = false; |
147 | | - break; |
148 | | - case 't': |
149 | | - testReadBytesTimeout ^= FAKE_INCREASED_AVAILABLE; |
150 | | - logger->printf("testing readBytes timeout: %d\n", !!testReadBytesTimeout); |
151 | | - break; |
152 | | - default:; |
153 | | - } |
| 145 | + if (reading && (digitalRead(READING_PIN) == 0)) { |
| 146 | + logger->println("now stopping reading, keeping writing"); |
| 147 | + reading = false; |
| 148 | + } |
| 149 | + |
| 150 | + if (digitalRead(TIMEOUT_PIN) == 0) { |
| 151 | + testReadBytesTimeout ^= FAKE_INCREASED_AVAILABLE; |
| 152 | + logger->printf("testing readBytes timeout: %d\n", !!testReadBytesTimeout); |
| 153 | + } |
154 | 154 | } |
0 commit comments