You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Tomek CEDRO <to...@cedro.info> on 2023/02/18 19:59:40 UTC

esp32 / pcnt / rotary encoder

Hello world :-)

Is PCNT peripheral supported on ESP32 port in NuttX?

I am building a new device that will use industrial rotary encoder
with pulses up to 1..3MHz so GPIO/IRQ processing is probably not a
good idea.

I am wondering if there are such rotary use cases in NuttX?

I wanted to use RISC-V CPU.. I have whole bunch of ESP32-C3.. but it
has no PCNT peripheral that sounds like a perfect candidate for the
task.. so I will probably use ESP32 :-)

Any hints welcome :-)
Tomek

-- 
CeDeROM, SQ7MHZ, http://www.tomek.cedro.info

Re: esp32 / pcnt / rotary encoder

Posted by "Alan C. Assis" <ac...@gmail.com>.
Yes, you can use MCUBoot to do FOTA that is already is integrated on
NuttX for ESP32

On 2/19/23, Tomek CEDRO <to...@cedro.info> wrote:
> Allright, I have NuttX origin/master built on FreeBSD and running on
> ESP32-DevKitC :-)
>
> For some reason uname -a shows release 10.4.0 not 12.0.0(99/dev whatever)
> o_O
>
> The whole NuttX firmware build and flashing is faster than scripts
> upload in MicroPython heheh.. and they fight for encoder / timer /
> pcnt api for over two years.. I can also see CAN support.. maybe its
> finally time to switch to NuttX for gooood =) =) =)
>
> Now lets get to qencoder stuff ]:->
>
> TANK U FOLKS! :-)
>
> Tomek
>
> ps/2: Does NuttX have some sort of FOTA mechanism so the signed
> firmware could be updated remotely over WiFi/IP from some sort of
> server with a fallback mechanism of
> boot-from-last-that-worked-or-bare-nonalterable? :-)
>
>
> % /usr/bin/time -h gmake -j10 all flash ESPTOOL_PORT=/dev/cuaU0
>
> CPP:
> /XXX/nuttxworkspace.git/nuttx/boards/xtensa/esp32/esp32-devkitc/../common/scripts/esp32_rom.ld->
> /zraid/daCPP:
> /XXX/nuttxworkspace.git/nuttx/boards/xtensa/esp32/esp32-devkitc/../common/scripts/flat_memory.ld->
> /zraid/CPP:
> /XXX/nuttxworkspace.git/nuttx/boards/xtensa/esp32/esp32-devkitc/../common/scripts/legacy_sections.ld->
> /zrLD: nuttx
> CP: nuttx.hex
> MKIMAGE: ESP32 binary
> esptool.py -c esp32 elf2image -fs 4MB -fm dio -ff 40m -o nuttx.bin nuttx
> esptool.py v4.4
> Creating esp32 image...
> Merged 1 ELF section
> Successfully created esp32 image.
> Generated: nuttx.bin (ESP32 compatible)
> esptool.py -c esp32 -p /dev/cuaU0 -b 921600  write_flash -fs detect
> -fm dio -ff 40m 0x10000 nuttx.bin
> esptool.py v4.4
> Serial port /dev/cuaU0
> Connecting............
> Chip is ESP32-D0WDQ6 (revision v1.0)
> Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse,
> Coding Scheme None
> Crystal is 40MHz
> MAC: 08:3a:f2:ab:ff:34
> Uploading stub...
> Running stub...
> Stub running...
> Changing baud rate to 921600
> Changed.
> Configuring flash size...
> Auto-detected Flash size: 4MB
> Flash will be erased from 0x00010000 to 0x0003afff...
> Compressed 172624 bytes to 97312...
> Wrote 172624 bytes (97312 compressed) at 0x00010000 in 1.9 seconds
> (effective 742.0 kbit/s)...
> Hash of data verified.
>
> Leaving...
> Hard resetting via RTS pin...
>         16,89s real             47,78s user             25,60s sys
>
>
> % pyserial-miniterm /dev/cuaU0 115200
> --- Miniterm on /dev/cuaU0  115200,8,N,1 ---
> --- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
>
> nsh> ␛[Kuname -a
> NuttX 10.4.0 74790c8033 Feb 19 2023 05:06:25 xtensa esp32-devkitc
> nsh> ␛[Kcoremark
> 2K performance run parameters for coremark.
> CoreMark Size    : 666
> Total ticks      : 17470
> Total time (secs): 17.470000
> Iterations/Sec   : 686.891815
> Iterations       : 12000
> Compiler version : GCC8.4.0
> Compiler flags   : Using NuttX compilation options
> Parallel PThreads : 2
> Memory location  : Defined by the NuttX configuration
> seedcrc          : 0xe9f5
> [0]crclist       : 0xe714
> [1]crclist       : 0xe714
> [0]crcmatrix     : 0x1fd7
> [1]crcmatrix     : 0x1fd7
> [0]crcstate      : 0x8e3a
> [1]crcstate      : 0x8e3a
> [0]crcfinal      : 0xa14c
> [1]crcfinal      : 0xa14c
> Correct operation validated. See README.md for run and reporting rules.
> CoreMark 1.0 : 686.891815 / GCC8.4.0 Using NuttX compilation options /
> Defined by the NuttX configuration / 2:PThreads
>
>
> --
> CeDeROM, SQ7MHZ, http://www.tomek.cedro.info
>

Re: esp32 / pcnt / rotary encoder

Posted by Tomek CEDRO <to...@cedro.info>.
Allright, I have NuttX origin/master built on FreeBSD and running on
ESP32-DevKitC :-)

For some reason uname -a shows release 10.4.0 not 12.0.0(99/dev whatever) o_O

The whole NuttX firmware build and flashing is faster than scripts
upload in MicroPython heheh.. and they fight for encoder / timer /
pcnt api for over two years.. I can also see CAN support.. maybe its
finally time to switch to NuttX for gooood =) =) =)

Now lets get to qencoder stuff ]:->

TANK U FOLKS! :-)

Tomek

ps/2: Does NuttX have some sort of FOTA mechanism so the signed
firmware could be updated remotely over WiFi/IP from some sort of
server with a fallback mechanism of
boot-from-last-that-worked-or-bare-nonalterable? :-)


% /usr/bin/time -h gmake -j10 all flash ESPTOOL_PORT=/dev/cuaU0

CPP:  /XXX/nuttxworkspace.git/nuttx/boards/xtensa/esp32/esp32-devkitc/../common/scripts/esp32_rom.ld->
/zraid/daCPP:  /XXX/nuttxworkspace.git/nuttx/boards/xtensa/esp32/esp32-devkitc/../common/scripts/flat_memory.ld->
/zraid/CPP:  /XXX/nuttxworkspace.git/nuttx/boards/xtensa/esp32/esp32-devkitc/../common/scripts/legacy_sections.ld->
/zrLD: nuttx
CP: nuttx.hex
MKIMAGE: ESP32 binary
esptool.py -c esp32 elf2image -fs 4MB -fm dio -ff 40m -o nuttx.bin nuttx
esptool.py v4.4
Creating esp32 image...
Merged 1 ELF section
Successfully created esp32 image.
Generated: nuttx.bin (ESP32 compatible)
esptool.py -c esp32 -p /dev/cuaU0 -b 921600  write_flash -fs detect
-fm dio -ff 40m 0x10000 nuttx.bin
esptool.py v4.4
Serial port /dev/cuaU0
Connecting............
Chip is ESP32-D0WDQ6 (revision v1.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse,
Coding Scheme None
Crystal is 40MHz
MAC: 08:3a:f2:ab:ff:34
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Flash will be erased from 0x00010000 to 0x0003afff...
Compressed 172624 bytes to 97312...
Wrote 172624 bytes (97312 compressed) at 0x00010000 in 1.9 seconds
(effective 742.0 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
        16,89s real             47,78s user             25,60s sys


% pyserial-miniterm /dev/cuaU0 115200
--- Miniterm on /dev/cuaU0  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---

nsh> ␛[Kuname -a
NuttX 10.4.0 74790c8033 Feb 19 2023 05:06:25 xtensa esp32-devkitc
nsh> ␛[Kcoremark
2K performance run parameters for coremark.
CoreMark Size    : 666
Total ticks      : 17470
Total time (secs): 17.470000
Iterations/Sec   : 686.891815
Iterations       : 12000
Compiler version : GCC8.4.0
Compiler flags   : Using NuttX compilation options
Parallel PThreads : 2
Memory location  : Defined by the NuttX configuration
seedcrc          : 0xe9f5
[0]crclist       : 0xe714
[1]crclist       : 0xe714
[0]crcmatrix     : 0x1fd7
[1]crcmatrix     : 0x1fd7
[0]crcstate      : 0x8e3a
[1]crcstate      : 0x8e3a
[0]crcfinal      : 0xa14c
[1]crcfinal      : 0xa14c
Correct operation validated. See README.md for run and reporting rules.
CoreMark 1.0 : 686.891815 / GCC8.4.0 Using NuttX compilation options /
Defined by the NuttX configuration / 2:PThreads


-- 
CeDeROM, SQ7MHZ, http://www.tomek.cedro.info

Re: esp32 / pcnt / rotary encoder

Posted by Tomek CEDRO <to...@cedro.info>.
On Sat, Feb 18, 2023 at 9:53 PM Alan C. Assis  wrote:
> Hi Tomek,
> Please take a look:
> https://github.com/apache/nuttx/blob/master/arch/xtensa/src/esp32/esp32_qencoder.c
>
> It was tested with common rotary encoders (i.e. those used on 3D
> Printers to select items on UI menu).
>
> I didn't test it at high frequencies, but according with this thread
> https://esp32.com/viewtopic.php?t=7011 it could work up to 40MHz (APB
> Freq / 2) if you disable the input filter.

Thank you Alan!! Looks what I exactly need! :-)

-- 
CeDeROM, SQ7MHZ, http://www.tomek.cedro.info

Re: esp32 / pcnt / rotary encoder

Posted by "Alan C. Assis" <ac...@gmail.com>.
Hi Tomek,

Please take a look:

https://github.com/apache/nuttx/blob/master/arch/xtensa/src/esp32/esp32_qencoder.c

It was tested with common rotary encoders (i.e. those used on 3D
Printers to select items on UI menu).

I didn't test it at high frequencies, but according with this thread
https://esp32.com/viewtopic.php?t=7011 it could work up to 40MHz (APB
Freq / 2) if you disable the input filter.

BR,

Alan

On 2/18/23, Tomek CEDRO <to...@cedro.info> wrote:
> Hello world :-)
>
> Is PCNT peripheral supported on ESP32 port in NuttX?
>
> I am building a new device that will use industrial rotary encoder
> with pulses up to 1..3MHz so GPIO/IRQ processing is probably not a
> good idea.
>
> I am wondering if there are such rotary use cases in NuttX?
>
> I wanted to use RISC-V CPU.. I have whole bunch of ESP32-C3.. but it
> has no PCNT peripheral that sounds like a perfect candidate for the
> task.. so I will probably use ESP32 :-)
>
> Any hints welcome :-)
> Tomek
>
> --
> CeDeROM, SQ7MHZ, http://www.tomek.cedro.info
>