diff --git a/rp2040_uart/2024-03_rp2040-uart.md b/rp2040_uart/2024-03_rp2040-uart.md index 7ac78ee5a395458bcb69c8c3624397c4bc72143c..45fe1e4c9c285c797ae047d28206d03d274b417d 100644 --- a/rp2040_uart/2024-03_rp2040-uart.md +++ b/rp2040_uart/2024-03_rp2040-uart.md @@ -61,9 +61,17 @@ Not totally sure, but I'm going to move on to try out Earle's software serial PI So - let's try this out. -OK, my big dawg `earle` looks to have this locked down, it is werken. It's also wrapped in the arduino Serial API meaning I could use 'em in an abstracted class for P2P comms. Bless his heart, now I need to check i.e. continuity and make some measurements... +OK, I have this up and running: I am streaming at a fixed BAUD, then counting the ratio of bytes we miss in a stream. The uc's are counting missed and proper bytes (reading monotonic sequence numbers) and then checking also intervals between transmissions... -Ah, jesus, nevermind, it is catching garbage bytes... all 255's, and it's reporting new-byteness when in fact none are visible on the line. +| Mbit/s | Misses (errs / total-bytes) | Expected Byte Time (us) | Avg Byte Time | +| --- | --- | --- | --- | +| 0.1 | nil | 100 | 110.2 | +| 0.5 | nil | 20 | 22.2 | +| 1.0 | 0.025 (1/40) (!) | 10 | 13.4 | +| 2.5 | 0.497 | 4 | 11.0 | +| 5.0 | 0.755 | 2 | 11.0 | + +So, I'm not convinced that I haven't fuxd anything here... it seems wild that we would have such a bottleneck to performance, and there are a few red flags here; namely that we have a lower bound of 11us between transmits, which would also explain our increasing error rate when we surpass 1 Mbit/sec (as the byte-wise period there is 10us or so). --- diff --git a/rp2040_uart/code/uart_pio_earle_rx/uart_pio_earle_rx.ino b/rp2040_uart/code/uart_pio_earle_rx/uart_pio_earle_rx.ino deleted file mode 100644 index 1592a923273ded26d1be6a3ade3e9d1d6f640f0a..0000000000000000000000000000000000000000 --- a/rp2040_uart/code/uart_pio_earle_rx/uart_pio_earle_rx.ino +++ /dev/null @@ -1,71 +0,0 @@ -#include "screen.h" - -// using an RP2040 XIAO -// with earle philhower core - -// "D10" - GPIO 3 -#define PIN_DEBUG 3 - -// on XIAO "RX" - GPIO 1 -#define PIN_RX 1 -#define PIO_BAUD 1000000 - -SerialPIO serial(SerialPIO::NOPIN, PIN_RX); - -void setup(void){ - pinMode(PIN_LED_B, OUTPUT); - digitalWrite(PIN_LED_B, LOW); - - pinMode(PIN_DEBUG, OUTPUT); - digitalWrite(PIN_DEBUG, LOW); - - // the display setup - displaySetup(); - displayPrint("bonjour..."); - - serial.begin(PIO_BAUD); -} - -uint32_t lastUpdate = 0; -uint32_t updateInterval = 200; - -uint8_t expectedRx = 0; -uint32_t missCount = 0; -uint32_t catchCount = 0; - -uint8_t chars[256]; - -void loop(void){ - if(serial.available()){ - // earle core throws -1 if we have an error, - int data = serial.read(); - if(data < 0) { - return; - } - // count total hits - catchCount ++; - // catch data and count sequence errors - digitalWrite(PIN_DEBUG, !digitalRead(PIN_DEBUG)); - chars[catchCount & 255] = data; - if(data != expectedRx){ - missCount ++; - } - expectedRx = data + 1; - } - // uint8_t data = uart_rx_program_getc(pio, sm); - // digitalWrite(PIN_DEBUG, LOW); - // ... - if(lastUpdate + updateInterval < millis()){ - lastUpdate = millis(); - digitalWrite(PIN_LED_B, !digitalRead(PIN_LED_B)); - displayPrint(String(missCount) + " / " + String(catchCount) + " \n" + - String(chars[0]) + ", " + String(chars[1]) + ", " + String(chars[2]) + ", " + String(chars[3]) + ", " + String(chars[4]) + ", " + String(chars[5]) + ", " - ); - - // displayPrint(spipi_print()); - // displayPrint(String(rxCount) + "\n" + - // String(rxSize) - // ); - } -} - diff --git a/rp2040_uart/code/uart_pio_earle_rx/screen.cpp b/rp2040_uart/code/uart_pio_earle_tx_rx/screen.cpp similarity index 100% rename from rp2040_uart/code/uart_pio_earle_rx/screen.cpp rename to rp2040_uart/code/uart_pio_earle_tx_rx/screen.cpp diff --git a/rp2040_uart/code/uart_pio_earle_rx/screen.h b/rp2040_uart/code/uart_pio_earle_tx_rx/screen.h similarity index 100% rename from rp2040_uart/code/uart_pio_earle_rx/screen.h rename to rp2040_uart/code/uart_pio_earle_tx_rx/screen.h diff --git a/rp2040_uart/code/uart_pio_earle_tx_rx/uart_pio_earle_tx_rx.ino b/rp2040_uart/code/uart_pio_earle_tx_rx/uart_pio_earle_tx_rx.ino new file mode 100644 index 0000000000000000000000000000000000000000..6d34a41dd5ac6563ef1d72a8ea76220e9c3ad62c --- /dev/null +++ b/rp2040_uart/code/uart_pio_earle_tx_rx/uart_pio_earle_tx_rx.ino @@ -0,0 +1,102 @@ +#include "screen.h" + +// using an RP2040 XIAO +// with earle philhower core + +// "D10" - GPIO 3 +#define PIN_DEBUG 3 + +#define PIN_RX 1 +#define PIN_TX 0 +#define PIO_BAUD 2500000 + +SerialPIO serial(PIN_TX, PIN_RX); + +void setup(void){ + pinMode(PIN_LED_B, OUTPUT); + digitalWrite(PIN_LED_B, LOW); + + pinMode(PIN_DEBUG, OUTPUT); + digitalWrite(PIN_DEBUG, LOW); + + // the display setup + displaySetup(); + displayPrint("bonjour..."); + + serial.begin(PIO_BAUD); +} + +uint32_t lastUpdate = 0; +uint32_t updateInterval = 1000; + +uint8_t expectedRx = 0; +uint32_t missCount = 0; +uint32_t catchCount = 0; + +uint8_t expected_miss = 0; +uint8_t actual_miss = 0; + +uint8_t chars[256]; + +uint8_t seqNum = 0; + +// and let's calculate actual bandwidth (success bytes / sec * 8) and bitrate ( * 10) +// and record avg per-cycle pickup ? + +uint32_t lastTx = 0; +float intervalEstimate = 0.0F; + +void loop(void){ + + // catch 'em AFAP + if(serial.available()){ + while(serial.available()){ + int data = serial.read(); + // earle core throws -1 if we have an error, + if(data < 0) { + return; + } + // count total hits + catchCount ++; + // stuff it + chars[catchCount & 255] = data; + // check for missus + if(data != expectedRx){ + actual_miss = data; + expected_miss = expectedRx; + missCount ++; + } + expectedRx = data + 1; + } + } + + // and write AFAP, recording outgoing times + if(serial.availableForWrite()){ + digitalWrite(PIN_DEBUG, !digitalRead(PIN_DEBUG)); + serial.write(seqNum ++); + uint32_t txTime = micros(); + uint32_t txInterval = txTime - lastTx; + lastTx = txTime; + intervalEstimate = (float)txInterval * 0.01F + intervalEstimate * 0.99F; + // while(serial.availableForWrite()){ + // } + } + + // ... + if(lastUpdate + updateInterval < millis()){ + lastUpdate = millis(); + digitalWrite(PIN_LED_B, !digitalRead(PIN_LED_B)); + displayPrint(String(missCount) + " / " + String(catchCount) + " \n" + + "miss: " + String((float)missCount / (float)catchCount, 9) + "\n" + + String(expected_miss) + ": " + String(actual_miss) + "\n" + + "avg interval: " + String(intervalEstimate, 4) + // String(chars[0]) + ", " + String(chars[1]) + ", " + String(chars[2]) + ", " + String(chars[3]) + ", " + String(chars[4]) + ", " + String(chars[5]) + ", " + ); + + // displayPrint(spipi_print()); + // displayPrint(String(rxCount) + "\n" + + // String(rxSize) + // ); + } +} +