dfb61f01db
Support for Xtensa emitter and assembler, and upgraded F4 and F7 STM HAL This release adds support for the Xtensa architecture as a target for the native emitter, as well as Xtensa inline assembler. The int.from_bytes and int.to_bytes methods now require a second argument (the byte order) per CPython (only "little" is supported at this time). The "readall" method has been removed from all stream classes that used it; "read" with no arguments should be used instead. There is now support for importing packages from compiled .mpy files. Test coverage is increased to 96%. The generic I2C driver has improvements: configurable clock stretching timeout, "stop" argument added to readfrom/writeto methods, "nack" argument added to readinto, and write[to] now returns num of ACKs received. The framebuf module now handles 16-bit depth (generic colour format) and has hline, vline, rect, line methods. A new utimeq module is added for efficient queue ordering defined by modulo time (to be compatible with time.ticks_xxx functions). The pyboard.py script has been modified so that the target board is not reset between scripts or commands that are given on a single command line. For the stmhal port the STM Cube HAL has been upgraded: Cube F4 HAL to v1.13.1 (CMSIS 2.5.1, HAL v1.5.2) and Cube F7 HAL to v1.1.2. There is a more robust pyb.I2C implementation (DMA is now disabled by default, can be enabled via an option), and there is an implementation of machine.I2C with robust error handling and hardware acceleration on F4 MCUs. It is now recommended to use machine.I2C instead of pyb.I2C. The UART class is now more robust with better handling of errors/timeouts. There is also more accurate VBAT and VREFINT measurements for the ADC. New boards that are supported include: NUCLEO_F767ZI, STM32F769DISC and NUCLEO_L476RG. For the esp8266 port select/poll is now supported for sockets using the uselect module. There is support for native and viper emitters, as well as an inline assembler (with limited iRAM for storage of native functions, or the option to store code to flash). There is improved software I2C with a slight API change: scl/sda pins can be specified as positional only when "-1" is passed as the first argument to indicate the use of software I2C. It is recommended to use keyword arguments for scl/sda. There is very early support for over-the-air (OTA) updates using the yaota8266 project. A detailed list of changes follows. py core: - emitnative: fix native import emitter when in viper mode - remove readall() method, which is equivalent to read() w/o args - objexcept: allow clearing traceback with 'exc.__traceback__ = None' - runtime: mp_resume: handle exceptions in Python __next__() - mkrules.mk: rework find command so it works on OSX - *.mk: replace uses of 'sed' with $(SED) - parse: move function to check for const parse node to parse.[ch] - parse: make mp_parse_node_new_leaf an inline function - parse: add code to fold logical constants in or/and/not operations - factor persistent code load/save funcs into persistentcode.[ch] - factor out persistent-code reader into separate files - lexer: rewrite mp_lexer_new_from_str_len in terms of mp_reader_mem - lexer: provide generic mp_lexer_new_from_file based on mp_reader - lexer: rewrite mp_lexer_new_from_fd in terms of mp_reader - lexer: make lexer use an mp_reader as its source - objtype: implement __call__ handling for an instance w/o heap alloc - factor out common code from assemblers into asmbase.[ch] - stream: move ad-hoc ioctl constants to stream.h and rename them - compile: simplify configuration of native emitter - emit.h: remove long-obsolete declarations for cpython emitter - move arch-specific assembler macros from emitnative to asmXXX.h - asmbase: add MP_PLAT_COMMIT_EXEC option for handling exec code - asmxtensa: add low-level Xtensa assembler - integrate Xtensa assembler into native emitter - allow inline-assembler emitter to be generic - add inline Xtensa assembler - emitinline: embed entire asm struct instead of a pointer to it - emitinline: move inline-asm align and data methods to compiler - emitinline: move common code for end of final pass to compiler - asm: remove need for dummy_data when doing initial assembler passes - objint: from_bytes, to_bytes: require byteorder arg, require "little" - binary: do zero extension when storing a value larger than word size - builtinimport: support importing packages from compiled .mpy files - mpz: remove unreachable code in mpn_or_neg functions - runtime: zero out fs_user_mount array in mp_init - mpconfig.h: enable MICROPY_PY_SYS_EXIT by default - add MICROPY_KBD_EXCEPTION config option to provide mp_kbd_exception - compile: add an extra pass for Xtensa inline assembler - modbuiltins: remove unreachable code - objint: rename mp_obj_int_as_float to mp_obj_int_as_float_impl - emitglue: refactor to remove assert(0), to improve coverage - lexer: remove unreachable code in string tokeniser - lexer: remove unnecessary check for EOF in lexer's next_char func - lexer: permanently disable the mp_lexer_show_token function - parsenum: simplify and generalise decoding of digit values - mpz: fix assertion in mpz_set_from_str which checks value of base - mpprint: add assertion for, and comment about, valid base values - objint: simplify mp_int_format_size and remove unreachable code - unicode: comment-out unused function unichar_isprint - consistently update signatures of .make_new and .call methods - mkrules.mk: add MPY_CROSS_FLAGS option to pass flags to mpy-cross - builtinimport: fix bug when importing names from frozen packages extmod: - machine_i2c: make the clock stretching timeout configurable - machine_i2c: raise an error when clock stretching times out - machine_i2c: release SDA on bus error - machine_i2c: add a C-level I2C-protocol, refactoring soft I2C - machine_i2c: add argument to C funcs to control stop generation - machine_i2c: rewrite i2c.scan in terms of C-level protocol - machine_i2c: rewrite mem xfer funcs in terms of C-level protocol - machine_i2c: remove unneeded i2c_write_mem/i2c_read_mem funcs - machine_i2c: make C-level functions return -errno on I2C error - machine_i2c: add 'nack' argument to i2c.readinto - machine_i2c: make i2c.write[to] methods return num of ACKs recvd - machine_i2c: add 'stop' argument to i2c readfrom/writeto meths - machine_i2c: remove trivial function wrappers - machine_i2c: expose soft I2C obj and readfrom/writeto funcs - machine_i2c: add hook to constructor to call port-specific code - modurandom: allow to build with float disabled - modframebuf: make FrameBuffer handle 16bit depth - modframebuf: add back legacy FrameBuffer1 "class" - modframebuf: optimise fill and fill_rect methods - vfs_fat: implement POSIX behaviour of rename, allow to overwrite - moduselect: use stream helper function instead of ad-hoc code - moduselect: use configurable EVENT_POLL_HOOK instead of WFI - modlwip: add ioctl method to socket, with poll implementation - vfs_fat_file: allow file obj to respond to ioctl flush request - modbtree: add method to sync the database - modbtree: rename "sync" method to "flush" for consistency - modframebuf: add hline, vline, rect and line methods - machine_spi: provide reusable software SPI class - modframebuf: make framebuf implement the buffer protocol - modframebuf: store underlying buffer object to prevent GC free - modutimeq: copy of current moduheapq with timeq support for refactoring - modutimeq: refactor into optimized class - modutimeq: make time_less_than be actually "less than", not less/eq lib: - utils/interrupt_char: use core-provided mp_kbd_exception if enabled drivers: - display/ssd1306.py: update to use FrameBuffer not FrameBuffer1 - onewire: enable pull up on data pin - onewire/ds18x20: fix negative temperature calc for DS18B20 tools: - tinytest-codegen: blacklist recently added uheapq_timeq test (qemu-arm) - pyboard.py: refactor so target is not reset between scripts/cmd - mpy-tool.py: add support for OPT_CACHE_MAP_LOOKUP_IN_BYTECODE tests: - micropython: add test for import from within viper function - use read() instead of readall() - basics: add test for logical constant folding - micropython: add test for creating traceback without allocation - micropython: move alloc-less traceback test to separate test file - extmod: improve ujson coverage - basics: improve user class coverage - basics: add test for dict.fromkeys where arg is a generator - basics: add tests for if-expressions - basics: change dict_fromkeys test so it doesn't use generators - basics: enable tests for list slice getting with 3rd arg - extmod/vfs_fat_fileio: add test for constructor of FileIO type - extmod/btree1: exercise btree.flush() - extmod/framebuf1: add basics tests for hline, vline, rect, line - update for required byteorder arg for int.from_bytes()/to_bytes() - extmod: improve moductypes test coverage - extmod: improve modframebuf test coverage - micropython: get heapalloc_traceback test running on baremetal - struct*: make skippable - basics: improve mpz test coverage - float/builtin_float_round: test round() with second arg - basics/builtin_dir: add test for dir() of a type - basics: add test for builtin locals() - basics/set_pop: improve coverage of set functions - run-tests: for REPL tests make sure the REPL is exited at the end - basics: improve test coverage for generators - import: add a test which uses ... in from-import statement - add tests to improve coverage of runtime.c - add tests to improve coverage of objarray.c - extmod: add test for utimeq module - basics/lexer: add a test for newline-escaping within a string - add a coverage test for printing the parse-tree - utimeq_stable: test for partial stability of utimeq queuing - heapalloc_inst_call: test for no alloc for simple object calls - basics: add tests for parsing of ints with base 36 - basics: add tests to improve coverage of binary.c - micropython: add test for micropython.stack_use() function - extmod: improve ubinascii.c test coverage - thread: improve modthread.c test coverage - cmdline: improve repl.c autocomplete test coverage - unix: improve runtime_utils.c test coverage - pyb/uart: update test to match recent change to UART timeout_char - run-tests: allow to skip set tests - improve warning.c test coverage - float: improve formatfloat.c test coverage using Python - unix: improve formatfloat.c test coverage using C - unix/extra_coverage: add basic tests to import frozen str and mpy - types1: split out set type test to set_types - array: allow to skip test if "array" is unavailable - unix/extra_coverage: add tests for importing frozen packages unix port: - rename define for unix moduselect to MICROPY_PY_USELECT_POSIX - Makefile: update freedos target for change of USELECT config name - enable utimeq module - main: allow to print the parse tree in coverage build - Makefile: make "coverage_test" target mirror Travis test actions - moduselect: if file object passed to .register(), return it in .poll() - Makefile: split long line for coverage target, easier to modify - enable and add basic frozen str and frozen mpy in coverage build - Makefile: allow cache-map-lookup optimisation with frozen bytecode windows port: - enable READER_POSIX to get access to lexer_new_from_file stmhal port: - dma: de-init the DMA peripheral properly before initialising - i2c: add option to I2C to enable/disable use of DMA transfers - i2c: reset the I2C peripheral if there was an error on the bus - rename mp_hal_pin_set_af to _config_alt, to simplify alt config - upgrade to STM32CubeF4 v1.13.0 - CMSIS/Device 2.5.1 - upgrade to STM32CubeF4 v1.13.0 - HAL v1.5.1 - apply STM32CubeF4 v1.13.1 patch - upgrade HAL driver to v1.5.2 - hal/i2c: reapply HAL commit |
||
---|---|---|
.. | ||
FreeRTOS | ||
boards | ||
bootmgr | ||
fatfs/src | ||
ftp | ||
hal | ||
misc | ||
mods | ||
simplelink | ||
telnet | ||
tools | ||
util | ||
Makefile | ||
README.md | ||
application.lds | ||
application.mk | ||
appsign.sh | ||
main.c | ||
mpconfigport.h | ||
mptask.c | ||
mptask.h | ||
mpthreadport.c | ||
mpthreadport.h | ||
qstrdefsport.h | ||
serverstask.c | ||
serverstask.h | ||
version.h |
README.md
MicroPython port to CC3200 WiFi SoC
This is a MicroPython port to Texas Instruments CC3200 WiFi SoC (ARM Cortex-M4 architecture). This port supports 2 boards: WiPy and TI CC3200-LAUNCHXL.
Build Instructions for the CC3200
Currently the CC3200 port of MicroPython builds under Linux and OSX, but not under Windows.
The toolchain required for the build can be found at https://launchpad.net/gcc-arm-embedded.
In order to flash the image to the CC3200 you will need the cc3200tool. An alternative is to use CCS_Uniflash tool from TI, which works only under Windows, and all support is provided by TI itself.
Building the bootloader:
make BTARGET=bootloader BTYPE=release BOARD=LAUNCHXL
Building the "release" image:
make BTARGET=application BTYPE=release BOARD=LAUNCHXL
To build an image suitable for debugging:
In order to debug the port specific code, optimizations need to be disabled on the port file (check the Makefile for specific details). You can use CCS from TI. Use the CC3200.ccxml file supplied with this distribution for the debuuger configuration.
make BTARGET=application BTYPE=debug BOARD=LAUNCHXL
Flashing the CC3200-LAUNCHXL
Note that WiPy comes factory programmed with a default version of MicroPython, it cannot be programmed via serial, and can be upgraded only with OTA (see below).
- Make sure that you have built both the bootloader and the application in release mode.
- Make sure the SOP2 jumper is in position.
- Make sure you Linux system recognized the board and created
ttyUSB*
devices (see below for configuration offtdi_sio
driver). - Run "make erase" and immediately press Reset button on the device.
- Wait few seconds.
- Run "make deploy" and immediately press Reset button on the device.
- You are recommended to install the latest vendor WiFi firmware
servicepack from http://www.ti.com/tool/cc3200sdk. Download
CC3200SDK-SERVICEPACK package, install it, and locate
ota_*.ucf
andota_*.ucf.signed.bin
files. Copy them to the port's directory and run "make servicepack", with immediate press of Reset button. - Remove the SOP2 jumper and reset the board.
Flashing process using TI Uniflash:
- Open CCS_Uniflash and connect to the board (by default on port 22).
- Format the serial flash (select 1MB size in case of the CC3200-LAUNCHXL, 2MB in case of the WiPy, leave the rest unchecked).
- Mark the following files for erasing:
/cert/ca.pem
,/cert/client.pem
,/cert/private.key
and/tmp/pac.bin
. - Add a new file with the name of /sys/mcuimg.bin, and select the URL to point to cc3200\bootmgr\build<BOARD_NAME>\bootloader.bin.
- Add another file with the name of /sys/factimg.bin, and select the URL to point to cc3200\build<BOARD_NAME>\mcuimg.bin.
- Click "Program" to apply all changes.
- Flash the latest service pack (servicepack_1.0.0.10.0.bin) using the "Service Pack Update" button.
- Close CCS_Uniflash, remove the SOP2 jumper and reset the board.
Playing with MicroPython and the CC3200:
Once the software is running, you have two options to access the MicroPython REPL:
-
Through telnet.
- Connect to the network created by the board (as boots up in AP mode), ssid = "wipy-wlan", key = "www.wipy.io".
- You can also reinitialize the WLAN in station mode and connect to another AP, or in AP mode but with a different ssid and/or key.
- Use your favourite telnet client with the following settings: host = 192.168.1.1, port = 23.
- Log in with user = "micro" and password = "python"
- Connect to the network created by the board (as boots up in AP mode), ssid = "wipy-wlan", key = "www.wipy.io".
-
Through UART (serial).
- This is enabled by default in the standard configuration, for UART0 (speed 115200).
- For CC3200-LAUNCHXL, you will need to configure Linux
ftdi_sio
driver as described in the blog post. After that, connecting a board will create two/dev/ttyUSB*
devices, a serial console is available on the 2nd one (usually/dev/ttyUSB1
). - WiPy doesn't have onboard USB-UART converter, so you will need an external one, connected to GPIO01 (Tx) and GPIO02 (Rx).
- Usage of UART port for REPL is controlled by MICROPY_STDIO_UART setting (and
is done at the high level, using a suitable call to
os.dupterm()
function in boot.py, so you can override it at runtime regardless of MICROPY_STDIO_UART setting).
The board has a small file system of 192K (WiPy) or 64K (Launchpad) located in the serial flash connected to the CC3200. SD cards are also supported, you can connect any SD card and configure the pinout using the SD class API.
Uploading scripts:
To upload your MicroPython scripts to the FTP server, open your FTP client of choice and connect to: ftp://192.168.1.1, user = "micro", password = "python"
Tested FTP clients are: FileZilla, FireFTP, FireFox, IE and Chrome. Other clients should work as well, but you may need to configure them to use a single connection (this should be the default for any compliant FTP client).
Upgrading the firmware Over The Air (OTA)
OTA software updates can be performed through the builtin FTP server. After
building a new mcuimg.bin
in release mode, upload it to:
/flash/sys/mcuimg.bin
. It will take around 6s (The TI SimpleLink file
system is quite slow because every file is mirrored for safety). You won't
see the file being stored inside /flash/sys/
because it's actually saved
bypassing FatFS, but rest assured that the file was successfully transferred,
and it has been signed with a MD5 checksum to verify its integrity.
Now, reset the MCU by pressing the switch on the board, or by typing:
import machine
machine.reset()
There's a script which automates this process from the host side:
- Make sure the board is running and connected to the same network as the computer.
make BTARGET=application BTYPE=release BOARD=LAUNCHXL WIPY_IP=192.168.1.1 WIPY_USER=micro WIPY_PWD=python deploy-ota
If WIPY_IP
, WIPY_USER
or WIPY_PWD
are omitted the default values (the ones shown above) will be used.
Notes and known issues
Regarding old revisions of the CC3200-LAUNCHXL
First silicon (pre-release) revisions of the CC3200 had issues with the ram blocks, and MicroPython cannot run there. Make sure to use a v4.1 (or higer) LAUNCHXL board when trying this port, otherwise it won't work.
Note regarding FileZilla
Do not use the quick connect button, instead, open the site manager and create a new configuration. In the "General" tab make sure that encryption is set to: "Only use plain FTP (insecure)". In the Transfer Settings tab limit the max number of connections to one, otherwise FileZilla will try to open a second command connection when retrieving and saving files, and for simplicity and to reduce code size, only one command and one data connections are possible.