close

參考資料
https://www.digikey.com/en/maker/blogs/programming-micropython-on-the-esp8266/57abec67b5c34eb398d8fe6ae6442f46
https://www.raspberrypi.org/forums/viewtopic.php?t=191744 (port unix)

Compile and Flash MicroPython Firmware

Install Homebrew

The first thing you will need to install is a package manager called “Homebrew”. To install Homebrew open up the terminal window and copy and paste the following command:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install Git

Now that we have brew package manager install you can go ahead and install git if it is not installed already by typing the following command in the terminal window: 

brew install git

This will then begin to install git, which is where we will download all our code from to compile the firmware such as the ESP SDK and the MicroPython files.

Installing the ESP SDK

If you do not wish to install and compile the MicroPython firmware then you can download an already built firmware file from www.micropython.org/downloads .

Programming%20MicroPython%20on%20the%20ESP8266

To build the MicroPython firmware for the ESP8266 you will first need to build the ESP SDK toolchain that can actually do the compilation on your computer.

You will also need to install the following dependencies if not already installed:

brew tap homebrew/dupes
brew install binutils coreutils automake wget gawk libtool gperf gnu-sed --with-default-names grep
export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"

In addition to the development tools MacOS needs a case-sensitive filesystem. You might need to create a virtual disk and build esp-open-sdk on it:

sudo hdiutil create ~/Documents/case-sensitive.dmg -volname "case-sensitive" -size 10g -fs "Case-sensitive HFS+"
sudo hdiutil mount ~/Documents/case-sensitive.dmg

Navigate to where you downloaded the ESP SDK by typing the following in the terminal:

cd /Volumes/case-sensitive

In Mac OS or Linux you need to open up a terminal window to issue a git command, make sure you are in the directory where you want to download the files. Run the following command to clone the repository:

cd /Desktop/
git clone https://github.com/pfalcon/esp-open-sdk.git

This will now download and install the ESP open SDK repository to your desktop on your computer.

To build the tool-chain and SDK type the following:

cd esp-open-sdk
make

In order for us to use the tool-chain, you must also create a path so the MicroPython compiler can find it:

export PATH=/Volumes/case-sensitive/esp-open-sdk/xtensa-lx106-elf/bin:$PATH

Install MicroPython

To install MicroPython you must first compile the firmware to flash on to your ESP device. Make sure you are in a directory where you want to download the files to and download the following git repository:

git  clone https://github.com/micropython/micropython.git

Add the external dependencies to the MicroPython repository checkout:

git submodule update --init

The MicroPython cross-compiler must be built to pre-compile some of the built-in scripts to bytecode. This can be done by using:

make –C mpy-cross

Then, to build MicroPython for the ESP8266, just run:

cd esp8266
make axtls
make

This will produce binary images in the build/ subdirectory.

Flashing the Firmware

If you install MicroPython to your module for the first time, or after installing any other firmware, you should erase flash completely:

esptool.py --port =/dev/cu.usbserial-AI032CSO erase_flash

Erase flash also as a troubleshooting measure, if a module doesn't behave as expected.

To flash MicroPython image to your ESP8266 you will also need to create a path to the esptool, which was included in the ESP SDK we install previously:

export PATH=/Volumes/case-sensitive/esp-open-sdk/esptool:$PATH

Now run the following to flash the MicroPython firmware to the ESP8266 module, making sure that it is in Bootloader mode:

make PORT=/dev/cu.usbserial-AI032CSO deploy

Connecting to the ESP8266 module

Now everything has been setup on the ESP8266 board you can now go ahead and connect to it usingr Putty(Windows)

Programming%20MicroPython%20on%20the%20ESP8266

Programming in MicroPython

 

arrow
arrow
    全站熱搜

    stanley 發表在 痞客邦 留言(1) 人氣()