Skip to content

Commit 8d75f0d

Browse files
committed
Merge branch 'fix/ram_loadable_app_p4' into 'master'
ram_app: fixed ram loadable app on p4 Closes IDF-8994 See merge request espressif/esp-idf!33312
2 parents 489ba7c + 6933ba3 commit 8d75f0d

File tree

10 files changed

+74
-19
lines changed

10 files changed

+74
-19
lines changed

components/bootloader_support/bootloader_flash/include/esp_private/bootloader_flash_internal.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
2-
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
#pragma once
77
#include <stdint.h>
88
#include <esp_err.h>
9+
#include "soc/soc_caps.h"
910

1011
#ifdef __cplusplus
1112
extern "C" {
@@ -27,6 +28,13 @@ esp_err_t bootloader_init_spi_flash(void);
2728
void bootloader_flash_hardware_init(void);
2829
#endif
2930

31+
#if SOC_MEMSPI_FLASH_PSRAM_INDEPENDENT
32+
/**
33+
* @brief Initialise flash core clock
34+
*/
35+
void bootloader_flash_init_core_clock(void);
36+
#endif //SOC_MEMSPI_FLASH_PSRAM_INDEPENDENT
37+
3038
#ifdef __cplusplus
3139
}
3240
#endif

components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32p4.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
#include "bootloader_init.h"
2020
#include "hal/mmu_hal.h"
2121
#include "hal/mmu_ll.h"
22+
#include "hal/spimem_flash_ll.h"
2223
#include "hal/cache_hal.h"
2324
#include "hal/cache_ll.h"
25+
#include "esp_private/bootloader_flash_internal.h"
2426

25-
void IRAM_ATTR bootloader_flash_update_id()
27+
void IRAM_ATTR bootloader_flash_update_id(void)
2628
{
2729
esp_rom_spiflash_chip_t *chip = &rom_spiflash_legacy_data->chip;
2830
chip->device_id = bootloader_read_flash_id();
@@ -33,15 +35,23 @@ void bootloader_flash_update_size(uint32_t size)
3335
rom_spiflash_legacy_data->chip.chip_size = size;
3436
}
3537

36-
void IRAM_ATTR bootloader_flash_cs_timing_config()
38+
void IRAM_ATTR bootloader_flash_cs_timing_config(void)
3739
{
3840
SET_PERI_REG_MASK(SPI_MEM_C_USER_REG, SPI_MEM_C_CS_HOLD_M | SPI_MEM_C_CS_SETUP_M);
3941
SET_PERI_REG_BITS(SPI_MEM_C_CTRL2_REG, SPI_MEM_C_CS_HOLD_TIME_V, 0, SPI_MEM_C_CS_HOLD_TIME_S);
4042
SET_PERI_REG_BITS(SPI_MEM_C_CTRL2_REG, SPI_MEM_C_CS_SETUP_TIME_V, 0, SPI_MEM_C_CS_SETUP_TIME_S);
4143
}
4244

45+
void IRAM_ATTR bootloader_flash_init_core_clock(void)
46+
{
47+
_spimem_flash_ll_select_clk_source(0, FLASH_CLK_SRC_SPLL);
48+
_spimem_ctrlr_ll_set_core_clock(0, 6);
49+
}
50+
4351
void IRAM_ATTR bootloader_flash_clock_config(const esp_image_header_t *pfhdr)
4452
{
53+
bootloader_flash_init_core_clock();
54+
4555
uint32_t spi_clk_div = 0;
4656
switch (pfhdr->spi_speed) {
4757
case ESP_IMAGE_SPI_SPEED_DIV_1:

components/bootloader_support/src/esp32p4/bootloader_esp32p4.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ static inline void bootloader_hardware_init(void)
109109
REGI2C_WRITE_MASK(I2C_BIAS, I2C_BIAS_DREG_1P1, 10);
110110
REGI2C_WRITE_MASK(I2C_BIAS, I2C_BIAS_DREG_1P1_PVT, 10);
111111

112+
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
112113
// IDF-10019 TODO: This is temporarily for ESP32P4-ECO0, please remove it when eco0 is not widly used.
113-
int __DECLARE_RCC_ATOMIC_ENV __attribute__ ((unused));
114114
if (likely(ESP_CHIP_REV_ABOVE(chip_version, 1))) {
115-
spimem_flash_ll_select_clk_source(0, FLASH_CLK_SRC_SPLL);
116-
spimem_ctrlr_ll_set_core_clock(0, 6);
115+
bootloader_flash_init_core_clock();
117116
}
117+
#endif
118118
}
119119

120120
static inline void bootloader_ana_reset_config(void)

components/hal/esp32p4/include/hal/spimem_flash_ll.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ static inline void spimem_flash_ll_set_dummy_out(spi_mem_dev_t *dev, uint32_t ou
734734
* @param clk_src clock source, see valid sources in type `soc_periph_flash_clk_src_t`
735735
*/
736736
__attribute__((always_inline))
737-
static inline void spimem_flash_ll_select_clk_source(uint32_t mspi_id, soc_periph_flash_clk_src_t clk_src)
737+
static inline void _spimem_flash_ll_select_clk_source(uint32_t mspi_id, soc_periph_flash_clk_src_t clk_src)
738738
{
739739
(void)mspi_id;
740740
uint32_t clk_val = 0;
@@ -759,7 +759,7 @@ static inline void spimem_flash_ll_select_clk_source(uint32_t mspi_id, soc_perip
759759

760760
/// use a macro to wrap the function, force the caller to use it in a critical section
761761
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
762-
#define spimem_flash_ll_select_clk_source(...) (void)__DECLARE_RCC_ATOMIC_ENV; spimem_flash_ll_select_clk_source(__VA_ARGS__)
762+
#define spimem_flash_ll_select_clk_source(...) (void)__DECLARE_RCC_ATOMIC_ENV; _spimem_flash_ll_select_clk_source(__VA_ARGS__)
763763

764764
/**
765765
* @brief Set FLASH core clock
@@ -768,7 +768,7 @@ static inline void spimem_flash_ll_select_clk_source(uint32_t mspi_id, soc_perip
768768
* @param freqdiv Divider value
769769
*/
770770
__attribute__((always_inline))
771-
static inline void spimem_ctrlr_ll_set_core_clock(uint8_t mspi_id, uint32_t freqdiv)
771+
static inline void _spimem_ctrlr_ll_set_core_clock(uint8_t mspi_id, uint32_t freqdiv)
772772
{
773773
(void)mspi_id;
774774
HP_SYS_CLKRST.peri_clk_ctrl00.reg_flash_core_clk_en = 1;
@@ -777,7 +777,7 @@ static inline void spimem_ctrlr_ll_set_core_clock(uint8_t mspi_id, uint32_t freq
777777

778778
/// use a macro to wrap the function, force the caller to use it in a critical section
779779
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
780-
#define spimem_ctrlr_ll_set_core_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; spimem_ctrlr_ll_set_core_clock(__VA_ARGS__)
780+
#define spimem_ctrlr_ll_set_core_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; _spimem_ctrlr_ll_set_core_clock(__VA_ARGS__)
781781

782782
/**
783783
* @brief Reset whole memory spi

components/soc/esp32p4/include/soc/Kconfig.soc_caps.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,10 @@ config SOC_MEMSPI_SRC_FREQ_20M_SUPPORTED
14711471
bool
14721472
default y
14731473

1474+
config SOC_MEMSPI_FLASH_PSRAM_INDEPENDENT
1475+
bool
1476+
default y
1477+
14741478
config SOC_SYSTIMER_COUNTER_NUM
14751479
int
14761480
default 2

components/soc/esp32p4/include/soc/soc_caps.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,8 @@
563563
#define SOC_MEMSPI_SRC_FREQ_40M_SUPPORTED 1
564564
#define SOC_MEMSPI_SRC_FREQ_20M_SUPPORTED 1
565565

566+
#define SOC_MEMSPI_FLASH_PSRAM_INDEPENDENT 1
567+
566568
/*-------------------------- SYSTIMER CAPS ----------------------------------*/
567569
#define SOC_SYSTIMER_COUNTER_NUM 2 // Number of counter units
568570
#define SOC_SYSTIMER_ALARM_NUM 3 // Number of alarm units

tools/ci/idf_pytest/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
'usj_device': 'Test usb_serial_jtag and usb_serial_jtag is used as serial only (not console)',
124124
'twai_std': 'twai runner with all twai supported targets connect to usb-can adapter',
125125
'lp_i2s': 'lp_i2s runner tested with hp_i2s',
126+
'ram_app': 'ram_app runners',
126127
}
127128

128129
DEFAULT_CONFIG_RULES_STR = ['sdkconfig.ci=default', 'sdkconfig.ci.*=', '=default']

tools/test_apps/system/.build-test-rules.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ tools/test_apps/system/ram_loadable_app:
8585
- if: IDF_TARGET == "esp32c5"
8686
temporary: true
8787
reason: not supported # TODO: [ESP32C5] IDF-8644, IDF-10315
88-
disable_test:
89-
- if: IDF_TARGET in ["esp32p4"]
90-
temporary: true
91-
reason: TBD # TODO: IDF-8994
9288

9389
tools/test_apps/system/rtc_mem_reserve:
9490
enable:

tools/test_apps/system/ram_loadable_app/pytest_ram_loadable_app.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,53 @@
44
from pytest_embedded_idf.dut import IdfDut
55

66

7-
@pytest.mark.temp_skip_ci(targets=['esp32p4', 'esp32c5'], reason='esp32p4, esp32c5 support TBD') # TODO: [ESP32P4] IDF-8994 [ESP32C5] IDF-8644, IDF-10315
8-
@pytest.mark.supported_targets
7+
@pytest.mark.temp_skip_ci(targets=['esp32c5'], reason='esp32c5 support TBD') # TODO: [ESP32C5] IDF-8644, IDF-10315
8+
@pytest.mark.esp32
9+
@pytest.mark.esp32s2
10+
@pytest.mark.esp32s3
11+
@pytest.mark.esp32c2
12+
@pytest.mark.esp32c3
13+
@pytest.mark.esp32c6
14+
@pytest.mark.esp32h2
15+
@pytest.mark.esp32c5
16+
@pytest.mark.esp32c61
917
@pytest.mark.generic
1018
@pytest.mark.parametrize('config', ['pure_ram',], indirect=True,)
1119
def test_pure_ram_loadable_app(dut: IdfDut) -> None:
1220
dut.expect('main_task: Calling app_main()', timeout=10)
1321
dut.expect('Time since boot: 3 seconds...', timeout=10)
1422

1523

16-
# TODO: [ESP32P4] IDF-8994 [ESP32C5] IDF-8644, IDF-10315, [ESP32C61] IDF-10951
17-
@pytest.mark.temp_skip_ci(targets=['esp32p4', 'esp32c5', 'esp32c61'], reason='support TBD')
18-
@pytest.mark.supported_targets
24+
# TODO: [ESP32C5] IDF-8644, IDF-10315, [ESP32C61] IDF-10951
25+
@pytest.mark.temp_skip_ci(targets=['esp32c5', 'esp32c61'], reason='support TBD')
26+
@pytest.mark.esp32
27+
@pytest.mark.esp32s2
28+
@pytest.mark.esp32s3
29+
@pytest.mark.esp32c2
30+
@pytest.mark.esp32c3
31+
@pytest.mark.esp32c6
32+
@pytest.mark.esp32h2
33+
@pytest.mark.esp32c5
34+
@pytest.mark.esp32c61
1935
@pytest.mark.generic
2036
@pytest.mark.parametrize('config', ['defaults',], indirect=True,)
2137
def test_ram_loadable_app(dut: IdfDut) -> None:
2238
dut.expect('spi_flash: detected chip', timeout=10)
2339
dut.expect('Time since boot: 3 seconds...', timeout=30)
40+
41+
42+
# Tests with ram_app runners
43+
@pytest.mark.esp32p4
44+
@pytest.mark.ram_app
45+
@pytest.mark.parametrize('config', ['defaults',], indirect=True,)
46+
def test_ram_loadable_app_with_ram_app_runner(dut: IdfDut) -> None:
47+
dut.expect('spi_flash: detected chip', timeout=10)
48+
dut.expect('Time since boot: 3 seconds...', timeout=30)
49+
50+
51+
@pytest.mark.esp32p4
52+
@pytest.mark.ram_app
53+
@pytest.mark.parametrize('config', ['pure_ram',], indirect=True,)
54+
def test_pure_ram_loadable_app_with_ram_app_runner(dut: IdfDut) -> None:
55+
dut.expect('main_task: Calling app_main()', timeout=10)
56+
dut.expect('Time since boot: 3 seconds...', timeout=10)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y

0 commit comments

Comments
 (0)