Merge branch 'change/do_mpll_ldo_earlier' into 'master'

mpll: do mpll ldo init earlier

See merge request espressif/esp-idf!28104
This commit is contained in:
Armando (Dou Yiwen) 2023-12-26 20:59:35 +08:00
commit 22b9bc2708
13 changed files with 119 additions and 44 deletions

View File

@ -70,6 +70,9 @@ if(NOT BOOTLOADER_BUILD)
if(CONFIG_SOC_MULTI_USAGE_LDO_SUPPORTED)
list(APPEND srcs "ldo/esp_ldo.c")
if(CONFIG_SPIRAM OR CONFIG_SOC_CLK_MPLL_SUPPORTED)
list(APPEND srcs "ldo/esp_ldo_psram.c")
endif()
endif()
if(CONFIG_SOC_ASYNC_MEMCPY_SUPPORTED)

View File

@ -324,6 +324,11 @@ menu "Hardware Settings"
endmenu
menu "LDO Config"
depends on SOC_MULTI_USAGE_LDO_SUPPORTED
orsource "./port/$IDF_TARGET/Kconfig.ldo"
endmenu
# Invisible bringup bypass options for esp_hw_support component
config ESP_BRINGUP_BYPASS_CPU_CLK_SETTING
bool

View File

@ -44,7 +44,7 @@ typedef struct {
} esp_ldo_unit_init_cfg_t;
/**
* @Brief Init a LDO during early stage
* @brief Init a LDO during early stage
*
* @note This API is only for early stage usage
*

View File

@ -0,0 +1,22 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Init PSRAM VDD LDO during early stage
*/
void esp_ldo_vdd_psram_early_init(void);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,32 @@
/*
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdlib.h>
#include <string.h>
#include "sdkconfig.h"
#include "esp_attr.h"
#include "esp_log.h"
#include "esp_check.h"
#include "soc/soc_caps.h"
#include "hal/ldo_ll.h"
#include "esp_private/esp_ldo.h"
#include "esp_private/esp_ldo_psram.h"
void esp_ldo_vdd_psram_early_init(void)
{
if (CONFIG_ESP_VDD_PSRAM_LDO_ID != -1) {
esp_ldo_unit_init_cfg_t unit_cfg = {
.unit_id = LDO_ID2UNIT(CONFIG_ESP_VDD_PSRAM_LDO_ID),
.cfg = {
.voltage_mv = CONFIG_ESP_VDD_PSRAM_LDO_VOLTAGE_MV,
},
.flags.enable_unit = true,
.flags.shared_ldo = true,
};
esp_ldo_unit_handle_t early_unit = esp_ldo_init_unit_early(&unit_cfg);
assert(early_unit);
}
}

View File

@ -0,0 +1,24 @@
config ESP_VDD_PSRAM_LDO_ID
int "PSRAM VDD connected LDO ID, set -1 for using external power supply and disable internal LDO"
default 2
range -1 4
help
PSRAM VDD pin connected LDO ID.
PSRAM VDD needs to be connected to an voltage output. This option selects the on-chip
LDO which is connected to the PSRAM VDD.
Set to -1 for connecting to external voltage output.
choice ESP_VDD_PSRAM_LDO_VOLTAGE_MV
prompt "PSRAM VDD connected LDO voltage"
depends on ESP_VDD_PSRAM_LDO_ID != -1
default ESP_VDD_PSRAM_LDO_VOLTAGE_MV_1800
help
Select the LDO (ESP_VDD_PSRAM_LDO_ID) voltage output
config ESP_VDD_PSRAM_LDO_VOLTAGE_MV_1800
bool "1.8V"
endchoice
config ESP_VDD_PSRAM_LDO_VOLTAGE_MV
int
default 1800 if ESP_VDD_PSRAM_LDO_VOLTAGE_MV_1800

View File

@ -8,8 +8,10 @@
#include "esp_attr.h"
#include "esp_err.h"
#include "esp_log.h"
#include "esp_clk_tree.h"
#include "esp_private/periph_ctrl.h"
#include "esp_private/esp_ldo.h"
#include "esp_private/rtc_clk.h"
#include "esp_private/esp_ldo_psram.h"
#include "../esp_psram_impl.h"
#include "rom/opi_flash.h"
#include "hal/psram_ctrlr_ll.h"
@ -36,6 +38,8 @@
#define AP_HEX_PSRAM_CS_ECC_HOLD_TIME 4
#define AP_HEX_PSRAM_CS_HOLD_DELAY 3
#define AP_HEX_PSRAM_MPLL_DEFAULT_FREQ_MHZ 400
typedef struct {
union {
struct {
@ -350,18 +354,13 @@ static void s_configure_psram_ecc(void)
esp_err_t esp_psram_impl_enable(void)
{
#if CONFIG_SPIRAM_LDO_ID
if (CONFIG_SPIRAM_LDO_ID != -1) {
esp_ldo_unit_init_cfg_t unit_cfg = {
.unit_id = LDO_ID2UNIT(CONFIG_SPIRAM_LDO_ID),
.cfg = {
.voltage_mv = CONFIG_SPIRAM_LDO_VOLTAGE_MV,
},
.flags.enable_unit = true,
};
esp_ldo_unit_handle_t early_unit = esp_ldo_init_unit_early(&unit_cfg);
assert(early_unit);
}
esp_ldo_vdd_psram_early_init();
#if SOC_CLK_MPLL_SUPPORTED
uint32_t xtal_freq = 0;
ESP_ERROR_CHECK(esp_clk_tree_src_get_freq_hz(SOC_MOD_CLK_XTAL, ESP_CLK_TREE_SRC_FREQ_PRECISION_EXACT, &xtal_freq));
assert(xtal_freq == 40000000);
rtc_clk_mpll_enable();
rtc_clk_mpll_configure(xtal_freq / 1000000, AP_HEX_PSRAM_MPLL_DEFAULT_FREQ_MHZ);
#endif
PSRAM_RCC_ATOMIC() {

View File

@ -46,31 +46,6 @@ menu "PSRAM config"
If enabled, 1/8 of the PSRAM total size will be reserved for error-correcting code.
config SPIRAM_LDO_ID
int "PSRAM connected LDO ID, set -1 for using external power supply"
default 2
range -1 4
help
PSRAM VDD needs to be connected to an voltage output. This option selects the on-chip
LDO which is connected to the PSRAM VDD.
Set to -1 for connecting to external voltage output.
choice SPIRAM_LDO_VOLTAGE_MV
prompt "PSRAM connected LDO voltage"
depends on SPIRAM_LDO_ID != -1
default SPIRAM_LDO_VOLTAGE_MV_1800
help
Select the speed for the PSRAM chip.
config SPIRAM_LDO_VOLTAGE_MV_1800
bool "1.8V"
endchoice
config SPIRAM_LDO_VOLTAGE_MV
int
default 1800 if SPIRAM_LDO_VOLTAGE_MV_1800
config SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
bool "Allow external memory as an argument to xTaskCreateStatic"
default y

View File

@ -69,6 +69,8 @@
#include "soc/keymng_reg.h"
#endif
#include "esp_private/rtc_clk.h"
#include "esp_private/esp_ldo_psram.h"
#include "esp_private/esp_mmu_map_private.h"
#if CONFIG_SPIRAM
#include "esp_psram.h"
@ -518,6 +520,14 @@ void IRAM_ATTR call_start_cpu0(void)
abort();
}
#endif
#if SOC_CLK_MPLL_SUPPORTED
#if SOC_PSRAM_VDD_POWER_MPLL
esp_ldo_vdd_psram_early_init();
#endif
rtc_clk_mpll_enable();
#endif
esp_mspi_pin_init();
// For Octal flash, it's hard to implement a read_id function in OPI mode for all vendors.
// So we have to read it here in SPI mode, before entering the OPI mode.

View File

@ -302,9 +302,7 @@ static inline __attribute__((always_inline)) void clk_ll_mpll_set_config(uint32_
// MPLL_Freq = XTAL_Freq * (div + 1) / (ref_div + 1)
uint8_t ref_div = 1;
uint8_t div = mpll_freq_mhz / 20 - 1;
uint32_t val = REGI2C_READ(I2C_MPLL, I2C_MPLL_DIV_REG_ADDR);
val |= ((div << 3) | ref_div);
uint8_t val = ((div << 3) | ref_div);
REGI2C_WRITE(I2C_MPLL, I2C_MPLL_DIV_REG_ADDR, val);
}

View File

@ -1295,6 +1295,10 @@ config SOC_PM_PAU_LINK_NUM
int
default 4
config SOC_PSRAM_VDD_POWER_MPLL
bool
default y
config SOC_CLK_RC_FAST_SUPPORT_CALIBRATION
bool
default n

View File

@ -558,6 +558,9 @@
#define SOC_PM_PAU_LINK_NUM (4)
/*-------------------------- PSRAM CAPS ----------------------------*/
#define SOC_PSRAM_VDD_POWER_MPLL (1)
/*-------------------------- CLOCK SUBSYSTEM CAPS ----------------------------------------*/
#define SOC_CLK_RC_FAST_SUPPORT_CALIBRATION (0)
#define SOC_MODEM_CLOCK_IS_INDEPENDENT (0)

View File

@ -32,8 +32,8 @@ Hardware
Some PSRAM chips are 1.8 V devices and some are 3.3 V. Consult the datasheet for your PSRAM chip and {IDF_TARGET_NAME} device to find out the working voltages.
By default PSRAM is powered up by the on-chip LDO2, you can use :ref:`CONFIG_SPIRAM_LDO_ID` to switch the LDO ID according. Setting this value to -1 for using external power supply.
By default PSRAM connected LDO is set to correct voltage according to the used Espressif module. You can still use :ref:`CONFIG_SPIRAM_LDO_VOLTAGE_MV` to select LDO output voltage if you do not use an Espressif module. When using external power supply, this option does not exist.
By default PSRAM is powered up by the on-chip LDO2, you can use :ref:`CONFIG_ESP_VDD_PSRAM_LDO_ID` to switch the LDO ID according. Setting this value to -1 for using external power supply, this means the on-chip LDO will not be used.
By default PSRAM connected LDO is set to correct voltage according to the used Espressif module. You can still use :ref:`CONFIG_ESP_VDD_PSRAM_LDO_VOLTAGE_MV` to select LDO output voltage if you do not use an Espressif module. When using external power supply, this option does not exist.
.. note::