LoBo Forums

Full Version: Kendryte K210 port announcement
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
MicroPython for Kendryte K210

Quote:This MicroPython port is now in beta stage. Some bugs and issues can be expected.

All standard MicroPython functionality and modules are implemented, as well as advanced thread support, file system support and display module.

Modules providing support for K210 peripherals (Pin, UART, I2C, SPI, Camera, PWM, etc) are still not available, but will be implemented soon.


This implementation is based on MaixPy, Sipeed's implementation of MicroPython for K210.
Based on kendryte-freertos-sdk (modified to include some needed features not yet implemented) it brings many new features:
  • MicroPython core based on latest build from main MicroPython repository, unchanged except for the thread support.
  •  Refactored _thread module with many new features, based on my MicroPython for ESP32 _thread module.
  • Full support for SPIFFS file system on internal Flash (with directories support) and Fat32 file system on external SD Card
  • Full file system timestamp support for both SPIFFS and Fat32.
  • ymodem module for file transfer to/from K210 board using ymodem protocol.
  • uhashlib and ucryptolib using K210 hardware AES.
  • Display module ported from my MicroPython for ESP32 display module.
  • pye, full screen file editor (as python frozen module) is provided.
  • Eclipse project files are included. To include it into Eclipse goto  File->Import->Existing Projects into Workspace->Select root directory->[select MicroPython_K210_LoBo directory]->Finish. Rebuild index.
  • Porting most of the modules from my MicroPython for ESP32 port is planned.
  • More to come soon ...

Full Wiki pages with detailed instructions for build and usage will be available soon.



The K210 MicroPython implementation is developed and tested on great K210 boards from Sipeed (Maix-bit and Maix-Dock) first anounced on this Indiegogo campaign.
Some of the boards are available at Seeed and Banggood and should be available from other sources soon.



How to Build

Clone the MicroPython repository:

Code:
git clone https://github.com/loboris/MicroPython_K210_LoBo.git

You can also download the repository as a zip file (using Clone or download button on the first repository page) and unpack it to some directory.
You will not be able to use git pull to update the repository, but otherwise the building process is the same.


Build the MicroPython firmware:

Easy to use script BUILD.sh is provided to make the build process simple.

Kendryte toolchain, needed for compiling for K210, will be automatically downloaded and unpacked on first run of BUILD.sh script.
kendryte-freertos-sdk is included in the repository,

Change the working directory to MicroPython_K210_LoBo/k210-freertos.

To build the MicroPython firmware, run:
Code:
./BUILD.sh

To flush the built firmware to your K210 board, run:
Code:
./kflash.py -p /dev/ttyUSB0 -b 2000000 -t MaixPy.bin

Change /dev/ttyUSB0 to the port used to connect to your board if needed.



I (188995) w25qxx_init: manuf_id:0xc8, device_id:0x17


__  __              _____  __   __  _____   __     __
|  \/  |     /\     |_   _| \ \ / / |  __ \  \ \   / /
| \  / |    /  \      | |    \ V /  | |__) |  \ \_/ /
| |\/| |   / /\ \     | |     > <   |  ___/    \   /  
| |  | |  / ____ \   _| |_   / . \  | |         | |  
|_|  |_| /_/    \_\ |_____| /_/ \_\ |_|         |_|
------------------------------------------------------

I (228135) [MAIXPY]: Stack:  min: 8065
I (232617) [MAIXPY]:  Pll0: freq: 780000000
I (237391) [MAIXPY]:  Pll1: freq: 159714285
I (242165) [MAIXPY]:   Cpu: freq: 390000000
I (246938) [MAIXPY]: Flash:   ID: [0xc8:0x17]
I (535090) [VFS_SPIFFS]: Flash VFS registered.

MaixPy-FreeRTOS by LoBo v1.0.1
------------------------------
MicroPython 76eeec7-dirty on 2019-01-24; Sipeed_board with Kendryte-K210
Type "help()" for more information.
>>>
>>>
>>> help('modules')
__main__          gc                ucollections      urandom
_thread           machine           ucryptolib        ure
array             math              uctypes           ustruct
binascii          micropython       uerrno            utime
board             os                uhashlib          utimeq
builtins          pye               uheapq            uzlib
cmath             re                uio               websocket
collections       sys               ujson             ymodem
display           ubinascii         uos
Plus any modules on the filesystem
>>>
>>> import machine, uos, utime, _thread
>>> def test():
...     cnt = 0
...     machine.initleds()
...     while 1:
...         machine.setled(machine.LEDR, False)
...         machine.setled(machine.LEDB, False)
...         if (cnt % 2):
...             machine.setled(machine.LEDR, True)
...         else:
...             machine.setled(machine.LEDB, True)
...         cnt += 1
...         utime.sleep_ms(500)
...
>>>
>>> th = _thread.start_new_thread("TestLED", test, ())
>>> _thread.list()

Total system run time: 880.221 s, Tasks run time: 880.221 s, numTasks=5
MicroPython threads:
-----------------------------------------------------------------------------------------------------
ID(handle) Proc             Name     State  Stack MaxUsed PyStack    Type Priority Run time (s)   (%)
-----------------------------------------------------------------------------------------------------
2148287848    0          TestLED   running  16016    1232    2048  PYTHON        8        0.354  0.04
2148402616    0       MainThread   running  31600    1256    4096    MAIN        8        4.000  0.45

FreeRTOS tasks running:
-------------------------------------------------------------------------------
ID(handle) Proc             Name     State MinStack Priority Run time (s)   (%)
-------------------------------------------------------------------------------
2148402616    0          mp_task   Running    30344       15        4.000  0.45
2148287848    0          TestLED     Ready    14784        8        0.354  0.04
2148355008    0             IDLE     Ready     7320        0      875.613 99.48
2148357096    1             IDLE     Ready     7416        0      880.183100.00
2148367744    1    hal_tick_task   Blocked     7432        0        0.008  0.00

>>>
>>>
>>>
>>> sd = uos.VfsSDCard()
>>> uos.mount(sd, '/sd')
>>> uos.listdir('/sd')
['test1.avi', 'test.txt', 'test1.txt', 'Picture', 'Video', 'Audio', 'VideoCall', 'Money.wav', 'Wall1.raw', 'TEST_F~1.TXT', 'test_syscalls.tx
t', 'test_filesystem.txt']
>>>
>>> uos.statvfs('/sd')
(4096, 4096, 1936436, 1925131, 1925131, 0, 0, 0, 0, 255)
>>>
>>> import display
>>> tft = display.TFT()
>>> tft.init(0)
>>> tft.circle(160,120,80,tft.RED,tft.BLUE)
>>> tft.image(0,0,'/flash/test1.jpg')
>>>
>>> import micropython, gc
>>> gc.collect()
>>> micropython.mem_info()
mem: total=37414, current=5122, peak=6688
stack: 1004
GC: total: 3121280, used: 1504, free: 3119776
No. of 1-blocks: 25, 2-blocks: 4, max blk sz: 6, max free sz: 97351
>>>

```

Schematics:
MAIX-Bit
MAIX-Dock
MAIX-Go

This is so so exciting for me for my robotic projects, the mind boggles with possibilities.
loboris very excited about this have a module on order from Banggood, but it would be incredibly helpful if you could push out the latest ESP32 enhancements and finish up the EVE project.

Thanks in advance
I want to use this platform to identify and localize the 5x5x5 cube in an image. Where is the best place for me to start to learn about training the CNN??
(01-25-2019, 11:53 AM)lobo Wrote: [ -> ]MicroPython for Kendryte K210

Quote:This MicroPython port is now in beta stage. Some bugs and issues can be expected.

All standard MicroPython functionality and modules are implemented, as well as advanced thread support, file system support and display module.

Modules providing support for K210 peripherals (Pin, UART, I2C, SPI, Camera, PWM, etc) are still not available, but will be implemented soon.

[snip]

Great work!  I know I'm not the only one anxiously awaiting the hardware functions, please let us know if there is any way we might be able to help out in improving the port.

Best wishes-
Larry
Hi,

I was wondering what the differences are between this and the MaixPy version?
(02-21-2019, 08:15 PM)xgarb Wrote: [ -> ]Hi,

I was wondering what the differences are between this and the MaixPy version?

I am not sure on the differences are but the MaixPy has been developing a bit see latest version https://github.com/sipeed/MaixPy/releases?r=slt-eml-bck-a2e0&utm_source=sailthru&utm_medium=email&utm_campaign=bck-02202019update&utm_term=
The original MaixPy is quite good, but it does not suit completely my needs.
There are many subtle issues which only shows after longer use and with more complex Python programs.

This port is fully based on FreeRTOS and should be at the end more feature-rich.
I'm porting all the modules from my MicroPython for ESP32 which is quite difficult with the original MaixPy.

One of the features I'm testing now is running two separate MincroPython instances on two processors which could 
pontentially be quite interesting.

I'll try give more info about why I'm doing it and the expected features on the Wiki pages.
(02-22-2019, 05:57 PM)lobo Wrote: [ -> ]The original MaixPy is quite good, but it does not suit completely my needs.
There are many subtle issues which only shows after longer use and with more complex Python programs.

This port is fully based on FreeRTOS and should be at the end more feature-rich.
I'm porting all the modules from my MicroPython for ESP32 which is quite difficult with the original MaixPy.

One of the features I'm testing now is running two separate MincroPython instances on two processors which could 
pontentially be quite interesting.

I'll try give more info about why I'm doing it and the expected features on the Wiki pages.

I know the developers of this hardware are very keen to have people help develop their platform. The advantages of RTOS is obvious and Lobo experience and knowledge with micro-python is also obvious. Is it not better to combine efforts rather than end up with 2 totally separate ports amking for double the development and maintenance work.
As a heads up have compiled, loaded, and have running Micropython with network support on a Maix Dock MI. The major issue was in flash.sh which looks in a non existent bin directory for files.
Pages: 1 2