MicroPython on ESP32 with SPIRAM support

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

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Post by loboris » Sat Sep 16, 2017 7:58 am

slzatz wrote:Is there any documentation available for the display module?
The documentation will be available in the next couple of days.

patrick.pollet
Posts: 16
Joined: Fri Apr 29, 2016 7:08 pm

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Post by patrick.pollet » Mon Sep 18, 2017 10:56 am

Dear All,

I think i encountered an issue with UART :

Trying UART1
_________________________________________________________
>>> from machine import UART
>>> u = UART(1)
>>> u.read()
Guru Meditation Error of type LoadProhibited occurred on core 0. Exception was unhandled.
Register dump:
PC : 0x4008804a PS : 0x00060433 A0 : 0x8008b827 A1 : 0x3ffbc4e0
A2 : 0x000136b8 A3 : 0x00000000 A4 : 0x88888888 A5 : 0x00000058
A6 : 0x3ffbc8c0 A7 : 0x00000008 A8 : 0x88888888 A9 : 0x3fa00008
A10 : 0x3ffb15d0 A11 : 0x00060423 A12 : 0x00060220 A13 : 0x3f4053f5
A14 : 0x00000000 A15 : 0x00000001 SAR : 0x00000006 EXCCAUSE: 0x0000001c
EXCVADDR: 0x8888888c LBEG : 0x400d7bb4 LEND : 0x400d7be0 LCOUNT : 0x0001f43b

Backtrace: 0x4008804a:0x3ffbc4e0 0x4008b827:0x3ffbc500 0x4008b868:0x3ffbc520 0x40087772:0x3ffbc540 0x40087947:0x3ffbc560 0x40084e7b:0x3ffbc580 0x40084eab:0x3ffbc5a0 0x40084ffc:0x3ffbc5d0 0x401115dc:0x3ffbc5f0 0x401083d4:0x3ffbc8b0 0x40107e18:0x3ffbc900 0x400d7c7c:0x3ffbc930 0x400d72a8:0x3ffbc950 0x400fc64d:0x3ffbc970 0x400fc66c:0x3ffbc990 0x400d8456:0x3ffbc9b0 0x400fc98a:0x3ffbca10 0x400dcf3f:0x3ffbca50 0x400da0c5:0x3ffbcab0 0x400fc278:0x3ffbcad0 0x400fc488:0x3ffbcaf0 0x400fea7d:0x3ffbcb10 0x400ff22e:0x3ffbcb30 0x400f5223:0x3ffbcba0 0x400f54d4:0x3ffbcc40 0x400ed908:0x3ffbcc80

CPU halted.
____________________________________________________________

And UART2 (it's slightly different) :

_____________________________________________________________
>>> from machine import UART
>>> u = UART(2)
>>> u.read()
assertion "(rule->act & RULE_ACT_KIND_MASK) == RULE_ACT_LIST" failed: file "/home/pollet/esp32/esp32psram/MicroPython_ESP32_psRAM_LoBo/MicroPython_BUILD/components/micropython/py/parse.c", line 936, function: mp_parse
abort() was called at PC 0x40107e1b on core 0
Guru Meditation Error: Core 0 panic'ed (abort)

Backtrace: 0x40008155:0x3ffbcae0 0x40007d16:0x3ffbcb00 0x400ff39e:0x3ffbcb30 0x400f5223:0x3ffbcba0 0x400f54d4:0x3ffbcc40 0x400ed908:0x3ffbcc80

CPU halted.
_______________________________________________________________

Checking the source i find that the default Pins for UART 1 are 9 & 10 and for UART 2 it's 16 & 17, these Pins seems to be involved in communication with psRAM and Flash.
I tried to change that with UART.init(pins=(...)) but i have the same crashs.
I will try to change it in source and recompile a new firmware (i will also try to investigate the assertion failed concerning UART 2).

Any idea or suggestion will be appreciate.

Regards.

Patrick

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

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Post by loboris » Mon Sep 18, 2017 12:18 pm

@patrick.pollet
Try this:

Code: Select all

uart = machine.UART(1,baudrate=115200,tx=25,rx=26)
And look at this post.
I've tested it connecting ESP32 board via USBtoSerial adapter to PC (Linux, minicom) and it works without problem.
If you are not using the latest version, please pull the latest commit from GitHub.

patrick.pollet
Posts: 16
Joined: Fri Apr 29, 2016 7:08 pm

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Post by patrick.pollet » Mon Sep 18, 2017 12:38 pm

@loboris,

Once again thanks for your precious help.

User avatar
pythoncoder
Posts: 4380
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Post by pythoncoder » Mon Sep 18, 2017 3:18 pm

This loopback test (which runs on ESP32) is a simple way to test UARTs, in particular the ability to concurrently send and receive. Link pins 24 and 25.

Code: Select all

import uasyncio as asyncio
from machine import UART
uart = UART(1, baudrate = 9600, tx = 25, rx =26)

async def sender():
    swriter = asyncio.StreamWriter(uart, {})
    while True:
        await swriter.awrite('Hello uart\n')
        await asyncio.sleep(2)

async def receiver():
    sreader = asyncio.StreamReader(uart)
    while True:
        res = await sreader.readline()
        print('Recieved', res)

loop = asyncio.get_event_loop()
loop.create_task(sender())
loop.create_task(receiver())
loop.run_forever()
Peter Hinch

patrick.pollet
Posts: 16
Joined: Fri Apr 29, 2016 7:08 pm

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Post by patrick.pollet » Mon Sep 18, 2017 4:14 pm

May i suggest little changes ?

In machine_uart.c, line 218

Code: Select all

 
    switch (uart_num) {
        case UART_NUM_0:
            self->rx = UART_PIN_NO_CHANGE; // GPIO 3
            self->tx = UART_PIN_NO_CHANGE; // GPIO 1
            break;
        case UART_NUM_1:
            self->rx = 15;
            self->tx = 4;
            break;
        case UART_NUM_2:
            self->rx = 26;
            self->tx = 25;
            break;
    }
To use default pins for UART1 & UART2 which do not cause CPU crash when doing something like :
uart = UART(1, baudrate=115200)

and,

in modsocket.c line 507, i added:

Code: Select all

{ MP_OBJ_NEW_QSTR(MP_QSTR_readinto), (mp_obj_t)&mp_stream_readinto_obj },
To have a readinto method for socket (which is useful (at least it's useful for me :-))).

Both suggestions was tested and works.

Patrick

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

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Post by loboris » Mon Sep 18, 2017 5:15 pm

@patrick.pollet
Thank you for the good suggestion about default UART pins.
Maybe it would be even better to simply declare tx & rx as mandatory arguments and check for pins not allowed to be used.

I've already added readinto to modsocket (I've updated MicroPython core to the latest commits from the MicroPython main port).
The changes will be pushed tomorrow or the day after.
Today the new esp-idf and toolchain versions were pushed to the GitHub which enables SPIRAM support using the main branch. I'm testing it now...

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

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Post by loboris » Wed Sep 20, 2017 11:56 am

:!: Update:

As of Sep 18, 2017 full support for psRAM is included into esp-idf and xtensa toolchain.
Building with special versions of esp-idf and Xtensa toolchain is no longer needed.
  • Updated esp-idf and xtenssa toolchain to the latest version …
  • Building with psRAM support is now included in main branch
  • No psram parameter is needed for BUILD.sh, just configure psram support in menuconfig
  • Updated MicroPython core to the latest version
  • Buxfixes and improvements in display module, support for ST7735 based displays added
  • Some changes to UART module, tx&rx arguments are now mandatory when creating the UART instance
  • Neopixel module improved, unlimited number of pixels is now supported and less memory is used
  • Other minor bugfixes
  • Bilding on Windows is now fully supported, latest xtensa toolchain for Windows is included

slzatz
Posts: 92
Joined: Mon Feb 09, 2015 1:09 am

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Post by slzatz » Fri Sep 22, 2017 9:46 am

I am using the latest firmware without psRAM enabled. At the end of a reset I get:

Code: Select all

...

FreeRTOS running on BOTH CORES, MicroPython task started on App Core.

uPY stack size = 19456 bytes
uPY  heap size = 81920 bytes

D (984) intr_alloc: Connected src 34 to int 3 (cpu 1)
Reset reason: Power on reset Wakeup: Power on wake
D (994) intr_alloc: Connected src 22 to int 4 (cpu 1)
W (1003) vfs_native: f_mount failed (13)
W (1004) vfs_native: ** Formatting Flash FATFS partition **
W (1004) vfs_native: ** Mounting again **
OSError: [Errno 2] ENOENT
MicroPython ESP32_LoBo_v2.0.2 - 2017-09-19 on ESP32 board with ESP32
Type "help()" for more information.
>>> 
Do I need to do address the vfs_native warnings?

cable134
Posts: 27
Joined: Sun Aug 20, 2017 10:51 pm

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Post by cable134 » Fri Sep 22, 2017 9:58 am

Dear loboris,
your progress is awesome. Thank you for your great contribution.

I've remarked that you implemented new module functionality as "GSM module and PPPoS support" (MICROPY_USE_GSM).
Is it ready for testing?

Thank you.

Post Reply