NOTICE: The Processors Wiki will End-of-Life on January 15, 2021. It is recommended to download any files or other content you may need that are hosted on processors.wiki.ti.com. The site is now set to read only.

User:Dbartlett/MicroPython CC3200

From Texas Instruments Wiki
Jump to: navigation, search

Introduction[edit]

MicroPython is an implementation of Python capable of running under a microcontroller environment. It provides a number of API's that allow a developer to easily interact with the MCU peripherals using Python.

The environment provides the user with a live shell where they can write Python code live on the system, or, by copying a Python script to the device via FTP they can create complex programs that run when the device boots.

MicroPython runs natively on the PyBoard, a development platform built around a STM32F405RG microcontroller and the WiPy, built around a CC3200 which adds WiFi connectivity to the platform.

A port exists for the CC3200 Launch XL which this guide describes how to compile and flash.

Prerequisites[edit]

Hardware[edit]

Hardware Required

  • CC3200-LAUNCHXL (Rev 4.1 or higher, devices older than this revision will not work.)

Software[edit]


Installation[edit]

Compiling MicroPython[edit]

  1. Download and install the GCC ARM Embedded Compiler Toolchain version for your operating system. Windows Users: Make sure to tick the "Add path to environment variable" at the end of the installer to easily run the tools from the command prompt.
  2. Download and install Cygwin as well the "make" and "python" packages.
    Cygwin install make.png
  3. Download the latest MicroPython release from the project Github and extract the archive.
  4. Open Cygwin terminal and navigate to the "cc3200" directory inside the MicroPython code archive you downloaded with the following command. Replace "Drive Letter" and "MicroPython Directory" with the correct pathnames.
    cd /cygdrive/$DRIVE_LETTER$/$MICROPYTHON_DIRECTORY$/cc3200/
  5. We must now compile the Bootloader and Application binaries for MicroPython which can then be flashed to the CC3200. Inside the Cygwin terminal run the following commands. To build the bootloader
     make BTARGET=bootloader BTYPE=release BOARD=LAUNCHXL 
    To build the application binary:
     make BTARGET=application BTYPE=release BOARD=LAUNCHXL 

Once compilation completes successfully we can flash the binaries to the CC3200-LAUNCHXL.

Flashing MicroPython[edit]

  1. Firstly, ensure the SOP2, J6 and J7 jumpers are set correctly.
CC3200 with SOP2 jumper set to 100
  1. Download and install CCS UniFlash to your PC.
  2. Connect the LAUNCHXL to your PC using the USB cable.
  3. Check the COM port assigned to your device from the device manager. Control Panel|Device Manager|Ports (COM & LPT)
  4. Launch CCS UniFlash
  5. Click "New Target Configuration" and enter "CC3x Serial(UART) Interface".
    Target configuration screen.jpg
  6. In the "COM Port" enter the number of the COM Port assigned to your device.
  7. Format the CC3200 at 1MB capacity.
  8. On the left of the screen, under "System Files", open /cert/ca.pem , /cert/client.prem and /cert/private.key and tick the "Erase" box for each.
  9. Under "System Files" open /sys/mcuimg.bin and change the url to the following path: $MICROPYTHON_DIRECTORY$/cc3200/bootmgr/build/LAUNCHXL/release/bootloader.bin
  10. Check the "Update" and "Verify" boxes on the /sys/mcuimg.bin screen
  11. Click "Operation" and "Add File" in the title bar.
  12. Open this file and change the name to "/sys/factimg.bin" and set the url to: $MICROPYTHON_DIRECTORY$/cc3200/build/LAUNCHXL/release/mcuimg.bin.
  13. Check the "Update" and "Verify" boxes.
  14. Click "Operation" and then "Program" in the title bar.
  15. If not performed already, flash the latest service pack (servicepack_1.0.0.10.0.bin) using "Service Pack Programming"
  16. Close UniFlash, disconnect the device and reset the SOP2 Jumper.

Using MicroPython on the CC3200[edit]

Accessing the REPL(Live Shell)[edit]

Telnet[edit]

Initially only telnet is available for interacting with the REPL environment. By default MicroPython boots in AP Mode. On a PC with WiFi look for the access point named "wipy-wlan" or similar. The password for this network is : www.wipy.io

Once connected, use a telnet client to connect to 192.168.1.1, at the authentication prompt type, username=micro password=python. You should now have an open session with the CC3200 and can write Python code live on the system.

Serial[edit]

It is also possible to access the REPL via serial, this means you can program live on the system while maintaining internet access on your computer. To enable this functionality first connect via telnet as described above, then run the following code line by line.

from machine import UART
import os
uart = UART(0, baudrate=115200)
os.dupterm(uart)

The REPL environment is now duplicated over the USB serial interface and can be used as normal. Adding this code to your boot.py file will cause it to be run on power up meaning you only have to perform these steps once.

NOTE: If you want to use this serial port for your application you must disable serial REPL access.

Uploading Scripts[edit]

Using the REPL environment is good for experimenting with the system but not as useful for when you want to run your finished project. For this you can upload Python scripts to the CC3200 and they will be run on the device.

Firstly, connect to the WiFi network of the device and using your FTP client of choice, connect to 192.168.1.1 using username=micro password=python. The directory structure of the device is as follows:

/
|--Flash/
     |--cert/
     |--lib/
     |--sys/
     |-boot.py
     |-main.py

The file "boot.py" contains code that is run once every time the system starts, it is not recommended to run anything particularly complicated here. "main.py" contains the code for your application, it is executed after "boot.py".

Replacing these files with ones of your own is all you need to program your CC3200 while it runs MicroPython.