BeagleBoard/GSoC 2021/Micropython for BeagleConnect Freedom

=BeagleBoard/GSoC 2021/Micropython for BeagleConnect Freedom =

About Student: Yadnik Bendale Mentors: Jason Kridner Code: https://github.com/micropython/micropython/tree/master/ports/zephyr Wiki: N/A GSoC: N/A

=Status= This project is currently just a proposal.

=Proposal= I have completed all the project requirements listed on the ideas list and have opened the pull request here.

About you
IRC: Yadnik Bendale Github: Yadnik1 School: Dwarkadas J Sanghvi College Of Engineering Country: India Primary language:English,Hindi,Marathi Typical work hours: 9AM-9PM IST Previous GSoC participation: I am very keen on working in Embedded Systems and Internet of Things.Doing the Micropython for BeagleConnect Freedom project greatly intrigues me and will definitely enable me to make a significant impact to the community by increasing the functionality of the BeagleConnect Freedom device.I wish to keep contributing to the BeagleConnect Freedom project and one day see it being used as one of the most adapted products in the IOT and IIOT field. This is my first time participating in GSoC.

About your project
Project name: Micropython for BeagleConnect Freedom

Description
Introduction: BeagleConnect is a revolutionary technology which eliminates low-level software development for IoT and IIoT applications,such as building automation, factory automation, and home automation.What sets it apart is that it eliminates the need of relying on software libraries enabling it to be used for interfacing a greater number of sensors, actuators and indicators for communicating over various networks compared to other conventional solutions.This can be achieved since it is built with fully open source software with submissions to mainline Linux and Zephyr repositories to aide in support and porting. The BeagleConnect Freedom is based on the TI CC1352R and is the first available BeagleConnect solution which runs the Zephyr RTOS and has mikroBUS ports along with BLE and Sub-GHz radios on it.The BeagleConnect has a few technologies at the core namely IPv6 (via 6LoWPAN),Zephyr support for IEEE 802.15.4 and Greybus from Project Ara. The goal of this project is to port Micropython and Circuitpython support along with GPIO, I2C, SPI, PWM, UART and ADC drivers support in MicroPython for the BeagleConnect solution.After the porting is completed and the drivers have been inculcated,the practicality will be thoroughly tested with the help of MikroElektronika click boards of each respective protocol and documented on my blog. Before starting the porting process I will first figure out how the USB accesses the TI CC1352R MCU since the MSP430 connects to USB and then connects via UART and I2C to the CC1352R MCU in the BeagleConnect Freedom which I came to know after discussing with my mentor. A solution to tackle this would be to be to use the MSP430USBDEVPACK where the TI CC1352R will be enumerated as virtual com port and code on PC side will be the same like that for UART. Another approach would be using instances of open source ftdi usb to ttl driver code. Project Deliverables: 1)Porting MicroPython  MicroPython is a completely free and open source software that is a lean and efficient implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimised to run on microcontrollers and in constrained environments.A few of its salient features that will be advantageous for the BeagleConnect include: Execution: There is ample of documentation related to porting Micropython to the Zephyr RTOS Running on Beagleconnect. The most comprehensive guide can be found in the MicroPython port to Zephyr RTOS repository. west build -b ~/micropython/ports/zephyr   west debug If I find any difficulty while navigating through I will rely on the Micropython repository and the Micropython forum page. 2)Porting Circuitpython:  CircuitPython is a programming language designed to simplify experimenting and learning to program on low-cost microcontroller boards.It is majorly built for Adafruit devices and has a very active community base. CircuitPython is designed with education in mind. It's easy to start learning how to program and the user gets immediate feedback from the board.This will enable even a novice user to take complete advantage of the BeagleConnect Freedom device.A few of its salient features that will be advantageous for the BeagleConnect include: Execution: The core code of MicroPython is shared amongst ports including CircuitPython. There is also Documentation released by Adafruit for creating ones own port. For reference purposes i will constantly refer the CircuitPython Documentation and the forums for effective flow of the porting process. I will test various pins and features of the board using some hardware like LEDs, resistors and EEPROM after each individual port in accordance with the basic Board Tests.Pull requests will be generated for all the work done to the respective upstream repositories. 3)Writing drivers in MicroPython:  I will be following a general procedure as given below for writing GPIO, I2C, SPI, PWM, UART and ADC drivers for the BeagleConnect Freedom.Once done I will test it with MikroElektronika click boards,2 boards supporting each protocol to validate operation of both simultaneously as well as combined with another board using some other protocol. Procedure for drivers in Micropython:  The BeagleConnect Freedom is based on the CC1352R Launchpad development kit,which houses the SimpleLink CC1352R wireless MCU.A structured approach for writing drivers would be From machine import UART  uart=UART(1,baudrate=9600,bits=8,parity=none,stop=1) uart.write(b ‘\XAA’) Here we import the UART class,we initialise an instance and we pass as constructor parameters the settings we need to configure after which we can use simple methods like read and write to get data to and from the device. A list of constructors and methods for writing each driver can be found on the Micropython official website: 1)Universal asynchronous receiver-transmitter (UART) 2)Inter-integrated circuit(I2C) 3)Serial Peripheral Interface (SPI) 4)Pulse Width Modulation(PWM) 5)Analog to Digital Converter(ADC) 6)General-Purpose Input/Output(GPIO) The official document by the Micopython is a great resource to refer to in general. For maximizing micropython execution speed I will take these things into consideration for a highly optimized driver code. Hardware requirements: 1)BeagleConnect Freedom node and gateway device 2)MikroElektronika click boards 2 each supporting each protocol(While selecting the click boards the number one priority is which boards have maximum probability to be used at the nodes end). UART: I2C SPI GPIO PWM ADC 3)General Hardware required:
 * It provides an interactive prompt (the REPL) to execute commands immediately, along with the ability to run and import scripts from the built-in filesystem. The REPL has history, tab completion, auto-indent and paste mode for a great user experience.
 * Highly configurable due to many compile-time configuration options
 * Code coverage at 98.4% for the core and at 96.3% for the core plus extended modules
 * I will start with installing Zephyr SDK, getting Zephyr source code, and setting up development environment followed by configuring the environment, for example by sourcing  zephyrproject/zephyr/zephyr-env.sh.
 * I will then clone the MicroPython repository into the home directory and build the Zephyr port for the BeagleConnect Freedom board like this:
 * Followed by this is I will flash it to the board and start a gdb debug session using:
 * The serial console and REPL allow for live feedback from your code and interactive programming
 * The internal storage for CircuitPython makes it great for data-logging, playing audio clips, and otherwise interacting with files.
 * There is no compiling, no downloading and no uploading needed due to which it runs immediately just after creating a file, editing the code and saving the file.
 * The first step would be creating a UF2 Port by Cloning the Adafruit uf2-samdx1 repository followed by creating a new folder in boards/ with the particular board name.I will also refer other board files as examples for how to fill out the board files.
 * The next step will be cloning the Adafruit CircuitPython repository and creating a new folder with the board name.
 * To first go through the memory map of the microcontroller present in its datasheet.
 * After obtaining the range of memory addresses where the peripherals are located,the memory address associated with each peripheral can be obtained.
 * From the memory address the register map can be observed from where we can incur each offset address of a register which is basically a word for the microcontroller to perform a particular action. A sample code for the UART protocol can be seen as follows:
 * GPS CLICK
 * ULTRASONIC 2 CLICK
 * AIR QUALITY 4 CLICK
 * TEMP&HUM 13 CLICK
 * AMR ANGLE CLICK
 * THERMO CLICK
 * WATER DETECT CLICK
 * RELAY CLICK
 * BUZZ 2 CLICK
 * HAPTIC 2 CLICK
 * ECG CLICK BUNDLE
 * THREE AXIS ACCELEROMETER
 * LEDs
 * Resistors
 * EEPRPOM

Timeline
Provide a development timeline with a milestone each of the 11 weeks and any pre-work. (A realistic timeline is critical to our selection process.)

Experience and approach
I am a pre final year student having good understanding of C,C++,OpenGl and Python.I have experience working with various Develeopment Boards like a variety of Arduino,STM and Teensy boards and SBC's like Beaglebone Black,Raspberry Pi and BalenFin. I also interned at Blue Pheonix Tech where I worked in the domain of Embedded Systems and IOT. I worked on the development of WorkSafe an IOT product used for monitoring Spo2, heart rate along with body and ambient temperature with face detection.I was responsible for developing the entire IOT functionality that involves interfacing of the esp32 cam, nodemcu and sensors with the software interface.

I have been consistently taking part in all the contests on Hackster.io and had also won a prize in the Deep Learning Superhero Challenge there for my work on Making a People Counter using the OPENVINO Toolkit.I have also been a part of the Swadeshi Microprocessor Challenge,where my team has entered the semi-finals for making an FPGA accelerated remote vital stats monitoring device to measure SPO2, ECG and pulse rate using a technology called remote-Plethysmography. The video for the same can be found here. I have prior experience working under mentors in technical teams of my college. DJS Arya,the team I am a part of designs,manufactures and fabricates a canister size satellite for the Cansat Competetion,where I am responsible for the entire sensor subsystem integration,writing flight software code and data telemetry using the zigbee protocol. I have thoroughly gone through Zephyr RTOS,Micropython and CircuitPython repositories with their official documentation which provided me invaluable clarity towards the project. Hence,I am confident that I will be able to complete the project in the stipulated time.

Contingency
My belief has always been to ask my mentors only after giving my best towards that respective task and is definitely the way to go in open source. However in a case where I am out of resources and my mentor isn't around I will divert my focus towards documentation or towards a part of the project that is not correlated to the part I am stuck with. In such a case few references i would like to refer are: 1)Official Micropython documentation. 2)Official Circuitpython documentation. 3)Adafruit CircuitPython and MicroPython forums. 4)For adding driver support the SimpleLink CC1352R wireless MCUreference manual and datasheet.

Benefit
Once completed the functionality of the BeagleConnect will be greatly enhanced.It will be complete with the support of MicroPython which is used more by the mainstream community as well as CircuitPython which is more beginner friendly and easy to use.Thus users from varied level of experience and domain knowledge will be able to take full advantage of BeagleConnect along with driver support for varied peripherals in Micropython. In totality the BeagleConnect Freedom will come loaded with Greybus,MicroPython and CircuitPython in the same firmware enabling the users to dive deeper into hardware. Hence BeagleConnect will be one of the go to choices be it for hobbyist projects or for enterprise level products in the domain of IOT and IIOT. If there was Micropython and Greybus in the same firmware load, that might be pretty cool. as I'd said, it is more an exercise of getting good support for the hardware into upstream Zephyr and exposing the functionality in an easy to use way. -Jason Kridner

Misc
I have completed the requirements stated in the ideas page,the cross compilation task can be found here and the created the pull request can be found here

Suggestions
Is there anything else we should have asked you?