MicroPython on ESP32 with SPIRAM support

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: MicroPython on ESP32 with SPIRAM support

Post by loboris » Sat Dec 23, 2017 9:07 am

@OutoftheBOTS_

ESP 32 has two periphherals which are used for PWM:
  • LEDC module, primarily designed to control the intensity of LEDs, although it can be used to generate PWM signals for other purposes as well. It has 16 channels which can generate independent waveforms.
  • two MCPWM units which can be used to control different motors.
Only the LEDC module is used in MicroPython PWM module at the moment.
I'm planning to add support for MCPWM in January with support for various types of motors/motor drivers.

There is a bug in esp-idf driver preventing using sdcard in SPI mode and display at the same time.
If sdcard is connected in SD mode you can use sdcard and display, but make shure none of display spi pins is connected to any of gpios used for sdcard (CMO-15, CLK-14, D0-2, D1-4, D2-12, D3-13).

I've just tested it on ESP32-WROVER-KIT and it works (display image from sdcard).

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: MicroPython on ESP32 with SPIRAM support

Post by OutoftheBOTS_ » Sat Dec 23, 2017 9:39 am

Can I switch to SD card in SPI mode without needing to rebuild firmware??

Also can I have a file open on SD card and flash at the same time??

Do I just use uos.mountsd(True) and uos.mountsd(False) to switch between flash and SD??

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: MicroPython on ESP32 with SPIRAM support

Post by OutoftheBOTS_ » Sat Dec 23, 2017 9:53 am

Also I have another question for you. it is about your excellent display library.

I am using the ili9341 and your library sets it up in 240x320 mode like most drivers I have seen. I prefer to use it in 320x240 by flicking bit 5 of register 0x36 the Memory Access Control register. This register can also do horizontal and vertical flip as well as RGB/BGR setup. I know your library has tft.orient(orient) does this function set this register or does it do rotation in software on the ESP??

loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: MicroPython on ESP32 with SPIRAM support

Post by loboris » Sat Dec 23, 2017 10:08 am

You have to rebuild the firmware to change the sdcard mode.

You can open file on internal FS and on sdcard at the same time. Up to Maximum number of opened files (configered with menuconfig) on each FS can be opened at the same time.

You have to mount sdcard only once. It is mounted on /sd. Internal file system is mounted on /flash.

uos.mountsd(True) initializes the sdcard driver, mounts sdcard on /sd and changes the active directory to /sd

uos.mountsd(False) or uos.mountsd() initializes the sdcard driver, mounts sdcard on /sd and stays in whatever directory you are currently in.

To access the files on internal FS or sdcard, just use the full path to the file, '/sd/myfile.txt' or '/flash/myfile.txt', or change the working directory with chdir('/sd') or chdir('/flash') before accessing them.

To unmount the sdcard use uos.umountsd().

TFT orientation is changed by setting the MADCTL register (0x36).

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: MicroPython on ESP32 with SPIRAM support

Post by OutoftheBOTS_ » Sat Dec 23, 2017 10:25 am

Thank you a lot that all makes sense with the file system to me now. Hopefully the bug in the esp-idf will get addressed by Espressif as having a large fast access and removable storage like SD for loading images in fast 4 bit mode will be handy for image handling.

I have yet another question for you.

I can't seem to the Telnet working I just get this error

>>> network.telnet.start()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'telnet'

Did I do something wrong during the build of the firmware??

loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: MicroPython on ESP32 with SPIRAM support

Post by loboris » Sat Dec 23, 2017 10:28 am

Check if Enable Telnet server is checked in → MicroPython → System settings (menuconfig)

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: MicroPython on ESP32 with SPIRAM support

Post by OutoftheBOTS_ » Sat Dec 23, 2017 11:31 am

I tried running the compile from my Raspberry pi as it is a Linux OS

When I run ./BUILD.sh menuconfig I get this error

make[1]: Entering directory '/home/pi/MicroPython_ESP32_psRAM_LoBo/Tools/esp-idf/tools/kconfig'
cc -DCURSES_LOC="<curses.h>" -DLOCALE -MD -c -o mconf.o mconf.c
In file included from mconf.c:23:0:
lxdialog/dialog.h:38:20: fatal error: curses.h: No such file or directory
#include CURSES_LOC
^
compilation terminated.
<builtin>: recipe for target 'mconf.o' failed
make[1]: *** [mconf.o] Error 1
make[1]: Leaving directory '/home/pi/MicroPython_ESP32_psRAM_LoBo/Tools/esp-idf/tools/kconfig'
make[1]: Entering directory '/home/pi/MicroPython_ESP32_psRAM_LoBo/Tools/esp-idf/tools/kconfig'
cc -DCURSES_LOC="<curses.h>" -DLOCALE -MD -c -o mconf.o mconf.c
In file included from mconf.c:23:0:
lxdialog/dialog.h:38:20: fatal error: curses.h: No such file or directory
#include CURSES_LOC

compilation terminated.
<builtin>: recipe for target 'mconf.o' failed
make[1]: *** [mconf.o] Error 1
make[1]: Leaving directory '/home/pi/MicroPython_ESP32_psRAM_LoBo/Tools/esp-idf/tools/kconfig'
/home/pi/MicroPython_ESP32_psRAM_LoBo/Tools/esp-idf/make/project_config.mk:20: recipe for target '/home/pi/MicroPython_ESP32_psRAM_LoBo/Tools/esp-idf/tools/kconfig/mconf' failed
make: *** [/home/pi/MicroPython_ESP32_psRAM_LoBo/Tools/esp-idf/tools/kconfig/mconf] Error 2
'make menuconfig' FAILED!

loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: MicroPython on ESP32 with SPIRAM support

Post by loboris » Sat Dec 23, 2017 12:39 pm

OutoftheBOTS_ wrote:
Sat Dec 23, 2017 11:31 am
I tried running the compile from my Raspberry pi as it is a Linux OS
RPi has Linux OS, but there is no Xtenssa Toolchain for RPi (it has the ARM processor).

You can try to build the toolchain "from scratch" on RPi:
You have to install some packages first:

Code: Select all

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install gawk gperf grep gettext automake bison flex texinfo help2man libtool libtool-bin git wget make libncurses-dev python python-serial python-dev python-pip sudo pip install pyserial
Then build the whole Xtenssa toolchain from scratch:

Code: Select all

sudo apt-get install gawk gperf grep gettext python python-dev automake bison flex texinfo help2man libtool libtool-bin
clone -b xtensa-1.22.x https://github.com/espressif/crosstool-NG.git
cd crosstool-NG
./bootstrap
./configure --enable-local
make install ./ct-ng xtensa-esp32-elf
./ct-ng build
chmod -R u+w builds/xtensa-esp32-elf
The process can take the whole day to finish, and I think there is some problem with the latest toolchain chain source and it won't build on arm...

If you only want to test the build process on Linux (recommended and much better than on Windows), and the RPi is not required, it is better to instal Linux (Ubuntu 16.04 recomended) in VirtualBox. It works without problem, you can use minimal distribution, without desktop.

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: MicroPython on ESP32 with SPIRAM support

Post by OutoftheBOTS_ » Sat Dec 23, 2017 10:23 pm

I installed Ubuntu in virtual box but got the exact same error

loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: MicroPython on ESP32 with SPIRAM support

Post by loboris » Sat Dec 23, 2017 10:33 pm

OutoftheBOTS_ wrote:
Sat Dec 23, 2017 10:23 pm
I installed Ubuntu in virtual box but got the exact same error
After fresh ubuntu install you must also install some prerequisites:

Code: Select all

sudo apt-get install git wget make libncurses-dev flex bison gperf python python-serial
You don't need to install Xtenssa toolchain and esp-idf, they are included in the MicroPython repository.

Post Reply