Project Report for GSoC 2021

MicroPython for BeagleConnect Freedom

Table of contents

  1. About
  2. Introduction
  3. Detailed Implementation
    1. Flashing and validating the Zephyr port of MicroPython
    2. GPIO Class
    3. I2C Class
    4. UART Class
    5. SPI Class
    6. Documentation:
  4. Benefits
  5. Conclusion
  6. Future Improvements
  7. References

About

  1. Student Name: Yadnik Bendale
  2. Mentors: Jason Kridner, Deepak Khatri, Tim Orling
  3. GSoC entry link: https://summerofcode.withgoogle.com/projects/#6316697687949312
  4. Blog link: https://yadnik1.github.io/Yadnik1-GSoC-2021.github.io/
  5. Introductory video: https://www.youtube.com/watch?v=x1hBazDr2Bk
  6. Proposal link: https://elinux.org/BeagleBoard/GSoC_2021/Micropython_for_BeagleConnect_Freedom

Introduction

BeagleConnect Freedom board is based on the Zephyr Project which is a scalable real-time operating system (RTOS). It has its main applications in the Internet of things and Industrial Internet of things domain.The board contains 2 mikroBUS connectors for connecting any of the hundreds of Click Board mikroBUS add-on devices. Until this project BeagleConnect Freedom could only be operated using the Zephyr RTOS and Greybus protocol for various IOT applications.This project enables users to take MicroPython into use, using the zephyr port of MicroPython, increasing the versatility of BeagleConnect Freedom and making it more user friendly. Enabling users to write minimal code in MicroPython for interfacing various sensors, actuators and indicators. The goal of the project intitially was to enable MicroPython and CircuitPython for BeagleConnect Freedom along with basic UART, GPIO, I2C, SPI, PWM, ADC drivers. As the project progressed, on discussion with mentors we decided to leave the CircuitPython port for now and focus on implementing click boards based on UART, GPIO, I2C and SPI classes considering the time constraint.

Detailed Implementation

1. Flashing and validating the Zephyr port of MicroPython:

The first step of the implementation of the project was actually building and flashing the MicroPython application firmware on BeagleConnect Freedom board.Starting off, the board needs to be upstreamed and present in the Zephyr repository, so that users can clone the repository on their local machine and flash it directly.For the same I worked on the Documentation and branding, alongwith adding the SPI node in the device tree file of the board for hardware interfacing.I also enabled the hardware features like SPI and I2C in the defconfig file.For the firmware to build the boards files were also supposed to be added in the MicroPython repository in the zephyr port section.For the same I opened 2 pull requests:

  1. Making necessary changes to board files in Zephyr repository: https://github.com/jadonk/zephyr/pull/9
  2. Adding Board and enabling hardware features in MicroPython repository: https://github.com/micropython/micropython/pull/7696

Followed by this the flashed application firmware was also tested by performing certain basic Python operations and blinking LEDs, both on board and externally.

2. GPIO Class:

Taking the GPIO class into use I was able to run 2 click boards directly, writing their respective driver codes. I also implemented 2 click baords based on the PWM class by applying minimal delay using GPIO pins.

  1. Relay click: Was able to take the 2 relays on board into use by enabling and disabling them.
  2. Water detect click: Was able to detect the presence of water on board,returning 0 in absence and 1 in presence of water.
  3. Haptic 2 click: Operated a coin vibration motor using the motor driver of the click board.
  4. Buzz 2 click: Could get the Buzzer to work, emitting sound at maximum pitch.

3. I2C Class:

Both the click boards were successfully implemented on the I2C class. Wrote driver code for the 2 click boards operating on this peripheral to get the required readings from them.

  1. Temperatre and Humiditiy 13 click: The click board accurately returned Temperature and Humidity values.
  2. Air quality 4 click: Could get the Total volatile organic compounds (TVOC) and CO2 equivalent readings accurately and tested it extensively in various scenarios.

4. UART Class:

Implementing boards on UART and SPI class turned out to be blockers in this project.Tested out the read and write operations by sending data from BeagleConnect Freedom to other board and observed output on serial monitor. I wrote the driver class for the GPS click and Ultrasonic click also getting them verified from the MicroPython community, however could not get the desired output from them.

  1. GPS click: Wrote the driver code for the GPS click to receive GPGGA data,however could not receive and print the GPGGA sentence.
  2. Ultrasonic 2 click: Wrote driver code to print the distance,however my code prints 0’s only.

To tackle the problems encountered I tried using a logic analyzer, probing both RX and TX lines however observed that there was no activity on the RX side of the board.For the GPS click along with the logic analyzer I also tried debugging on the hardware side, by attaching an antenna and by using an alternative GPS, like the Adafruit Ultimate GPS. Also observed that the UART class was a work under progress,some methods like uart.init() used for intitialising the baud rate were not implemented.

5. SPI Class:

Was able to write a driver code for the Accel 10 click,however learned towards the end of my project timeline that SPI class for the particular port could only be initalised.Read and write operations of registers could not be performed,due to which could not run the click boards on this peripheral class.

6. Documentation:

This was the first time someone was using the Zephyr port of MicroPython so extensively and hence effective documentation was a very important apsect of this project.I documented both I2C and GPIO classes implementation from ground up including the basics and how to’s required, like building and flashing the application firmware. All the driver code I have written is present in the Github repository.I also uploaded videos on Youtube with explanation of all the click boards I was able to run.

  1. Playlist of Youtube Videos: https://www.youtube.com/watch?v=x1hBazDr2Bk&list=PLbZw2G3ld0D471Cp4zPe0opPVPxQNkkxe
  2. Posts on blog: https: https://yadnik1.github.io/Yadnik1-GSoC-2021.github.io/
  3. Github repository: https://github.com/Yadnik1/Examples-Zephyr-port-of-MicroPython-

Benefits

With this project the users of BeagleConnect Freedom or any other users working on the Zephyr Port of MicroPython will be able be able to take MicroPython effectively into use for building their application.With the work done on this project there is enough documentation suggesting the differences between the Zephyr and generic port of MicroPython.Also drivers for some sensor ICs were written for the first time under this project.Users from the zephyr community can also take instances from this project when using MicroPython on boards having Zephyr support increasing the reach of MicroPython multifold. Under this project MicroPython code was written for the first time for the Mickroe Click boards, generally working in C language. With the various questions I asked on forums, it will also make it easier for Zephyr port users to locate the state of the project and clear their doubts since no official documentation for this port exists apart from the Readme file available on the MicroPython repository.

Conclusion

I will continue to support this project in the future, take care of any bugs, issues and will continue implementing additional features whenever required.I will also work post GSoC to complete the missed goals of this project. It was a great journey and I did get to learn a lot working in this project.These 10 weeks have been a great learning experience. I would like to thank BeagleBoard.org Foundation and Google for giving me such an amazing opportunity. Furthermore, I would like to thank my mentors Jason,Deepak and Tim for their constant support and guidance, also the members of BeagleBoard.org Foundation, namely Cathy ,Vaishnav, and fellow participants whom I also learnt a lot from.

Future Improvements

  1. In this GSoC I could not focus much on PWM and ADC classes as the priority was to implement the remaining classes for which driver code had been more or less written.Post GSoC I would be looking into this.
  2. Having dedicated board and SoC files for CC1352P for Zephyr Project would be very beneficial in the long run.
  3. On discussing with Mentors and Adafruit community there is potential of a dedicated CircuitPython port for BeagleConnect Freedom.

References

This is a curated collection of links I used throughout the project:

https://github.com/micropython/micropython/blob/master/ports/zephyr/README.md https://github.com/MikroElektronika/mikrosdk_click_v2/tree/master/clicks https://github.com/mcauser/awesome-micropython https://github.com/jadonk/beagle_connect_zephyr_board https://docs.micropython.org/en/latest/ https://docs.zephyrproject.org/latest/

 Share!

 
comments powered by Disqus