How to disable UART0 and mux its pins for PRU usage?

Hello everyone.
I’ve been lurking here and googling around looking for answers but found no one doing what I’m trying.

My main objective is to be able to use 16 pins as PRU inputs, on a single PRU, without board modification or additional hardware.

PRU1 has most of the pins available and there are two that are really good candidates for reassigning: PR1_PRU1_PRU_R31_14 and PR1_PRU1_PRU_R31_15, which go out on pins E15 and E16.
The pins E15 and E16, named UART0_TXD and UART0_RXD respectively, are by default assigned to a uart0 device with parts of its definition in two files: am33xx.dtsi and am335x-bone-common.dtsi.
I currently set dtb=am335x-boneblack-emmc-overlay.dtb inside uEnv.txt and do not know what is the default DTB used when nothing is set there. I guess it is am335x-boneblack.dts, but both include the above mentioned DTSIs, so that should not matter.

I’m guessing that removing the uart0 device inside the ocp (am33xx.dtsi) and the phandle (am335x-bone-common.dtsi), then changing the mux settings for the pins from this:

`

uart0_pins: pinmux_uart0_pins {

pinctrl-single,pins = <
AM33XX_IOPAD(0x970, PIN_INPUT_PULLUP | MUX_MODE0) /* uart0_rxd.uart0_rxd /
AM33XX_IOPAD(0x974, PIN_OUTPUT_PULLDOWN | MUX_MODE0) /
uart0_txd.uart0_txd */

;
};

`

To something like this:

`

uart0_pins: pinmux_uart0_pins {

pinctrl-single,pins = <
AM33XX_IOPAD(0x970, PIN_INPUT_PULLDOWN | MUX_MODE6) /* uart0_rxd.uart0_rxd /
AM33XX_IOPAD(0x974, PIN_INPUT_PULLDOWN | MUX_MODE6) /
uart0_txd.uart0_txd */

;
};

`

…would do the trick.

I’m aware that there is a SN74LVC2G241 and a pulldown in the way, but they seem harmless for what I’m trying to achieve.

Now the questions:

  1. Will that work?

  2. Besides losing that serial port, what other side effects I will have by doing that?

  3. Is that SN74LVC2G241 a problem?

  4. Is there a way to disable uart0 (the driver, device, etc), change the mux and use it on the PRU after booting to linux? The idea here is to retain as much functionality as possible and still get to use the pin as PRU input when needed.

  5. Any other alternatives?
    Bonus question: What is the default DTB and where is it set?

Thanks for your time,

Hello everyone.
I’ve been lurking here and googling around looking for answers but found no one doing what I’m trying.

My main objective is to be able to use 16 pins as PRU inputs, on a single PRU, without board modification or additional hardware.

PRU1 has most of the pins available and there are two that are really good candidates for reassigning: PR1_PRU1_PRU_R31_14 and PR1_PRU1_PRU_R31_15, which go out on pins E15 and E16.
The pins E15 and E16, named UART0_TXD and UART0_RXD respectively, are by default assigned to a uart0 device with parts of its definition in two files: am33xx.dtsi and am335x-bone-common.dtsi.
I currently set dtb=am335x-boneblack-emmc-overlay.dtb inside uEnv.txt and do not know what is the default DTB used when nothing is set there. I guess it is am335x-boneblack.dts, but both include the above mentioned DTSIs, so that should not matter.

I’m guessing that removing the uart0 device inside the ocp (am33xx.dtsi) and the phandle (am335x-bone-common.dtsi), then changing the mux settings for the pins from this:

`

uart0_pins: pinmux_uart0_pins {

pinctrl-single,pins = <
AM33XX_IOPAD(0x970, PIN_INPUT_PULLUP | MUX_MODE0) /* uart0_rxd.uart0_rxd /
AM33XX_IOPAD(0x974, PIN_OUTPUT_PULLDOWN | MUX_MODE0) /
uart0_txd.uart0_txd */

;
};

`

To something like this:

`

uart0_pins: pinmux_uart0_pins {

pinctrl-single,pins = <
AM33XX_IOPAD(0x970, PIN_INPUT_PULLDOWN | MUX_MODE6) /* uart0_rxd.uart0_rxd /
AM33XX_IOPAD(0x974, PIN_INPUT_PULLDOWN | MUX_MODE6) /
uart0_txd.uart0_txd */

;
};

`

…would do the trick.

I’m aware that there is a SN74LVC2G241 and a pulldown in the way, but they seem harmless for what I’m trying to achieve.

Now the questions:

  1. Will that work?

Yes

  1. Besides losing that serial port, what other side effects I will have by doing that?

u-boot (the bootloader) also uses UART0 to output messages before Linux is booted. You need to shift it to a different UART by recompiling the bootloader with CONFIG_CONS_INDEX set to whichever UART you want to use for serial console. Also need to update the update the kernel command line for which you will have to update the bootloader again.

  1. Is that SN74LVC2G241 a problem?

If you see the schematics, 74LVC2G241 directs traffic one way on the RX pin and the other way on the TX pin. You will have to bypass the buffer if you want to use both the pins as inputs.

  1. Is there a way to disable uart0 (the driver, device, etc), change the mux and use it on the PRU after booting to linux? The idea here is to retain as much functionality as possible and still get to use the pin as PRU input when needed.

Once you update the pinmux and the console kernel command line Linux won’t use it, so you’re free to use the pins however you like.

  1. Any other alternatives?

I solved the exact same problem that you have (wanting to use 16 PRU inputs). It’s a hardware solution called BeagleLogic standalone (also a blog post on the design of it) that implements a 16-channel logic analyzer using the PRUs on the AM335x SoC. The serial console (what UART0 did) is moved to UART4. Let me know if you’re interested in a board.

Bonus question: What is the default DTB and where is it set?

The default DTB depends on the board EEPROM. If you connect a USB-Serial cable to the 6-pin header (configuration 115200-8-N-1) and see the output, you will know which DTB was loaded.

Best Regards.

Thanks for the very informative reply and for all the effort that went into developing BeagleLogic. It is a really cool project!

I totally missed the part where the 74LVC2G241 buffer had a direction. I’ll have to think about sacrificing it but those are tiny pads, and it might expose the SoC too much when using the serial. Well, that BBB would be gathering dust if not for this project, so it might be worth it.

It seems I need to clarify question 4: “Is there a way to disable uart0 (the driver, device, etc), change the mux and use it on the PRU after booting to linux? The idea here is to retain as much functionality as possible and still get to use the pin as PRU input when needed.
What I meant to ask here is if there is a way to disable the uart and change the mux after booting into linux? The intention was to keep it working as a serial and only switch it to PRU input when needed.

u-boot (the bootloader) also uses UART0 to output messages before Linux is booted. You need to shift it to a different UART by recompiling the bootloader with CONFIG_CONS_INDEX set to whichever UART you want to use for serial console. Also need to update the update the kernel command line for which you will have to update the bootloader again.

Must I change them for the PRU muxing and linux boot to work, or only if I want u-boot and the kernel to output to another UART? I probably won’t care very much if I lose se capacity to do serial debugging while my custom DTB is in use, but not booting at all defeats the purpose. I would rather avoid recompiling u-boot if possible, and I guess it might be possible to change the kernel command line directly in the UEnv.txt file if needed.

Right now I’d rather not switch boards. The challenge I set upon myself was trying to use the BBB as a Game boy cartridge, but if it proves unfeasible I’ll sure consider using something else.

Thanks again!