Difference between revisions of "BeagleBoard/GSoC 2021/Micropython for BeagleConnect Freedom"

From eLinux.org
Jump to: navigation, search
 
(52 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
 
[[Category: BeagleBoard]]
 
[[Category: BeagleBoard]]
 
[[Category: GSoC]]
 
[[Category: GSoC]]
Line 4: Line 5:
  
 
=[[BeagleBoard/GSoC 2021/Micropython for BeagleConnect Freedom]] =
 
=[[BeagleBoard/GSoC 2021/Micropython for BeagleConnect Freedom]] =
{{#ev:youtube|Jl3sUq2WwcY||right|BeagleLogic}} <!-- latest video will go here -->
+
 
 
About
 
About
''Student'': [http://elinux.org/User:student new student]<br>
+
''Student'': [https://elinux.org/User:Yadnik_Bendale Yadnik Bendale]<br>
 
''Mentors'': [http://elinux.org/User:Jkridner Jason Kridner]<br>
 
''Mentors'': [http://elinux.org/User:Jkridner Jason Kridner]<br>
''Code'': https://github.com/deebot/Beaglebone-BidirectionBus<br>
+
''Code'': https://github.com/micropython/micropython/tree/master/ports/zephyr<br>
''Wiki'': http://elinux.org/BeagleBoard/GSoC/ProposalTemplate<br>
+
''Wiki'': N/A<br>
''GSoC'': [https://summerofcode.withgoogle.com/archive/2016/projects/4885400476712960/ GSoC entry]<br>
+
''GSoC'': N/A<br>
 
<div style="clear:both;"></div>
 
<div style="clear:both;"></div>
  
Line 17: Line 18:
  
 
=Proposal=
 
=Proposal=
Please complete the requirements listed on the [http://bbb.io/gsocideas ideas page] and fill out this template.
+
I have completed all the project requirements listed on the [https://elinux.org/BeagleBoard/GSoC/Ideas-2021 ideas list] and have opened the pull request [https://github.com/jadonk/gsoc-application/pull/150 here].
  
 
==About you==
 
==About you==
''IRC'': Freenode IRC nickname<br>
+
''IRC'': Yadnik Bendale<br>
''Github'': Github account<br>
+
''Github'': [https://github.com/Yadnik1 Yadnik1]<br>
''School'': School name<br>
+
''School'': [https://www.djsce.ac.in/ Dwarkadas J Sanghvi College Of Engineering]<br>
''Country'': Country<br>
+
''Country'': India <br>
''Primary language'' (We have mentors who speak multiple languages): Language<br>
+
''Primary language'':English,Hindi,Marathi<br>  
''Typical work hours'' (We have mentors in various time zones): 8AM-5PM US Eastern<br>
+
''Typical work hours'': 9AM-9PM IST<br>
''Previous GSoC participation'': Tell us why you want to participate in GSoC here. Also, provide list of URLs for any previous GSoC participation with any organizations.
+
''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==
 
==About your project==
''Project name'': Micropython for BeagleConnect Freedom <br>
+
''Project name'': MicroPython for BeagleConnect Freedom <br>
  
 
===Description===
 
===Description===
 
'''Introduction:'''<br>
 
'''Introduction:'''<br>
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.<br>  
+
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.<br>  
The BeagleConnect Freedom is based on the TI CC1352 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.<br>
+
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.<br>
The goal of this project is to port Micropython and Circuitpython support along with GPIO, I2C, SPI, PWM 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.<br>
+
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.<br>
 +
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 [https://www.ti.com/tool/MSP430USBDEVPACK 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 [https://github.com/eblot/pyftdi ftdi usb to ttl driver code].<br>   
 
'''Project Deliverables:'''<br>
 
'''Project Deliverables:'''<br>
1)Porting of Micropython<br>
+
<br>
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:<br>
+
'''1)Porting MicroPython<br>'''
 +
<br>
 +
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:<br>
 
* 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.<br>
 
* 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.<br>
 
* Highly configurable due to many compile-time configuration options<br>
 
* Highly configurable due to many compile-time configuration options<br>
* Code coverage at 98.4% for the core and at 96.3% for the core plus extended modules
+
* Code coverage at 98.4% for the core and at 96.3% for the core plus extended modules<br>
 +
<br>
 
'''Execution:'''<br>
 
'''Execution:'''<br>
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 [https://github.com/micropython/micropython/tree/master/ports/zephyr MicroPython port to Zephyr RTOS] repository.
+
<br>
 +
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 [https://github.com/micropython/micropython/tree/master/ports/zephyr MicroPython port to Zephyr RTOS] repository.
 
* 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.<br>
 
* 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.<br>
* I will then clone the MicroPython repository into the home directory and build the Zephyr port for the BeagleConnect Freedom board like this:
+
* I will then clone the MicroPython repository into the home directory and build the Zephyr port for the BeagleConnect Freedom board like this:<br>
   west build -b frdm_k64f ~/micropython/ports/zephyr
+
   west build -b ~/micropython/ports/zephyr<br>
 
+
* Followed by this is I will flash it to the board and start a gdb debug session using:<br>
 +
  west debug<br>
 +
If I find any difficulty while navigating through I will rely on the [https://github.com/micropython/micropython Micropython] repository and the [https://forum.micropython.org/ MicroPython forum page].<br>
 +
<br>
 +
'''2)Porting CircuitPython:<br>'''
 +
<br>
 +
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:<br>
 +
*The serial console and REPL allow for live feedback from your code and interactive programming<br>
 +
*The internal storage for CircuitPython makes it great for data-logging, playing audio clips, and otherwise interacting with files.<br>
 +
* 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.<br>
 +
<br>
 +
'''Execution:'''<br>
 +
<br>
 +
The core code of MicroPython is shared amongst ports including CircuitPython. There is also Documentation released by Adafruit for [https://learn.adafruit.com/installing-circuitpython-on-samd21-boards/advanced-creating-your-own-port creating ones own port].<br>
 +
* The first step would be creating a UF2 Port by Cloning the [https://github.com/adafruit/uf2-samdx1 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.<br>
 +
*The next step will be cloning the Adafruit CircuitPython repository and creating a new folder with the board name.
 +
For reference purposes i will constantly refer the [https://readthedocs.org/projects/circuitpython/downloads/pdf/3.x/ CircuitPython Documentation] and the forums for effective flow of the porting process.<br>
 +
'''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 [https://github.com/adafruit/Adafruit_CircuitPython_BoardTest Board Tests].Pull requests will be generated for all the work done to the respective upstream repositories.'''<br>
 +
<br>
 +
'''3)Writing drivers in MicroPython:<br>'''
 +
<br>
 +
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.<br>
 +
'''Procedure for drivers in Micropython:<br>'''
 +
The BeagleConnect Freedom is based on the CC1352R Launchpad development kit, which houses the [https://www.ti.com/lit/ug/swcu185d/swcu185d.pdf?ts=1618036665070 SimpleLink CC1352R wireless MCU].A structured approach for writing drivers would be<br>
 +
 +
*To first go through the memory map of the microcontroller present in its datasheet.<br>
 +
*After obtaining the range of memory addresses where the peripherals are located, the memory address associated with each peripheral can be obtained.<br>
 +
* 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.<br>
 +
The gc and MicroPython modules can be used to control collection and profile memory.<br>
 +
A sample code for the UART protocol can be seen as follows:<br>
 +
From machine import UART
 +
uart=UART(1,baudrate=9600,bits=8,parity=none,stop=1)
 +
uart.write(b ‘\XAA’)<br>
 +
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.<br>
 +
<br>
 +
I would like to go a further in depth with an example driver code initialisation in MicroPython.<br>
 +
[[File:Example_driver.jpeg|Example driver initialisation]]
  
 +
Here we can infer that:<br>
 +
• From the top part of the code, we come to know that it is initialising an I2C class. Then we
 +
see that it is reading a register and comparing that with a number.<br>
 +
• From the datasheet we can find out the register name and come to know what the register
 +
does, in this case it is a “who am I” register which basically checks if we are talking to the
 +
right device.<br>
 +
• The latter part of the code deals with writing into a register and reading it back expecting it
 +
to change in a loop. From the datasheet we come to know that writing this specific bit will
 +
reset the device and that bit will be set while it is resetting.<br>
 +
• The last part deals with normal write operations which write a register to perform a particular
 +
configuration, and we can look at the datasheet to figure out what has happened.<br>
 +
<br>
 +
A list of constructors and methods for writing each driver can be found on the MicroPython official website:<br>
 +
1)[https://docs.micropython.org/en/latest/library/machine.UART.html Universal asynchronous receiver-transmitter (UART)]<br>
 +
2)[https://docs.micropython.org/en/latest/library/machine.I2C.html Inter-integrated circuit(I2C)]<br>
 +
3)[https://docs.micropython.org/en/latest/library/machine.SPI.html Serial Peripheral Interface (SPI)]<br>
 +
4)[https://docs.micropython.org/en/latest/esp8266/tutorial/pwm.html Pulse Width Modulation(PWM)]<br>
 +
5)[https://docs.openmv.io/library/pyb.ADC.html Analog to Digital Converter(ADC)]<br>
 +
6)[https://docs.micropython.org/en/latest/esp8266/tutorial/pins.html General-Purpose Input/Output(GPIO)]<br>
 +
The [https://docs.micropython.org/en/v1.10/micropython-docs.pdf official document] by the Micopython is a great resource to refer to in general.<br>
 +
For maximizing microPython execution speed I will take [http://docs.micropython.org/en/latest/reference/speed_python.html these] things into consideration for a highly optimised driver code.<br>
 +
<br>
 +
Software required and Programming Languages<br>
 +
MicroPython will be used majorly for writing drivers along with all the necessary SDKs required for
 +
porting processes. The C programming language will be used for kernel-level programming and
 +
the GCC compiler along with other build tools will be used for compiling the C source code (*.c)<br>
 +
<br>
  
 
+
Hardware requirements:<br>
 
+
1)BeagleConnect Freedom node and gateway device<br>
 
+
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).<br>
 
+
UART:<br>
 +
* [https://www.mikroe.com/gps-click GPS CLICK]<br>
 +
* [https://www.mikroe.com/ultrasonic-2-click ULTRASONIC 2 CLICK]<br>
 +
I2C:<br>
 +
* [https://www.mikroe.com/air-quality-4-click AIR QUALITY 4 CLICK]<br>
 +
* [https://www.mikroe.com/temphum-13-click TEMP&HUM 13 CLICK]<br>
 +
SPI:<br>
 +
* [https://www.mikroe.com/amr-angle-click AMR ANGLE CLICK]<br>
 +
* [https://www.mikroe.com/smoke-2-click SMOKE 2 CLICK ]<br>
 +
GPIO:<br>
 +
* [https://www.mikroe.com/water-detect-click WATER DETECT CLICK]<br>
 +
* [https://www.mikroe.com/relay-click RELAY CLICK]<br>
 +
PWM:<br>
 +
* [https://www.mikroe.com/buzz-2-click BUZZ 2 CLICK]<br>
 +
* [https://www.mikroe.com/haptic-2-click HAPTIC 2 CLICK]<br>
 +
Analog(for ADC interface):<br>
 +
* [https://www.mikroe.com/ecg-click-bundle ECG CLICK BUNDLE]<br>
 +
* [https://www.mikroe.com/three-axis-accelerometer-board THREE AXIS ACCELEROMETER]<br>
 +
3)General Hardware required:<br>
 +
* LEDs
 +
*Resistors
 +
*EEPRPOM
 +
 
 
===Timeline===
 
===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.)
 
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.)
Line 63: Line 154:
 
|-
 
|-
 
| May 17 || Proposal accepted or rejected
 
| May 17 || Proposal accepted or rejected
 +
* Read and Research more on writing peripheral drivers and thoroughly go through the [https://www.ti.com/lit/ug/swcu185d/swcu185d.pdf?ts=1618036665070 SimpleLink CC1352R wireless MCU] reference manual.<br>
 +
* Order all the necessary hardware components<br>
 +
*Look up various approaches for effective communication for the TI CC1352R MCU via the USB of MSP430.
 
|-
 
|-
 
| Jun 07 || Pre-work complete, Coding officially begins!
 
| Jun 07 || Pre-work complete, Coding officially begins!
 +
*All the boards and hardware will be available to me and I will start with flashing the Zephyr RTOS on the BeagleConnect Freedom device.
 +
*Set up effective effective communication for the TI CC1352R MCU via the USB of MSP430.
 +
*Complete MicroPython port.
 +
*Test various pins and features using MicroPython and document it on my blog.
 +
* Generate pull request to the [https://github.com/zephyrproject-rtos/zephyr Zephyr RTOS] and [https://github.com/micropython/micropython MicroPython] upstream repositories.
 
|-
 
|-
| Jun 17 || Milestone #1, Introductory YouTube video
+
| Jun 17 || Milestone #1
 +
* Introductory YouTube video
 +
* Complete CircuitPython port.
 +
* Test various pins and features using CircuitPython and document it on my blog.
 +
* Generate pull request to the [https://github.com/zephyrproject-rtos/zephyr Zephyr RTOS] and [https://github.com/adafruit/circuitpython CircuitPython] upstream repositories.
 +
* Taking notes and feedback from my mentor regarding the progress of the porting, and address any issues if any.
 +
* By this stage I must have completed adding both CircuitPython and MicroPython support to the BeagleConnect.
 
|-
 
|-
 
| June 24 || Milestone #2
 
| June 24 || Milestone #2
 +
* Start writing peripheral driver code.
 +
* Complete writing UART driver code.
 +
* Implement and document the working of the MikroElektronika click boards using the UART Peripheral.
 +
1)[https://www.mikroe.com/gps-click GPS CLICK]:Calculate respective position.<br>
 +
2)[https://www.mikroe.com/ultrasonic-2-click ULTRASONIC 2 CLICK]:Detect both near-field and
 +
far-field objects.<br>
 
|-
 
|-
 
| June 30 || Milestone #3
 
| June 30 || Milestone #3
 +
*Complete writing I2C driver code.
 +
*Implement and document the working of the MikroElektronika click boards using the I2C interface.
 +
1)[https://www.mikroe.com/air-quality-4-click AIR QUALITY 4 CLICK]:Collect detailed information
 +
of the air quality parameters.<br>
 +
2)[https://www.mikroe.com/temphum-13-click TEMP&HUM 13 CLICK]:Measure relative humidity
 +
(RH) and temperature.<br>
 
|-
 
|-
| July 12 18:00 UTC || Milestone #4, Mentors and students can begin submitting Phase 1 evaluations
+
| July 12 18:00 UTC ||
 +
* Milestone #4, Mentors and students can begin submitting Phase 1 evaluations
 +
* Complete writing SPI driver code.
 +
* Implement and document the working of the MikroElektronika click boards using the SPI interface.
 +
1)[https://www.mikroe.com/amr-angle-click AMR ANGLE CLICK]:Measure angular and linear
 +
position.<br>
 +
2)[https://www.mikroe.com/smoke-2-click SMOKE 2 CLICK ]:Smoke Detection.<br>
 +
 
 
|-
 
|-
 
| July 16 18:00 UTC || Phase 1 Evaluation deadline
 
| July 16 18:00 UTC || Phase 1 Evaluation deadline
 +
* Complete writing PWM driver code.
 +
* Implement and document the working of the MikroElektronika click boards using the PWM interface.
 +
1)[https://www.mikroe.com/buzz-2-click BUZZ 2 CLICK]:Produce different sound patterns<br>
 +
2)[https://www.mikroe.com/haptic-2-click HAPTIC 2 CLICK]:Produce a haptic feedback.<br>
 
|-
 
|-
 
| July 23 || Milestone #5
 
| July 23 || Milestone #5
 +
* Complete writing ADC driver code.
 +
* Implement and document the working of the ADC board using the ADC interface.
 +
1)[https://www.mikroe.com/ecg-click-bundle ECG CLICK BUNDLE]:Measure electrical activity of
 +
a beating heart.<br>
 +
2)[https://www.mikroe.com/three-axis-accelerometer-board THREE AXIS ACCELEROMETER]:Measure static
 +
and dynamic acceleration.<br>
 
|-
 
|-
 
| July 30 || Milestone #6
 
| July 30 || Milestone #6
 +
* Complete writing GPIO driver code.
 +
* Implement and document the working of the MikroElektronika click boards using the GPIO interface.
 +
1[https://www.mikroe.com/water-detect-click WATER DETECT CLICK]:Detect the presence of
 +
water.<br>
 +
2)[https://www.mikroe.com/relay-click RELAY CLICK]:Control high power applications.<br>
 
|-
 
|-
 
| Aug 06 || Milestone #7
 
| Aug 06 || Milestone #7
 +
* Add all the interface driver code and documentation to the [https://github.com/jadonk/beagleconnect BeagleConnect] and [https://github.com/micropython/micropython Micropython] repositories.
 +
* Testing various click boards supporting same interface as well as different interfaces together.
 +
* Taking notes and feedback from my mentor regarding the quality of the driver code and examples run for the various peripherals.
 
|-
 
|-
| August 10 || Milestone #8, Completion YouTube video
+
| August 10 || Milestone #8  
 +
*Taking feedback from mentors
 +
*Completing the documentation
 +
*Completion YouTube video
 
|-
 
|-
 
| August 16 - 26 18:00 UTC || Final week: Students submit their final work product and their final mentor evaluation
 
| August 16 - 26 18:00 UTC || Final week: Students submit their final work product and their final mentor evaluation
Line 90: Line 235:
  
 
===Experience and approach===
 
===Experience and approach===
In 5-15 sentences, convince us you will be able to successfully complete your project in the timeline you have described.
+
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.<br>
 +
I also interned at Blue Phoenix 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.<br>
 +
[[File:Worksafe_product.jpeg|frameless|worksafe product]]
 +
 
 +
I have been consistently taking part in all the contests on [https://www.hackster.io/ Hackster.io] and had also won a prize in the Deep Learning Superhero Challenge there for my work on [https://www.hackster.io/366411/human-count-3d3e30 Making a People Counter] using the OPENVINO Toolkit.I have also been a part of the [https://innovate.mygov.in/swadeshi-microprocessor-challenge/ Swadeshi Microprocessor Challenge],where my team has entered the semi-finals for making an [https://drive.google.com/file/d/1cUXsZgCFhaSb163hZCSgGZFxTxJB8953/view?usp=sharing 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 [https://drive.google.com/file/d/1ZFUKZiWzTqZkLpZXuWrf6fAWsixUILbz/view here].<br>
 +
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 [http://cansatcompetition.com/ Cansat Competetion],where I am responsible for the entire sensor subsystem integration, writing flight software code and data telemetry using the zigbee protocol.<br>
 +
I have thoroughly gone through [https://github.com/zephyrproject-rtos/zephyr Zephyr RTOS],[https://github.com/micropython/micropython Micropython] and [https://github.com/adafruit/circuitpython CircuitPython] repositories with their official documentation which provided me invaluable clarity towards the project.<br>
 +
Hence,I am confident that I will be able to complete the project in the stipulated time.<br>
  
 
===Contingency===
 
===Contingency===
What will you do if you get stuck on your project and your mentor isn’t around?
+
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.<br>
 +
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.<br>
 +
In such a case few references I would like to refer are:<br>
 +
1)[https://docs.micropython.org/en/latest/ Official MicroPython documentation].<br>
 +
2)[https://circuitpython.readthedocs.io/en/6.2.x/README.html Official CircuitPython documentation].<br>
 +
3)[https://forums.adafruit.com/viewforum.php?f=60 Adafruit CircuitPython and MicroPython forums].<br>
 +
4)For adding driver support the [https://www.ti.com/lit/ug/swcu185d/swcu185d.pdf?ts=1618036665070 SimpleLink CC1352R wireless MCUreference manual] and [https://www.ti.com/lit/ds/symlink/cc1352r.pdf?ts=1618238649979&ref_url=https%253A%252F%252Fwww.google.com%252F datasheet].
 +
 
  
 
===Benefit===
 
===Benefit===
If successfully completed, what will its impact be on the BeagleBoard.org community? Include quotes from BeagleBoard.org community members who can be found on http://beagleboard.org/discuss and http://bbb.io/gsocchat.
+
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.<br>
 +
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.<br>
 +
Motivation for Micropython support on BeagleConnect Freedom is really to mimic the ease-of-use
 +
seen on other plaforms.<br>
 +
Adding Micropython support is something I think can be reasonably mainlined.
 +
-Jason Kridner
 
==Misc==
 
==Misc==
Please complete the requirements listed on the [[BeagleBoard/GSoC/Ideas#General_requirements|ideas page]]. Provide link to pull request.
+
I have completed the requirements stated in the ideas page,the cross compilation task can be found [https://github.com/Yadnik1/gsoc-application/tree/myapp/ExampleEntryJasonKridner here] and the created the pull request can be found [https://github.com/jadonk/gsoc-application/pull/150 here]
  
 
===Suggestions===
 
===Suggestions===
 
Is there anything else we should have asked you?
 
Is there anything else we should have asked you?

Latest revision as of 14:26, 19 April 2021


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:

  • 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


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.

  • 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:
 west build -b ~/micropython/ports/zephyr
  • Followed by this is I will flash it to the board and start a gdb debug session using:
 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:

  • 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.


Execution:

The core code of MicroPython is shared amongst ports including CircuitPython. There is also Documentation released by Adafruit for creating ones own port.

  • 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.

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

  • 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.

The gc and MicroPython modules can be used to control collection and profile memory.
A sample code for the UART protocol can be seen as follows:

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.

I would like to go a further in depth with an example driver code initialisation in MicroPython.
Example driver initialisation

Here we can infer that:
• From the top part of the code, we come to know that it is initialising an I2C class. Then we see that it is reading a register and comparing that with a number.
• From the datasheet we can find out the register name and come to know what the register does, in this case it is a “who am I” register which basically checks if we are talking to the right device.
• The latter part of the code deals with writing into a register and reading it back expecting it to change in a loop. From the datasheet we come to know that writing this specific bit will reset the device and that bit will be set while it is resetting.
• The last part deals with normal write operations which write a register to perform a particular configuration, and we can look at the datasheet to figure out what has happened.

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 optimised driver code.

Software required and Programming Languages
MicroPython will be used majorly for writing drivers along with all the necessary SDKs required for porting processes. The C programming language will be used for kernel-level programming and the GCC compiler along with other build tools will be used for compiling the C source code (*.c)

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:

Analog(for ADC interface):

3)General Hardware required:

  • 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.)

Mar 29 Applications open, Students register with GSoC, work on proposal with mentors
Apr 13 Proposal complete, Submitted to https://summerofcode.withgoogle.com
May 17 Proposal accepted or rejected
  • Read and Research more on writing peripheral drivers and thoroughly go through the SimpleLink CC1352R wireless MCU reference manual.
  • Order all the necessary hardware components
  • Look up various approaches for effective communication for the TI CC1352R MCU via the USB of MSP430.
Jun 07 Pre-work complete, Coding officially begins!
  • All the boards and hardware will be available to me and I will start with flashing the Zephyr RTOS on the BeagleConnect Freedom device.
  • Set up effective effective communication for the TI CC1352R MCU via the USB of MSP430.
  • Complete MicroPython port.
  • Test various pins and features using MicroPython and document it on my blog.
  • Generate pull request to the Zephyr RTOS and MicroPython upstream repositories.
Jun 17 Milestone #1
  • Introductory YouTube video
  • Complete CircuitPython port.
  • Test various pins and features using CircuitPython and document it on my blog.
  • Generate pull request to the Zephyr RTOS and CircuitPython upstream repositories.
  • Taking notes and feedback from my mentor regarding the progress of the porting, and address any issues if any.
  • By this stage I must have completed adding both CircuitPython and MicroPython support to the BeagleConnect.
June 24 Milestone #2
  • Start writing peripheral driver code.
  • Complete writing UART driver code.
  • Implement and document the working of the MikroElektronika click boards using the UART Peripheral.

1)GPS CLICK:Calculate respective position.
2)ULTRASONIC 2 CLICK:Detect both near-field and far-field objects.

June 30 Milestone #3
  • Complete writing I2C driver code.
  • Implement and document the working of the MikroElektronika click boards using the I2C interface.

1)AIR QUALITY 4 CLICK:Collect detailed information of the air quality parameters.
2)TEMP&HUM 13 CLICK:Measure relative humidity (RH) and temperature.

July 12 18:00 UTC
  • Milestone #4, Mentors and students can begin submitting Phase 1 evaluations
  • Complete writing SPI driver code.
  • Implement and document the working of the MikroElektronika click boards using the SPI interface.

1)AMR ANGLE CLICK:Measure angular and linear position.
2)SMOKE 2 CLICK :Smoke Detection.

July 16 18:00 UTC Phase 1 Evaluation deadline
  • Complete writing PWM driver code.
  • Implement and document the working of the MikroElektronika click boards using the PWM interface.

1)BUZZ 2 CLICK:Produce different sound patterns
2)HAPTIC 2 CLICK:Produce a haptic feedback.

July 23 Milestone #5
  • Complete writing ADC driver code.
  • Implement and document the working of the ADC board using the ADC interface.

1)ECG CLICK BUNDLE:Measure electrical activity of a beating heart.
2)THREE AXIS ACCELEROMETER:Measure static and dynamic acceleration.

July 30 Milestone #6
  • Complete writing GPIO driver code.
  • Implement and document the working of the MikroElektronika click boards using the GPIO interface.

1WATER DETECT CLICK:Detect the presence of water.
2)RELAY CLICK:Control high power applications.

Aug 06 Milestone #7
  • Add all the interface driver code and documentation to the BeagleConnect and Micropython repositories.
  • Testing various click boards supporting same interface as well as different interfaces together.
  • Taking notes and feedback from my mentor regarding the quality of the driver code and examples run for the various peripherals.
August 10 Milestone #8
  • Taking feedback from mentors
  • Completing the documentation
  • Completion YouTube video
August 16 - 26 18:00 UTC Final week: Students submit their final work product and their final mentor evaluation
August 23 - 30 18:00 UTC Mentors submit final student evaluations

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 Phoenix 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.
worksafe product

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.
Motivation for Micropython support on BeagleConnect Freedom is really to mimic the ease-of-use seen on other plaforms.
Adding Micropython support is something I think can be reasonably mainlined.

-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?