Thursday, November 10, 2016

Build MicroPython on Cygwin to run on CC3200 LaunchPad and toggle Yellow LED (D6)

The following steps show you how to build MicroPython on Cygwin

1. Download MicroPython by "git clone --recursive https://github.com/micropython/micropython"

2. Switch to CC3200 MicroPython folder by "cd /cygdrive/$DRIVE_LETTER$/$MICROPYTHON_DIRECTORY$/cc3200/"

3. Build Bootloader by "make BTARGET=bootloader BTYPE=release BOARD=LAUNCHXL"

4. Build Application by "make BTARGET=application BTYPE=release BOARD=LAUNCHXL". You might suffer build problem because of Python version problem and the following steps show you how to fix them.

4.1------
You will get the following similar error which is caused by Python version on Cygwin:
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
mkdir -p build/LAUNCHXL/release/genhdr
Create build/LAUNCHXL/release/genhdr/pins.h
/c/cygwin64/bin/python: /c/cygwin64/bin/python: cannot execute binary file
make: *** [application.mk:248: build/LAUNCHXL/release/genhdr/pins.h] Error 126


You can run the following Python command:
 python boards/make-pins.py --board boards/LAUNCHXL/pins.csv --af boards/cc3200_af.csv --prefix boards/cc3200_prefix.c --hdr build/LAUNCHXL/release/genhdr/pins.h --qstr build/LAUNCHXL/release/pins_qstr.h > build/LAUNCHXL/release/pins.c

Comment out line 248 "$(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) > $(GEN_PINS_SRC)" in application.mk and keep making by:

 make BTARGET=application BTYPE=release BOARD=LAUNCHXL

4.2------------------
You will again get the following similar error which is caused by Python version on Cygwin:
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
/c/cygwin64/bin/python: /c/cygwin64/bin/python: cannot execute binary file
make: *** [../py/py.mk:259: build/LAUNCHXL/release/genhdr/mpversion.h] Error 126


You can run the following Python command:
python ../py/makeversionhdr.py build/LAUNCHXL/release/genhdr/mpversion.h

Comment out line 259 "$(Q)$(PYTHON) $(PY_SRC)/makeversionhdr.py $" in py.mk and keep making by:

 make BTARGET=application BTYPE=release BOARD=LAUNCHXL

4.3 -------------------
You will again get the following similar error which is caused by Python version on Cygwin:
 Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
GEN build/LAUNCHXL/release/genhdr/qstr.i.last
GEN build/LAUNCHXL/release/genhdr/qstr.split
/c/cygwin64/bin/python: /c/cygwin64/bin/python: cannot execute binary file
make: *** [../py/mkrules.mk:83: build/LAUNCHXL/release/genhdr/qstr.split] Error 126


 You can run the following Python command:python ../py/makeqstrdefs.py split build/LAUNCHXL/release/genhdr/qstr.i.last build/LAUNCHXL/release/genhdr/qstr build/LAUNCHXL/release/genhdr/qstrdefs.collected.h

Comment out line 83 "$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py split $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED)" in mkrules.mk and keep making by:

 make BTARGET=application BTYPE=release BOARD=LAUNCHXL

4.4---------------------
You will again get the following similar error which is caused by Python version on Cygwin:

Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
GEN build/LAUNCHXL/release/genhdr/qstr.split
GEN build/LAUNCHXL/release/genhdr/qstrdefs.collected.h
/c/cygwin64/bin/python: /c/cygwin64/bin/python: cannot execute binary file
make: *** [../py/mkrules.mk:88: build/LAUNCHXL/release/genhdr/qstrdefs.collected.h] Error 126


You can run the following Python command:
python ../py/makeqstrdefs.py cat build/LAUNCHXL/release/genhdr/qstr.i.last build/LAUNCHXL/release/genhdr/qstr build/LAUNCHXL/release/genhdr/qstrdefs.collected.h

Comment out line 88 "$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py cat $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED)" in mkrules.mk and keep making by:

make BTARGET=application BTYPE=release BOARD=LAUNCHXL

4.5-------------------
You will again get the following similar error which is caused by Python version on Cygwin:

Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
GEN build/LAUNCHXL/release/genhdr/qstrdefs.generated.h
/c/cygwin64/bin/python: /c/cygwin64/bin/python: cannot execute binary file
make: *** [../py/py.mk:273: build/LAUNCHXL/release/genhdr/qstrdefs.generated.h] Error 126
make: *** Deleting file 'build/LAUNCHXL/release/genhdr/qstrdefs.generated.h'


You can run the following Python command:
python ../py/makeqstrdata.py build/LAUNCHXL/release/genhdr/qstrdefs.preprocessed.h > build/LAUNCHXL/release/genhdr/qstrdefs.generated.h
 
Comment out line 273 "$(Q)$(PYTHON) $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@" in py.mk and keep making by:

make BTARGET=application BTYPE=release BOARD=LAUNCHXL

5. Finally, you will get application binary mcuimg.bin under micropython\cc3200\build\LAUNCHXL\release folder and boot loader binary bootloader.bin under micropython\cc3200\bootmgr\build\LAUNCHXL\release

6. Refer to http://processors.wiki.ti.com/index.php/User:Dbartlett/MicroPython_CC3200 to download bootloader.bin and mcuimg.bin to CC3200 LaunchPad. Please note CC3200 LAUNCHXL must be Rev 4.1 or higher. Devices older than this revision will not work.

7. Connect to MicroPython and try to following codes to turn on/off Yelleo LED (D6) on CC3200 LaunchPad.

       machine.Pin.board.GP10
       led=machine.Pin(machine.Pin.board.GP10, mode=machine.Pin.OUT)
       led.value(False) -->turn off LED
       led.value(True) -->turn on LED