diff --git a/rp2040_uart/2024-03_rp2040-uart.md b/rp2040_uart/2024-03_rp2040-uart.md index 823818e3ede12b574cea410db11df60f400c4117..7ac78ee5a395458bcb69c8c3624397c4bc72143c 100644 --- a/rp2040_uart/2024-03_rp2040-uart.md +++ b/rp2040_uart/2024-03_rp2040-uart.md @@ -59,4 +59,22 @@ Not totally sure, but I'm going to move on to try out Earle's software serial PI [the earle pio softwareserial.h](https://github.com/earlephilhower/arduino-pico/blob/4c1c72c996b6a1243b0eafa956dd0eb6410e2362/cores/rp2040/SerialPIO.h) [the earle pio softwareserial.cpp](https://github.com/earlephilhower/arduino-pico/blob/4c1c72c996b6a1243b0eafa956dd0eb6410e2362/cores/rp2040/SerialPIO.cpp) -So - let's try this out. \ No newline at end of file +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... + +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. + +--- + +### Not in Flash + +I'm also noticing [this pattern](https://github.com/earlephilhower/arduino-pico/blob/4c1c72c996b6a1243b0eafa956dd0eb6410e2362/cores/rp2040/SerialPIO.cpp#L90) to do: + +```cpp +void __not_in_flash_func(){} +``` + +Around some handlers. I wonder if this is a missing step on lots of these codes... This is discussed [in this forum post](https://forums.raspberrypi.com/viewtopic.php?t=311811) and also shows up in [the sdk here](https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_spi/spi.c#L84) - for fast shit. Maybe important... + +Also points to a larger red flag for me about the system... maybe this is not actually the microcontroller for hardo realtime stuff... \ No newline at end of file diff --git a/rp2040_uart/code/uart_pio_earle_rx/screen.cpp b/rp2040_uart/code/uart_pio_earle_rx/screen.cpp new file mode 100644 index 0000000000000000000000000000000000000000..45f33a49e0baa49ed6a53d6334f04f65afcb17b1 --- /dev/null +++ b/rp2040_uart/code/uart_pio_earle_rx/screen.cpp @@ -0,0 +1,39 @@ +#include "screen.h" +#include <Adafruit_GFX.h> +#include <Adafruit_SSD1306.h> +#include <Wire.h> + +// OLED +#define SCREEN_WIDTH 128 // OLED display width, in pixels +#define SCREEN_HEIGHT 64 // OLED display height, in pixels + +#define X_POS 0 +#define Y_POS 0 +#define TXT_SIZE 1 + +// even for displays with i.e. "0x78" printed on the back, +// the address that works is 0x3C, IDK +#define SCREEN_ADDRESS 0x3C + +Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT); + +// warning: is blocking, takes ~ 33ms ! +void displayPrint(String msg){ + display.clearDisplay(); + display.setCursor(X_POS, Y_POS); + display.print(msg); + display.display(); +} + +void displaySetup(void){ + // initialize the screen, + // oddly, SWITCHCAPVCC is the option that works even though OLED is hooked to 5V + display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS); + display.clearDisplay(); + display.display(); + display.setTextColor(SSD1306_WHITE); + display.setTextSize(TXT_SIZE); + display.setTextWrap(true); + display.dim(false); + displayPrint("bonjour..."); +} \ No newline at end of file diff --git a/rp2040_uart/code/uart_pio_earle_rx/screen.h b/rp2040_uart/code/uart_pio_earle_rx/screen.h new file mode 100644 index 0000000000000000000000000000000000000000..91fb08f0bd738345349813ee51aec5739694a9f9 --- /dev/null +++ b/rp2040_uart/code/uart_pio_earle_rx/screen.h @@ -0,0 +1,9 @@ +#ifndef SCREEN_H_ +#define SCREEN_H_ + +#include <Arduino.h> + +void displaySetup(void); +void displayPrint(String msg); + +#endif \ No newline at end of file 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 new file mode 100644 index 0000000000000000000000000000000000000000..1592a923273ded26d1be6a3ade3e9d1d6f640f0a --- /dev/null +++ b/rp2040_uart/code/uart_pio_earle_rx/uart_pio_earle_rx.ino @@ -0,0 +1,71 @@ +#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_tx/uart_pio_tx.ino b/rp2040_uart/code/uart_pio_tx/uart_pio_tx.ino index 73a5095fe126fd217072aaad8d364e3409f3b3b4..47f8c726fddad6c4a44f1ce5d959b7df6ba57ee2 100644 --- a/rp2040_uart/code/uart_pio_tx/uart_pio_tx.ino +++ b/rp2040_uart/code/uart_pio_tx/uart_pio_tx.ino @@ -9,7 +9,7 @@ // on XIAO "TX" - GPIO 0 #define PIN_TX 0 -#define PIO_BAUD 115200 +#define PIO_BAUD 1000000 // the PIO, and statemachine ? PIO pio = pio0; @@ -34,10 +34,12 @@ void setup(void){ uint32_t lastUpdate = 0; uint32_t updateInterval = 200; +uint8_t seqNum = 0; + void loop(void){ digitalWrite(PIN_DEBUG, HIGH); // blocking tx-put: - uart_tx_program_putc(pio, sm, 85); + uart_tx_program_putc(pio, sm, seqNum ++); delayMicroseconds(200); digitalWrite(PIN_DEBUG, LOW); // ...