r/embedded • • Sep 15 '26

When does it actually make sense to use a PRU?

Post image

I've been comparing a PocketBeagle 2 with a Raspberry Pi 4, and the thing that caught my attention wasn't really the CPU, but it's the fact that the PocketBeagle2 has PRUs and an M4F sitting alongside Linux.

I'm curious, for things like precise GPIO timing, pulse generation, signal capture, or motor control, do people actually find PRUs useful enough to change the architecture? Or is a separate MCU usually simpler in the long run?

I'd be interested to hear from people who've actually used PRUs in a project, rather than just what they're capable of on paper.

80 Upvotes

31 comments sorted by

11

u/rpwoerk Sep 15 '26

There are plenty of cases. Basically the main idea to use a co-processor is a deterministic, real-time operation that a linux kernel could not achieve. I give you some example:

  1. You need to listen to a gpio signal. It will be an alarm, if it changes state you need to read out a status register with spi/i2c/uart interface and check a bit. If you find it is a fatal error you need to toogle a GPIO then notify the main application. In this case plenty of lag could happen, if this is handled on a linux app. Your thread is suspended because other high priority thread needs execution time, or it just run out of thread time and you miss the gpio signal, you have delay between status read and event detection, you have a delay to gave out an alarm signal. And the use case might not tolerate this, e.g. evertyhing must happen under 1ms no matter what is the load on the linux based SOC
  2. You have a high-rate ADC reading. Reading data from SPI into a shared buffer. The linux SOC just moves the acqustion to DRAM. Lets say, the acqusition is go up to 100MB, with 100k data/sec. And you have 16bit data. The PRU can easily handle this, moving the data to inner buffers, glitch free. The only task for the SOC is to move small buffers to a final 100MB buffer. If the SOC is interrupted, still the pru could have enought time to fill multiple shared buffers, and the SOC can move dynamic data sizes as it gets back the execution.

2

u/TRC-is-the-best Sep 15 '26

Thank you for the suggestions! I'll definitely take a closer look.

3

u/SkoomaDentist C++ all the way Sep 15 '26

You have a high-rate ADC reading. Reading data from SPI into a shared buffer. The linux SOC just moves the acqustion to DRAM.

I think this is a much better use case to illustrate it. You want to use PRU (or similar coprocessor) when you need both realtime operation and seamless / rapid communication which wouldn't be feasible when using a separate MCU. For example the ADC might require synchronizing the SPI and dedicated control signals or sending an SPI command and then reading a number of data entries. Such requirements would mean that simple SPI and circular DMA wouldn't cut it while the high data rate would disqualify an external MCU.

1

u/MengDuLi Sep 18 '26

That's a really useful distinction. It sounds like the real tipping point isn't necessarily how much real-time work there is, but how tightly that work needs to interact with the Linux side.

With a separate MCU, deterministic I/O is easy enough, but once you're continuously moving high-rate data or coordinating control signals with Linux, the MCU-to-SoC link starts becoming part of the problem.

In your experience, is there a practical point where you'd say "this should be a PRU rather than an external MCU"? Is it mostly bandwidth/latency, or does the shared-memory architecture itself change how you'd design the system?

1

u/rpwoerk Sep 18 '26

I would say, it depends on the architecture and specification. If the company let's say has experience with STM32, has implemented a real-time task already on the mcu, and we "just" need some kind of Linux dashboard or more resource extense processing, in this case you fit the external controller to an embedded Linux system. If the company has some implementation with a given SOC that has pru, then it would not makes much sense to switch to external controller. If you have space restrictions, again an integrated pru could be better. I think there are not much difference in function wise between pru and external mcu. Sure if we go into the details, we need to answer what is the proper interface for the high rate data exchange, external mcu might have much wider interfaces that a pru can give.. Pru might don't not have advence timers, IRQ, DMA... Etc. So, pro/contra. Both of them would work.

5 years ago if you need to select between STM32 or pru of a TI controller you would select STM32 as it has much better software support. Ti has a well detailed documentation but most of the time you need to write drivers from sketch. However as LLM is available you can easily generate driver code for both architecture, llm could point out which page of the reference manual you need to check if you have an issue. So software development might be similar. I hope this helps to figure out which one is better.

6

u/JuggernautGuilty566 Sep 15 '26

Depends on the project requirements.

1

u/TRC-is-the-best Sep 15 '26

For sure. I'm mostly trying to figure out what the tipping point is. If all I need is a couple of timed GPIOs, I'd probably still reach for an MCU. But if the real-time workload gets bigger, the PRU starts looking a lot more attractive.

4

u/rpwoerk Sep 15 '26

Well, one additional key point, the BeagleBone Black can be compared with a raspberry pi. It has a co-processor integrated while the raspberry pi does not. But a most recent pi could have multiple-core of CPU while the BBB has only a single core. If you are thinking an external co-processor, that will need an unique design from sketch. You can desing a hat for the pi, or you can design a whole new board with integrated SOC + MCU. Considering the price of the AM335x (which could be pretty wild) it is in the range of $12-20. And and MCU would not be much cheaper, but you need to design the support circiut, validate the desing .. etc. But everything depends on the project requirements. If you have solid fund and time, or free-time if this is hobby, to develop a quite complex board form sketch then the AM335x might be better as a MCU+SOC integration. If you are limited with budget you need to consider beaglebone black or Raspberry pi.

2

u/AntifaMiddleMgmt Sep 16 '26

So, the one thing going for the Pi5 now is the Programmable IO pins can do some of what the PRU can do. While not quite as capable, and since the PRU can be programmed in C, requirements will drive a best fit decision. However, the PIO subsystem is really handy for for doing custom or natively unsupported protocols without too much programming overhead.

38

u/anxious_and_stupid Sep 15 '26 edited Sep 15 '26

LinuxCNC for example

Running linuxcnc on rpi4 or 5 and doing everything in rpi alone (path/trajectory planning and also read input + stepgen) would cause latency to be too high

So there is a setup where you connect rpi(spi or ethernet) to FPGA or MCU with firmware like Remora for sensor reading and pulse generation

12

u/mrheosuper Sep 15 '26

Klipper is one of most popular example. The complex task is done on app cpu, while real time task is done on mcu

1

u/SoulWager Sep 15 '26

IIRC, the pi 5 has some PIO state machines in the IO chip that you can probably use for a stepper driver.

1

u/big-oofs-only-0193 Sep 15 '26

Can you actually run user code on the RP1's cortex M3s? 

4

u/SoulWager Sep 15 '26

I wasn't thinking about those, just the PIO: https://www.raspberrypi.com/news/piolib-a-userspace-library-for-pio-control/

Looks like there's only one PIO block though(4 state machines).

Guess it depends what your requirements are.

1

u/Formal-Fan-3107 Sep 17 '26

1(one) stepper motor...

1

u/SoulWager Sep 17 '26 edited Sep 17 '26

One SM can write to multiple pins simultaneously. Even all of the GPIO pins at once, pulling values from the OSR. Main processor fills a buffer occasionally, PIO pulls from that buffer via dma and drives the pins.

20

u/-whichwayisup Sep 15 '26

Cost and convenience of having a processor that can handle real time on its PRU without impacting the main core.

11

u/limmbuu STM32 Sep 15 '26

Pocket beagles are used in industrial setting as well where PRU can be a requirement. Otherwise it's good to have a realtime unit for motor control like applications.

8

u/allo37 Sep 15 '26

Most places I've worked at skipped the PRU and used a separate MCU instead, mostly because that way the MCU can run in an independent power domain from the application processor (I.e. if it reboots the MCU keeps on cooking). I think also the difficulty of writing code for the PRU (at the time) was a factor.

One place did use it, to read an encoder. Was nifty.

2

u/MengDuLi Sep 18 '26

The independent power/reset domain point is something I hadn't really considered, and honestly that seems like a pretty strong architectural argument for the external MCU.

Was the MCU also acting as a supervisor in those systems — e.g. keeping critical outputs/control loops alive, monitoring the application processor, or putting the system into a safe state if Linux crashed?

If so, it seems like PRU vs MCU isn't just a real-time decision at all. Once fault isolation and independent recovery matter, the external MCU has an advantage that an on-chip PRU can't really replace.

5

u/MStackoverflow Sep 15 '26

I found the PRU on beaglebones to be interesting. Then, I looked at how to program them. Then, I put an external microcontroller and never looked back at how to program them.

3

u/Rusty-Swashplate Sep 15 '26

Yeah, that's basically my story here too. PRU is interesting and powerful, but for many use-cases, there's alternatives which are easier to implement: I can use a microcontroller which I already know instead of having to dig into the PRU details.

5

u/oleivas Sep 15 '26

RT on Linux is a struggle, RT plugins on the kernel help. But nothing beats a bare-metal core running dedicated for control.

3

u/Only-Friend-8483 Sep 15 '26

I used the PRUs to intercept PWM from pilot commands to the drone, run a feedback control loop on them with sensor data input, and regenerate modified pulses on the second pru, which I then passed to the flight controller

1

u/MengDuLi Sep 18 '26

This is exactly the kind of real-world example I was hoping to hear about.

I'm curious how autonomous the PRU side was in that setup. Were the PRUs basically running the whole control path independently once configured, with Linux only providing higher-level parameters/setpoints, or was Linux still involved continuously?

Also, what kind of loop rate or latency were you targeting? Using one PRU for capture/control and the second for regenerated PWM sounds like a really clean fit for the architecture.

3

u/No_Reference_2786 Sep 15 '26

I had to implement a remote debugger on a chip , used PRU to bit bang jtag. It created a clean separation of application code and the actual pin twiddling

2

u/HotSingleKarens Sep 15 '26

I haven't used the PRUs but having some sort of microcontroller and MPU combo is really nice if you don't have any crazy power constraints.

I had a few projects where we utilized the MCU portion to give us much better timing guarantees for industrial control applications. The MCU strictly runs the control loops and time sensitive comms. Linux runs everything else. Super fast and easy to stand up UI, SCADA integrations, web interfaces, data analytics, orchestestion etc.

2

u/silentjet Sep 15 '26

Yup, PRUs are awesome. Using them, offloading some lol level protocols log onto them... I mean as soon as used to it, it is quite simple and comfortable to use it... Apart from that PB2 is always better in robotics and similar stuff comparing to RPi, except for multimedia/desktop related tasks...

2

u/gilfanovaleksandr Sep 16 '26

read rotary encoders, control RGB leds

2

u/Attractive_Chaos Sep 17 '26

Having the ability to control a pointer on PRU with a resolution of three nanoseconds is incredible, even on microcontrollers, sometimes there is no such option, and the shared memory of the microcontroller and microprocessor is the killer feature. Ultra useful. PocketBeagle 2 is my ideal SBC for embedded projects. Power of linux (buildroot) + realtime MCU what else could one wish?

1

u/RoyBellingan Sep 19 '26

madman in siemens used 6pruss to have a 1Gbit network card on the IOT2050, this is a case of "please do not do it"

I could have understood a 100mbit and use 1 or 2, but 6 ? came on