Skip to content
Archisman Dey edited this page Aug 28, 2021 · 12 revisions

Improvements to simpPRU

This is a Google Summer of Code 2021 project that builds upon the work done in GSoC 2020 to make programming the PRU easier for beginners with the aim of:

  1. add unit tests for every language feature of simpPRU
  2. add support for the robotics focussed BeagleBone Blue
  3. add the ability to use hexadecimal ints, and support for modulo and bitshift operators in arithmetic operators
  4. update the grammar so that control statements (break / continue) can be called inside loops only
  5. update the grammar so that return statements can be called anywhere in a function
  6. add support for a char/uint8 data type that works with integers
  7. add support for C style static arrays
  8. add a more flexible for loop with start : stop : increment syntax
  9. add the ability to send chars, bools, and arrays to the host through RPMSG framework

This will make the overall language more robust and complete, which will help beginners learning to use the PRU or experienced users prototyping something on the PRU.

Project Details

Table of Contents

What is the PRU?

Texas Instruments’ Sitara AM335x and AM5729 processors are built of several CPUs, including two programmable real-time units (PRUs). These are 200MHz 32-bit microcontroller CPUs with a zero-depth pipeline and single-cycle access to a collection of pins and peripherals optimized for implementing software-defined peripherals. The PRUs don’t have pre-defined tasks in the system and are free from the Linux scheduler, so they are ideal for predictable low-latency tasks, a must-have feature for building quadcopters, 3D printers and balancing robots, just to name a few.

What is simpPRU?

Developed during GSoC 2020, simpPRU is an intuitive, statically typed and compiled language that transpiles down to PRU C and is then compiled using pru-gcc. It aims to make programming the PRU easier and more beginner friendly by including PRU specific features and offering a one command workflow.

Brief Overview of Technical Stack of simpPRU

  • simpPRU uses flex to generate the lexer and bison to generate the parser.
  • A custom code printer was written to convert the generated AST into PRU C, which is compiled into machine code by pru-gcc.
  • For communication between the PRU and the host CPU, functions are provided to send and receive messages through rpmsg.
  • It exposes access to the GPIO pins of the device by providing digital_write and digital_read functions.

Contributions

I have divided the list of contributions according to the pull requests I have sent:

Merged on July 13th, 2021

Things Added

  1. --preprocess flag that stops simpPRU after generating the intermediate C code (stored at /tmp/temp.c)
  2. -t flag to use stub functions instead of the PRU specific functions (useful for debugging on non-beagle hardware)
  3. print() and println() functions while using -t, which can print any int or bool identifier

Comments

I have generalised the print functions in a later PR to enable them to print arithmetic or boolean expressions rather than only a single identifier

Merged on July 15, 2021

Things Added

  1. test files for most of the previously implemented language features, along with their expected outputs
  2. a Python script for automated testing that compiles and runs all the tests and matches the outputs with the expected outputs

Comments

  • This caught a bug that prevented the looping variable in for loop from being visible inside the loop, which was later fixed by Vedant Paranjape (maintainer of simpPRU).
  • Test coverage should be improved later.

Merged on July 25, 2021

Things Added

  1. support for the modulo (%) operator
  2. support for octal (starting with 0) and hexadecimal (starting with 0x or 0X) integers
  3. made bitwise operators work on arithmetic expressions instead of only boolean expressions
  4. bitshift operators >> and << (left and right shifts) which work on integers
  5. tests for the above and updated documentation

Merged on July 27, 2021

Things Added

  1. fixes the issue where control statements could be called anywhere rather than inside loops only
  2. tests and updated documentation for the above

Comments

This ended up being a lot simpler than I thought, rather than an update to the grammar, this only required some keyword checking and simple bracket counting in the lexer.

Merged on August 2, 2021

Things Added

  1. a new for loop syntax with the range expression start: end: increment, here end can be smaller than start if increment is negative
  2. ability to skip start, which makes start zero by default, and the range expression looks like : end

Comments

Since it is not always possible to know whether start or end is smaller, this prints two for loops in the generated C code although only one of them run.

Merged on August 11, 2021

Things Added

  1. a char/uint8 data type that can be initialized from either a character literal (single quoted character) or from an integer
  2. ability to use chars as parameters and return values of functions
  3. print and println functions were modified to add support for printing characters
  4. added unit tests and updated the documentation to mention chars

Comments

In this PR, print and println functions print chars as characters, however a later PR changes this to print the equivalent ascii value of the character instead.

Merged on August 19, 2021

Things Added

  1. static arrays, where the size of array has to be specified during declaration
  2. indexing and modifying elements of an array (arrays are zero indexed)
  3. ability to use array elements as parameters and return values of functions
  4. initialising char arrays from string literals
  5. unit tests and documentation for arrays

Comments

  • Arrays themselves cannot be used as function parameters or return values yet since array lengths are not implicitly tied to arrays in C. A possible implementation of using arrays as function parameters with the length as a ghost parameter can be considered later.
  • Adding support for initializing integer and boolean arrays with a syntax similar to Python would be nice.

Pull Request is open as of August 20, 2021

Things Added

  1. send_int, send_char, send_bool functions to send integers, characters, and boolean variables to the host respectively
  2. send_message is kept as an alias of send_int to preserve backwars compatibility
  3. send_ints, send_chars, send_bools functions to send integer, character, and boolean arrays to the host respectively
  4. arrays are sent by converting them to space seperated strings
  5. updated documentation for rpmsg functions

Comments

This increases the complexity of the generated C code by quite a bit, the generated assembly file has to be examined later to see if the unused code is being eliminated by the compiler. If not, appropriate compiler flags have to be added.

Pull Request is open as of August 20, 2021

Things Added

  1. the language grammar has been updated to allow return statements anywhere in the function body rather than at the end only
  2. unit tests and documentation reflecting the change

Comments

Not enough error checking is there for this feature yet, it needs to be added before this PR is merged.

Merged on August 19, 2021

Things Added

  1. pinouts for the BeagleBone Blue in JSON format
  2. code for checking which BeagleBone simpPRU is running on has been updated to support the Blue

Comments

As I did not have a logic analyser or things like motors and servos during this summer, I could not test support for the IO pins of the Blue yet. As a result, the documentation has not been updated to include the pinouts for the Blue. This will be updated as soon as I test it properly.

Things to be implemented in the future

Apart from things mentioned in comments under my contributions, there are a few things that would be nice to haves and things I would like to implement after GSoC:

  • ability to use extra compiler flags while calling simppru, these flags get added while calling pru-gcc, helpful for setting optisation flags for example
  • support for using PWM using eCAP module: analog_write() and analog_read() functions
  • indicator for PRU on/off state in simppru-console - Issue #24

Conclusion

All the goals that were originally proposed have been completed to the best of my abilities (although some have not been merged yet). I have specified some things that can be improved in comments under my contributions topic, and some things that can be implemented in the future in the previous topic. I will be working on those things in the coming weeks to make simpPRU into a more complete platform.

I am extremely grateful to my mentors Pratim and Abhishek for their help and support in the last two months, Vedant (creater and maintainer of simpPRU) for providing help and reviewing code, several other people in the community who have provided various inputs while I was making my proposal and during the coding period, and lastly to the community admins Cathy and Jason who made sure everything ran smoothly and everyone got their hardware on time.

I am also thankful to Google for providing me the oppurtunity to work on this project during the summer, which helped me learn a lot and will also surely help in my career in the future.

Resources