-
Notifications
You must be signed in to change notification settings - Fork 0
Home
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:
- add unit tests for every language feature of simpPRU
- add support for the robotics focussed BeagleBone Blue
- add the ability to use hexadecimal ints, and support for modulo and bitshift operators in arithmetic operators
- update the grammar so that control statements (break / continue) can be called inside loops only
- update the grammar so that return statements can be called anywhere in a function
- add support for a char/uint8 data type that works with integers
- add support for C style static arrays
- add a more flexible for loop with start : stop : increment syntax
- 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.
- Name: Archisman Dey
- Mentors: Abhishek Kumar, Pratim Ugale, Andrew Henderson, Vedant Paranjape
- Organization: BeagleBoard.org
- Proposal Page: Improvements to simpPRU on eLinux
- Code: https://github.com/VedantParanjape/simpPRU/pulls
- Project Page: https://summerofcode.withgoogle.com/projects/#4991291718369280
- Progress log: https://forum.beagleboard.org/t/weekly-progress-report-thread-improvements-to-simppru/30120
- Introductory Video: https://www.youtube.com/watch?v=-zZ57sqQPSY
- What is the PRU?
- What is simpPRU?
- Brief Overview of Technical Stack of simpPRU
-
Contributions
- Print functions and flags for debugging and testing
- Unit tests for previously implemented features
- Hexadecimal integers, modulo and bitwise operators for arithmetic expressions
- Calling break and continue only inside loops
- A more flexible for loop
- A char/uint8 data type
- C style static arrays
- New functions for sending bools, chars, and arrays through RPMSG
- Return statements anywhere inside function
- Support for the BeagleBone Blue
- Things to be implemented in the future
- Conclusion
- Resources
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.
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.
- 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.
I have divided the list of contributions according to the pull requests I have sent:
Merged on July 13th, 2021
- --preprocess flag that stops simpPRU after generating the intermediate C code (stored at /tmp/temp.c)
- -t flag to use stub functions instead of the PRU specific functions (useful for debugging on non-beagle hardware)
- print() and println() functions while using -t, which can print any int or bool identifier
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
- test files for most of the previously implemented language features, along with their expected outputs
- a Python script for automated testing that compiles and runs all the tests and matches the outputs with the expected outputs
- 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.
3. Add support for hexadecimal ints, modulo and bitshift operators, and bitwise operators for arithmetic expressions
Merged on July 25, 2021
- support for the modulo (%) operator
- support for octal (starting with 0) and hexadecimal (starting with 0x or 0X) integers
- made bitwise operators work on arithmetic expressions instead of only boolean expressions
- bitshift operators >> and << (left and right shifts) which work on integers
- tests for the above and updated documentation
Merged on July 27, 2021
- fixes the issue where control statements could be called anywhere rather than inside loops only
- tests and updated documentation for the above
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
- a new for loop syntax with the range expression start: end: increment, here end can be smaller than start if increment is negative
- ability to skip start, which makes start zero by default, and the range expression looks like : end
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
- a char/uint8 data type that can be initialized from either a character literal (single quoted character) or from an integer
- ability to use chars as parameters and return values of functions
- print and println functions were modified to add support for printing characters
- added unit tests and updated the documentation to mention chars
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
- static arrays, where the size of array has to be specified during declaration
- indexing and modifying elements of an array (arrays are zero indexed)
- ability to use array elements as parameters and return values of functions
- initialising char arrays from string literals
- unit tests and documentation for arrays
- 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
- send_int, send_char, send_bool functions to send integers, characters, and boolean variables to the host respectively
- send_message is kept as an alias of send_int to preserve backwars compatibility
- send_ints, send_chars, send_bools functions to send integer, character, and boolean arrays to the host respectively
- arrays are sent by converting them to space seperated strings
- updated documentation for rpmsg functions
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
- the language grammar has been updated to allow return statements anywhere in the function body rather than at the end only
- unit tests and documentation reflecting the change
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
- pinouts for the BeagleBone Blue in JSON format
- code for checking which BeagleBone simpPRU is running on has been updated to support the Blue
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.
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
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.
- Share internet between laptop and BeagleBoards: https://gist.github.com/pdp7/d2711b5ff1fbb000240bd8337b859412
- Tutorial for writing a simple compiler from scratch: Writing a simple compiler on my own