Friday 30 August 2019

BeagleBone Black PRU

BeagleBone Black - Adventures with PRU

 Part of 'How fast can you make a GPIO toggle, I have now just done a torture GPIO toggle on BeagleBone just to see how fast it can run.

From the looks... it may just do the trick! - hopefully emulate a RAM chip and peripherals in an Amiga!

The Setup,

From The PRU guide on Element 14 the setup is pretty straight forward main difference is you dont need to install the code composer studio as the BBB gets configured with all the PRU software. What you do need are the samples; and put them anywhere you like.

 Update the kernel - nice but not really needed
  1. sudo /opt/scripts/tools/update_kernel.sh  
  2. sudo apt update  
  3. sudo apt upgrade  
  4. sudo apt dist-upgrade 
Connect to the BBB and link the compilers and do the export.
ln -s /usr/bin/ /usr/share/ti/cgt-pru/bin
export PRU_CGT=/usr/share/ti/cgt-pru

Next to get the sample code from GIT

git clone git://git.ti.com/pru-software-support-package/pru-software-support-package.git 
Change to the directory with the examples downloaded in the previous step - and run the makefiles
cd /opt/source/pru-software-support-package/examples/am335x
make
 Once compiled, set the IO pins
sudo config-pin P9_27 output
sudo config-pin P9_27 pruout
 and then copy the firmware files to /lib/firmware on the BBB

cd /sys/class/remoteproc/remoteproc1
 echo '<firmware name>' firmware
 echo 'start' > state
*NOTE - the example in the download does not toggle P9_27 - change to 0x0020 in the sources ffor gpio.

From the small application - Toggling P9_27; there is 25nSecond for one pulse. Loaded in to the PRU and voila!

#include <stdint.h>
#include <pru_cfg.h>
#include "resource_table_empty.h"

volatile register uint32_t __R30;
volatile register uint32_t __R31;

void main(void)
{
        volatile uint32_t gpio;

        /* Clear SYSCFG[STANDBY_INIT] to enable OCP master port */
        CT_CFG.SYSCFG_bit.STANDBY_INIT = 0;

        /* Toggle GPO pins TODO: Figure out which to use */
        gpio = 0x0020;
        while (1) {
                __R30 ^= gpio;
//              __delay_cycles(100000000);
        }
}
 
From the FFT trace - there is all sorts of frequencies in there.. the harmonics are awesome!


Update:

Even without using high speed PRU GPIO pins, the access to normal pins from the PRU is still quite a respectable 80nSeconds. (ignore the yellow trace, its connected to the high speed line which is doing nothing)


Avaliable Pins on a BeagleBone Black




STM32F4 Interrupt latency - how fast can it go

STM32F4 - Interrupt latency

Following on from the ESP32, (ESP32 Interrupt Latency) I had a STM32F401RE Neucleo board lying about.. this was the next test bed for how fast can an interrupt go; and how fast can it manupulate a GPIO. Using OpenSTM32 development package and in C (no assembler yet)

First try - Using an Interrupt

My first experiment was with INTERRUPT routines. This shows how long it takes for the STM32F4 to act on an ISR  - 3uSeconds from the trace.


The YELLOW trace is the GPIO line dropping, the CYAN trace is another pin being cleared within the ISR function. I have a target of 100nSec to reach; I think that target is a bit much for this CPU


How fast can it actually toggle?

One thing I didn't look at was how fast the pin can be toggled.


Hmm... ~300nSecond for one pulse- and that is a while(1) set clear set clear loop using register access.  If the chip cant toggle at a fast pace, I dont think I have any hope reading a GPIO in a busy-wait loop.

Conclusion

The STM32F4 CPU isnt quick enough to interface directly to an 8Mhz bus on the Amiga. 

NEXT

The BeagleBone PRU speed ... https://gruhouse.blogspot.com/2019/08/beaglebone-black-adventures-with-pru-of.html