Page 1 of 1

ESP32 mem32 function doesn't work well

Posted: Sun Jan 31, 2021 4:35 pm
by PythonKai
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

Re: ESP32 mem32 function dosn't work well

Posted: Mon Feb 01, 2021 9:30 am
by pythoncoder
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.

Re: ESP32 mem32 function doesn't work well

Posted: Mon Feb 01, 2021 11:12 am
by Roberthh
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

Re: ESP32 mem32 function doesn't work well

Posted: Mon Feb 01, 2021 12:01 pm
by PythonKai
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

Re: ESP32 mem32 function doesn't work well

Posted: Tue Feb 02, 2021 1:05 pm
by PythonKai
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

Re: ESP32 mem32 function doesn't work well

Posted: Fri Aug 13, 2021 8:41 pm
by JohnnyGC
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.

Re: ESP32 mem32 function doesn't work well

Posted: Wed Aug 18, 2021 4:56 am
by JohnnyGC
There is at least an explanation for some of this behaviour. See

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