UART (JTagulator) auto-scan

One of the nice features of the JTAGulator is the ability to auto-detect which pins are UART or JTAG pins. I believe the BP5 doesn’t need to have these pins hard-wired to specific pins. I’d be interested in trying to develop code that could auto-detect the UART pins, although I’m no expert. Does this sound like a reasonable project?

That sounds like an excellent project. I have JTagulator on my list - I believe you mentioned it on Twitter? I checked it out a while back and it seems like it wouldn’t be a problem to install it as a mode on the bus pirate. Though the low pin count would make the probing process a bit more tedious. The chips I saw it ported too didn’t have a huge numbers of ios (if I recall).

But, I read your post as maybe the Bus Pirate is the target? Using the Bus Pirate as a hacking target for other tools is also something I’m interested in.

#define BP_DEBUG_UART_0 uart0
#define BP_DEBUG_UART_0_TX BIO4
#define BP_DEBUG_UART_0_RX BIO5
#define BP_DEBUG_UART_1 uart1
#define BP_DEBUG_UART_1_TX BIO0
#define BP_DEBUG_UART_1_RX BIO1   

The RP2040 UARTs are available on two sets of pins. BIO0/BIO1 and BIO4/BIO5.

The PIO can be used with the UART example from the SDK, which is available on any pin.

There are 8 PIO state machines (if you disable the LEDs), so there can be 8 RXs or 8 TXs or any combination.

Yes, I can picture using the DP5 as a tool to identify UART/JTAG ports. But I’m a noob with PIO, so I have a big learning curve.

1 Like

The SDK examples are pretty complete. It has the function for loading the PIO program and then the examples how to use it.

If it’s a stumbling block, I can integrate the example code into a mode that you can use.

For example:

    // Console output (also a UART, yes it's confusing)
    setup_default_uart();
    printf("Starting PIO UART RX example\n");

    // Set up the hard UART we're going to use to print characters
    uart_init(HARD_UART_INST, SERIAL_BAUD);
    gpio_set_function(HARD_UART_TX_PIN, GPIO_FUNC_UART);

    // Set up the state machine we're going to use to receive them.
    PIO pio = pio0;
    uint sm = 0;
    uint offset = pio_add_program(pio, &uart_rx_program);
    uart_rx_program_init(pio, sm, offset, PIO_RX_PIN, SERIAL_BAUD);

    // Tell core 1 to print some text to uart1 as fast as it can
    multicore_launch_core1(core1_main);
    const char *text = "Hello, world from PIO! (Plus 2 UARTs and 2 cores, for complex reasons)\n";
    multicore_fifo_push_blocking((uint32_t) text);

    // Echo characters received from PIO to the console
    while (true) {
        char c = uart_rx_program_getc(pio, sm);
        putchar(c);
    }

After the PIO setup, it’s similar to using a typical UART.

That would help a bit. I’m looking at the JTAGulator code, and I think it firsts listens to each pin to see if any text comes in (voltage changes). That’s how it detects the TX line. I’m still studying the code…

I previously only looked at the JTAG side of the project, so I’m not familiar with the UART part.

Does it also do auto baud rate detection? The old PIC we used could do it. I searched a bit and it seems the RP2040 UART doesn’t, however there is mention of some PIO script that will detect baud rate - but I can’t actually find it.

I’ll setup a PIO uart example in a new mode, or as a macro for the uart mode ASAP.

I came across this cool repo, maybe it could help?

1 Like

The latest version of JTagulator does JTAG, SWD, and UART in one scan. BTW, the board doesn’t seem to be easily purchasable, unless you build your own. BPV5 would fill in a nice niche.

Here’s a pico-based UART bridge that auto-bauds.
Pico Debug’n’Dump

1 Like

Looking at the JTagulator code (I’m a newbie), I think the first step is to monitor all pins, looking for voltage values that vary. Once this is found, it assumes this is an output pin, it tries all other pins with varying input to see if the output responds.

1 Like

Another good one! I’m grabbing this too.