ULP pin speed and consistency

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
errorfixrepeat
Posts: 8
Joined: Tue May 07, 2019 5:48 pm

ULP pin speed and consistency

Post by errorfixrepeat » Tue May 07, 2019 6:23 pm

I am trying to use the ULP coprocessor to monitor of an SPI communication, and generate a new response at the same time. The end goal is to have the ULP as a man in the middle altering the messages as they pass.

I have implemented the code which works well at low speeds using an ESP8266 to spoof the signals, but when I try it on the real 125kHz clock it doesn't work. Looking at the signals on a logic analyser this seemed to be an issue with speed, so I have tried to create a minimum test case to profile. The ULP toggles a pin as fast as possible, while the main processor does the same using machine.Pin for comparison.

Here are two screenshots from the logic analyser:
ULP: ~300kHz
[url=https://ibb.co/FhVkJvb][img]https://i.ibb.co/6yBcbhR/Screenshot-201 ... -45-28.png[/img][/url]
ESP32: 53kHz
[url=https://ibb.co/zxyfTQm][img]https://i.ibb.co/h9P8JLg/Screenshot-201 ... -44-32.png[/img][/url]


The ULP generated signal is not consistent, with some cycles taking nearly double the time and an uneven duty cycle. This doesn't give sufficient time for other parts of the ULP routine to run.

Are these speeds typical when using the ULP or are there any ways to speed up the ULP?

errorfixrepeat
Posts: 8
Joined: Tue May 07, 2019 5:48 pm

Re: ULP pin speed and consistency

Post by errorfixrepeat » Tue May 07, 2019 8:00 pm

ULP code:
/*
* Taken from JoBa1 ESP32 ULP blink example
*/

#include "soc/soc_ulp.h" // for WRITE_RTC_REG
#include "soc/rtc_io_reg.h" // for RTC_GPIO_*

.set gpio, 15 // GPIO12 - RTC 15 - Touch5

.text
entry:
// might be needed for some pads, but surely not #2
WRITE_RTC_REG(RTC_IO_TOUCH_PAD5_REG, RTC_IO_TOUCH_PAD5_TO_GPIO_S, 1, 1)
// use digital function, not rtc function
WRITE_RTC_REG(RTC_IO_TOUCH_PAD5_REG, RTC_IO_TOUCH_PAD5_MUX_SEL_S, 1, 1)
// gpio_2 shall be output, not input
WRITE_RTC_REG(RTC_GPIO_OUT_REG, RTC_GPIO_OUT_DATA_S + gpio, 1, 1)

on:
WRITE_RTC_REG(RTC_GPIO_ENABLE_W1TS_REG, RTC_GPIO_ENABLE_W1TS_S + gpio, 1, 1)
WRITE_RTC_REG(RTC_GPIO_ENABLE_W1TC_REG, RTC_GPIO_ENABLE_W1TC_S + gpio, 1, 1)
jump on // back you go.

errorfixrepeat
Posts: 8
Joined: Tue May 07, 2019 5:48 pm

Re: ULP pin speed and consistency

Post by errorfixrepeat » Tue May 07, 2019 8:01 pm

Micropython Code:
from esp32 import ULP
from machine import mem32
from machine import Pin
import utime

f = open('ulp_main.bin')
# binary = src_to_binary(source)
binary = f.read()

load_addr, entry_addr = 0, 4 #144 on real program

ULP_MEM_BASE = 0x50000000
ULP_DATA_MASK = 0xffff # ULP data is only in lower 16 bits

ulp = ULP()
ulp.set_wakeup_period(0, 10000) # use timer0, wakeup after 50.000 cycles
ulp.load_binary(load_addr, binary)
# mem32[ULP_MEM_BASE + load_addr] = 0x1000
ulp.run(entry_addr)

flag=Pin(13, Pin.OUT)
while True:
flag.value(1)
flag.value(0)

Post Reply