Skip to content

ESP32-S3 ULP-FSM SENS_ register r/w problem #8275

Closed
@rhgoll

Description

@rhgoll

Board

Heltec ESP32 Lora (V3)

Device Description

ESP32-S3 with SX1262 Lora module

Hardware Configuration

nothing

Version

other

IDE Name

PlatformIO

Operating System

Windows 11 22H2

Flash frequency

40Mhz

PSRAM enabled

no

Upload speed

460800

Description

If I read or set the SENS_SAR_PERI_CLK_GATE_CONF_REG from ULP code, it seems not working (but I get no error message).
If I read or set it from the main CPU, it works.

I am using ULP FSM C macro in PlatformIO Arduino framework.
The framework is a custom built from esp-idf 4.4.4, with added support of ULP:

CONFIG_ESP32S3_ULP_COPROC_ENABLED=y
CONFIG_ESP32S3_ULP_COPROC_RESERVE_MEM=512

This code snippet in the sketch is only a small part of an older big project running on ESP32.
The remaining ULP-FSM code (not showed here) ported from the ESP32 is working without problem, only this new register manipulation don't work.

Sketch

#include "Arduino.h"
#include "soc/rtc_cntl_reg.h"
#include "soc/rtc_io_reg.h"
#include "soc/sens_reg.h"
#include "driver/rtc_io.h"
#include "esp32s3/ulp.h"

#define _v(val) ((uint32_t)(&val-RTC_SLOW_MEM))

RTC_NOINIT_ATTR uint32_t rtc_slow_debug_sens1;
RTC_NOINIT_ATTR uint32_t rtc_slow_debug_sens2;
RTC_NOINIT_ATTR uint32_t rtc_slow_debug_sens_cpu;
RTC_NOINIT_ATTR uint32_t rtc_slow_ulp_finished;

const ulp_insn_t program[] =
{
  I_MOVI(R3,_v(rtc_slow_debug_sens1)),
  I_RD_REG(SENS_SAR_PERI_CLK_GATE_CONF_REG,0,15),
  I_STL(R0,R3,0),
  I_RD_REG(SENS_SAR_PERI_CLK_GATE_CONF_REG,16,31),
  I_STH(R0,R3,0),
  I_WR_REG_BIT(SENS_SAR_PERI_CLK_GATE_CONF_REG,SENS_IOMUX_CLK_EN_S,1),
  I_MOVI(R3,_v(rtc_slow_debug_sens2)),
  I_RD_REG(SENS_SAR_PERI_CLK_GATE_CONF_REG,0,15),
  I_STL(R0,R3,0),
  I_RD_REG(SENS_SAR_PERI_CLK_GATE_CONF_REG,16,31),
  I_STH(R0,R3,0),
  I_MOVI(R3,_v(rtc_slow_ulp_finished)),
  I_MOVI(R0,1),
  I_STL(R0,R3,0),
  I_END(),
  I_HALT()
};

size_t load_addr = 0;
size_t size = sizeof(program)/sizeof(ulp_insn_t);

String toBinary(uint32_t num);

void setup()
{
  Serial.begin(115200);
  rtc_slow_ulp_finished=0;
  Serial.println("Starting ULP...");
  ulp_process_macros_and_load(load_addr, program, &size);
  ulp_run(load_addr);   
  delay(100); //wait for ulp to finish
  Serial.printf("ULP finished: %d\n",rtc_slow_ulp_finished);
  Serial.println("PERI_REG before ULP setting: "+toBinary(rtc_slow_debug_sens1));
  Serial.println("PERI_REG after ULP setting: "+toBinary(rtc_slow_debug_sens2));
  
  rtc_slow_debug_sens_cpu=READ_PERI_REG(SENS_SAR_PERI_CLK_GATE_CONF_REG);
  Serial.println("PERI_REG before CPU setting: "+toBinary(rtc_slow_debug_sens_cpu));
  rtc_gpio_init(GPIO_NUM_4);
  rtc_slow_debug_sens_cpu=READ_PERI_REG(SENS_SAR_PERI_CLK_GATE_CONF_REG);
  Serial.println("PERI_REG after CPU setting: "+toBinary(rtc_slow_debug_sens_cpu)); 
}

void loop()
{
}

String toBinary(uint32_t num)
{
    String binary;
    for (uint8_t i=31;i>0;i--)
    {
      binary+=bitRead(num,i);
    }
    return binary;
}

Debug Message

Starting ULP...
ULP finished: 1
PERI_REG before ULP setting: 0010000000000000000000000000000
PERI_REG after ULP setting: 0010000000000000000000000000000
PERI_REG before CPU setting: 0000000000000000000000000000000
PERI_REG after CPU setting: 1000000000000000000000000000000

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions