ESP32 mem32 function doesn't work well

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
PythonKai
Posts: 4
Joined: Sun Jan 31, 2021 4:08 pm
Location: Bavaria Germany

ESP32 mem32 function doesn't work well

Post by PythonKai » Sun Jan 31, 2021 4:35 pm

Hello together,

I use a ESP32 WROOM module and tried to program the internal PCNT module via register access with the machine function mem32.
Unfortunately, it doesn't work as expected.

I tried to manipulate the PCNT_U0_CONF0 register

Code: Select all

>>> bin(mem32[0x3FF57000])
'0b11110000010000'
>>> mem32[0x3FF57000] = 0b1111011110000010000
>>> bin(mem32[0x3FF57000])
'0b11110000010000'
>>> 
The function has no effect, what did I wrong?
Thank you very much for a tip.
Ciao Kai
Last edited by PythonKai on Mon Feb 01, 2021 10:47 am, edited 1 time in total.

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

Re: ESP32 mem32 function dosn't work well

Post by pythoncoder » Mon Feb 01, 2021 9:30 am

The mem32 function is part of the stm library which, as its name suggests, is intended for STM processors. I'm not sure if there is an equivalent for ESP32. You may need to experiment with uctypes.
Peter Hinch
Index to my micropython libraries.

User avatar
Roberthh
Posts: 3668
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ESP32 mem32 function doesn't work well

Post by Roberthh » Mon Feb 01, 2021 11:12 am

You could alternatively try viper code, which give direct access to the hardware. e.g.

Code: Select all

@micropython.viper
def counter(value:int) -> int:
    PCNT_U0_CONF0=ptr32(0x3FF44004)
    PCNT_U0_CONF0[0] = value # 0b1111011110000010000
    res = PCNT_U0_CONF0[0]
    return res

PythonKai
Posts: 4
Joined: Sun Jan 31, 2021 4:08 pm
Location: Bavaria Germany

Re: ESP32 mem32 function doesn't work well

Post by PythonKai » Mon Feb 01, 2021 12:01 pm

Hi Robert,

thank you very much for the viper code example, it looks promising.
Unfortunately, I didn't understand the example in detail.
A pointer to memory is stored in PCNT_U0_CONF0, so far so good.

Why the index [0] is used to get access to the memory ?

Background for the problem:

I tried to measure 1100 pules with a frequency of ~85kHz (11us/pulse).
Neither the python interrupt routine nor a normal function with the Pin object is fast enough.
direct access of Input registers also to slow.
Do you think the viper code is faster ?
Therefor I want to activate the internal PCNT unit, maybe is a complete library for that periphery available ?

Thanks a lot Kai

PythonKai
Posts: 4
Joined: Sun Jan 31, 2021 4:08 pm
Location: Bavaria Germany

Re: ESP32 mem32 function doesn't work well

Post by PythonKai » Tue Feb 02, 2021 1:05 pm

Hello again,

I double checked the possibility to write into the ESP32 registers.
It is possible in several register spaces with the viper code also with the mem32 function.
Thats more or less the following spaces:
SPI
0x3FF42014 - 0x3FF420BC
GPIO/MUX
0x3FF44004 - 0x3FF484C4
ULP RTC
0x3FF48818 - 0x3FF48C44
Sensors
0x3FF48858 - 0x3FF4889C
TIM G0
0x3FF5F000 - 0x3FF5F098
TIM G1
0x3FF60000 - 0x3FF60098
Sensors
0x3FF48858 - 0x3FF4889C
ULP RTC
0x3FF48818 - 0x3FF48C28

Exists an address space restriction in microPython ?
If so, is it possible to disable this ?

Thanks a lot
Ciao Kai

JohnnyGC
Posts: 3
Joined: Sun Jul 25, 2021 9:32 pm

Re: ESP32 mem32 function doesn't work well

Post by JohnnyGC » Fri Aug 13, 2021 8:41 pm

Further to the above post, I unable to write the MCPWM registers. Reading seems to be OK as the default values as per the datasheet are returned.

Reading and writing to the peripherals mentioned by Kai seems to work.

Any help resolving this issue would be appreciated.

JohnnyGC
Posts: 3
Joined: Sun Jul 25, 2021 9:32 pm

Re: ESP32 mem32 function doesn't work well

Post by JohnnyGC » Wed Aug 18, 2021 4:56 am

There is at least an explanation for some of this behaviour. See

https://github.com/micropython/micropython/issues/7658

Post Reply