Skip to content
Snippets Groups Projects
Commit ff5e3ffa authored by Jake Read's avatar Jake Read
Browse files

oddity on pio rx examples, abandoning

parent 8b13d7a7
Branches
No related tags found
No related merge requests found
......@@ -35,8 +35,28 @@ So we should be able to to clk/8 : 16MBit/s, and indeed we can see things workin
But this is not terribly interesting: we want to see that we can catch words fast enough: the ISR on the RX side is normally where we meet our limits.
### UART PIO RX'ing
### UART PIO RX'ing with PIO Example
So, I should spin up an RX line now and see about firing an interrupt there... I'll get one chip TX'ing at a fixed rate and then start in on no. 2
... doing this using [the blocking example](https://github.com/raspberrypi/pico-examples/blob/master/pio/uart_rx/uart_rx.c) catches *some* bytes, but not that many (at only 1mbaud), and it's perhaps only latching when we *just* catch the byte in time, i.e. if we poll just as the last bit has arrived.
\ No newline at end of file
... doing this using [the blocking example](https://github.com/raspberrypi/pico-examples/blob/master/pio/uart_rx/uart_rx.c) catches *some* bytes, but not that many (at only 1mbaud), and it's perhaps only latching when we *just* catch the byte in time, i.e. if we poll just as the last bit has arrived - or perhaps we're only-sometimes catching in time, and the thing is not receiving next bytes etc etc..
So, the interrupt version... works at a similar quality: some bytes are captured, many are not. It tends to happen in phases. In traces below, CH1 goes lo-then-hi whenever a new byte is loaded into the TX chip, CH2 is the UART trace (TX/RX), and CH4 flips state whenever the UART RX IRQ fires.
![irq](images/2024-01-03_iffy-irq-rx-01.png)
![irq](images/2024-01-03_iffy-irq-rx-02.png)
So, this is all kind of bad news for our project, and I suspect I would have to get into some of the PIO depths to figure out what's going wrong, which I don't really have the time for at the moment. I can try slowing it down to see if this is a chunking error or something else... it's the same even at 115200 BAUD.
So - for troubleshooting, I am perhaps missing some pin config? But that looks to be handled in the example's setup.
Not totally sure, but I'm going to move on to try out Earle's software serial PIO, which I have some prior experience with, but also found some bugs in (?) IIRC.
### UART PIO RX'ing with Earle's Software Serial PIO
[the earle commit](https://github.com/earlephilhower/arduino-pico/pull/391)
[the earle pio_uart.h](https://github.com/earlephilhower/arduino-pico/blob/326697bbe1cc3b4b5f7c140dca10a6924262539d/cores/rp2040/pio_uart.pio.h)
[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
......@@ -9,13 +9,22 @@
// on XIAO "RX" - GPIO 1
#define PIN_RX 1
#define PIO_BAUD 1000000
#define PIO_BAUD 115200
// the PIO, and statemachine ?
PIO pio = pio0;
uint sm = 0;
uint offset = 0;
// irq handler,
void pio_irq_func(void){
while(!pio_sm_is_rx_fifo_empty(pio, sm)){
digitalWrite(PIN_DEBUG, !digitalRead(PIN_DEBUG));
uint8_t data = uart_rx_program_getc(pio, sm);
}
}
void setup(void){
pinMode(PIN_LED_B, OUTPUT);
digitalWrite(PIN_LED_B, LOW);
......@@ -27,25 +36,33 @@ void setup(void){
displaySetup();
displayPrint("bonjour...");
// add and init uart
offset = pio_add_program(pio, &uart_rx_program);
uart_rx_program_init(pio, sm, offset, PIN_RX, PIO_BAUD);
// setup the IRQ,
irq_add_shared_handler(PIO0_IRQ_0, pio_irq_func, PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY);
irq_set_enabled(PIO0_IRQ_0, true);
// ???? lol ffs
const uint irq_index = PIO0_IRQ_0 - ((pio == pio0) ? PIO0_IRQ_0 : PIO1_IRQ_0); // Get index of the IRQ;
// set PIO to interrupt when FIFO is NOT empty
pio_set_irqn_source_enabled(pio, irq_index, pis_sm0_rx_fifo_not_empty, true);
}
uint32_t lastUpdate = 0;
uint32_t updateInterval = 200;
void loop(void){
digitalWrite(PIN_DEBUG, !digitalRead(PIN_DEBUG));
uint8_t data = uart_rx_program_getc(pio, sm);
// 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(spipi_print());
// // displayPrint(String(rxCount) + "\n" +
// // String(rxSize)
// // );
// }
if(lastUpdate + updateInterval < millis()){
lastUpdate = millis();
digitalWrite(PIN_LED_B, !digitalRead(PIN_LED_B));
// displayPrint(spipi_print());
// displayPrint(String(rxCount) + "\n" +
// String(rxSize)
// );
}
}
......@@ -9,7 +9,7 @@
// on XIAO "TX" - GPIO 0
#define PIN_TX 0
#define PIO_BAUD 1000000
#define PIO_BAUD 115200
// the PIO, and statemachine ?
PIO pio = pio0;
......@@ -38,7 +38,7 @@ void loop(void){
digitalWrite(PIN_DEBUG, HIGH);
// blocking tx-put:
uart_tx_program_putc(pio, sm, 85);
delayMicroseconds(30);
delayMicroseconds(200);
digitalWrite(PIN_DEBUG, LOW);
// ...
if(lastUpdate + updateInterval < millis()){
......
rp2040_uart/images/2024-01-03_iffy-irq-rx-01.png

23 KiB

rp2040_uart/images/2024-01-03_iffy-irq-rx-02.png

21.6 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment