Skip to content

ESP32-P4: I2S probably lacks power management (LDO, not about sleep) #12540

@copych

Description

@copych

Board

ESP32P4 DevBoard

Device Description

WT9932P4 devBoard

Hardware Configuration

PCM5102 DAC:
BCLK 48
DOUT 47
WCLK 46

Version

v3.3.8

Type

Bug

IDE Name

Arduino IDE

Operating System

Windows 10

Flash frequency

80MHz

PSRAM enabled

yes

Upload speed

921600

Description

I2S on higher GPIOs requires power management, which is not obvious.
On the mentioned pins I have noticed "strange" behaviour: when I flash I2S example after flashing SDMMC example, i2s is working, but after hard reset, it is silent. So my guess was missing LDO code. Then I have added this piece

#include "sd_pwr_ctrl_by_on_chip_ldo.h"

.
.
.

#if defined CONFIG_IDF_TARGET_ESP32P4
    sd_pwr_ctrl_ldo_config_t ldo_config;
    #ifndef BOARD_SDMMC_POWER_CHANNEL
      #define BOARD_SDMMC_POWER_CHANNEL 4 // GPIO45 of ESP32P4
    #endif
    ldo_config.ldo_chan_id = BOARD_SDMMC_POWER_CHANNEL;
    sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL;
    sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle);
    sd_pwr_ctrl_set_io_voltage(pwr_ctrl_handle, 3300); // 3v3
#endif

and it worked again. As I see it is not the 'right' direct way. But my skill level is definitely isn't enough to make a correct system solution, so I address this to you.

Sketch

https://github.com/espressif/arduino-esp32/tree/master/libraries/ESP_I2S/examples/Simple_tone:


#include <Arduino.h>
#include <ESP_I2S.h>

// The GPIO pins are not fixed, most other pins could be used for the I2S function.
#define I2S_LRC  46
#define I2S_BCLK 48
#define I2S_DIN  47

const int frequency = 440;    // frequency of square wave in Hz
const int amplitude = 500;    // amplitude of square wave
const int sampleRate = 8000;  // sample rate in Hz

i2s_data_bit_width_t bps = I2S_DATA_BIT_WIDTH_16BIT;
i2s_mode_t mode = I2S_MODE_STD;
i2s_slot_mode_t slot = I2S_SLOT_MODE_STEREO;

const unsigned int halfWavelength = sampleRate / frequency / 2;  // half wavelength of square wave

int32_t sample = amplitude;  // current sample value
unsigned int count = 0;

I2SClass i2s;

void setup() {
  Serial.begin(115200);
  Serial.println("I2S simple tone");

  i2s.setPins(I2S_BCLK, I2S_LRC, I2S_DIN);

  // start I2S at the sample rate with 16-bits per sample
  if (!i2s.begin(mode, sampleRate, bps, slot)) {
    Serial.println("Failed to initialize I2S!");
    while (1);  // do nothing
  }
}

void loop() {
  if (count % halfWavelength == 0) {
    // invert the sample every half wavelength count multiple to generate square wave
    sample = -1 * sample;
  }

  // Left channel, the low 8 bits then high 8 bits
  i2s.write(sample);
  i2s.write(sample >> 8);

  // Right channel, the low 8 bits then high 8 bits
  i2s.write(sample);
  i2s.write(sample >> 8);

  // increment the counter for the next sample
  count++;
}

Debug Message

[none]

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

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions