Skip to content

Commit fe0f137

Browse files
committed
cpu/esp32/startup: migration to ESP-IDF v5.4
1 parent ac42810 commit fe0f137

1 file changed

Lines changed: 36 additions & 14 deletions

File tree

cpu/esp32/startup.c

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,25 @@
4242
#include "periph/init.h"
4343
#include "periph/rtc.h"
4444

45+
#include "esp_idf_api/uart.h"
46+
4547
/* ESP-IDF headers */
46-
#include "driver/periph_ctrl.h"
4748
#include "esp_attr.h"
4849
#include "esp_clk_internal.h"
4950
#include "esp_heap_caps_init.h"
5051
#include "esp_log.h"
5152
#include "esp_private/startup_internal.h"
5253
#include "esp_private/esp_clk.h"
53-
#include "esp_rom_uart.h"
5454
#include "esp_sleep.h"
5555
#include "esp_timer.h"
56-
#include "hal/interrupt_controller_types.h"
57-
#include "hal/interrupt_controller_ll.h"
5856
#include "rom/cache.h"
5957
#include "rom/ets_sys.h"
6058
#include "rom/rtc.h"
6159
#include "rom/uart.h"
62-
#include "soc/apb_ctrl_reg.h"
63-
#include "soc/cpu.h"
6460
#include "soc/rtc.h"
6561
#include "soc/rtc_cntl_reg.h"
6662
#include "soc/rtc_cntl_struct.h"
63+
#include "soc/syscon_reg.h"
6764
#include "soc/timer_group_struct.h"
6865

6966
#if __xtensa__
@@ -73,8 +70,13 @@
7370
#include "xtensa/xtensa_api.h"
7471
#endif
7572

73+
#if IS_USED(MODULE_ESP_IDF_SPI_FLASH)
74+
#include "esp_private/spi_flash_os.h"
75+
#include "esp_flash_internal.h"
76+
#endif
77+
7678
#if IS_USED(MODULE_ESP_SPI_RAM)
77-
#include "spiram.h"
79+
#include "esp_private/esp_psram_extram.h"
7880
#endif
7981

8082
#if IS_USED(MODULE_PUF_SRAM)
@@ -134,6 +136,7 @@ esp_err_t esp_timer_impl_early_init(void)
134136
* This function is the entry point in the user application. It is called
135137
* after a CPU initialization to startup the system.
136138
*/
139+
137140
static NORETURN void IRAM system_startup_cpu0(void)
138141
{
139142
#if __xtensa__
@@ -150,6 +153,7 @@ static NORETURN void IRAM system_startup_cpu0(void)
150153
#if IS_USED(MODULE_ESP_IDF_HEAP)
151154
/* init heap */
152155
heap_caps_init();
156+
heap_caps_enable_nonos_stack_heaps();
153157
if (IS_ACTIVE(ENABLE_DEBUG)) {
154158
ets_printf("Heap free: %u byte\n", get_free_heap_size());
155159
}
@@ -163,7 +167,7 @@ static NORETURN void IRAM system_startup_cpu0(void)
163167
uart_system_init();
164168

165169
/* initialize stdio */
166-
esp_rom_uart_tx_wait_idle(CONFIG_ESP_CONSOLE_UART_NUM);
170+
esp_idf_esp_rom_output_tx_wait_idle(CONFIG_ESP_CONSOLE_UART_NUM);
167171
early_init();
168172

169173
RESET_REASON reset_reason = rtc_get_reset_reason(PRO_CPU_NUM);
@@ -250,9 +254,11 @@ static NORETURN void IRAM system_init (void)
250254
srand(hwrand());
251255

252256
/* add SPI RAM to heap if enabled */
253-
#if CONFIG_SPIRAM_SUPPORT && CONFIG_SPIRAM_BOOT_INIT
254-
esp_spiram_init_cache();
255-
esp_spiram_add_to_heapalloc();
257+
#if CONFIG_SPIRAM && CONFIG_SPIRAM_BOOT_INIT
258+
esp_psram_extram_add_to_heap_allocator();
259+
#if CONFIG_SPIRAM_USE_MALLOC
260+
heap_caps_malloc_extmem_enable(CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL);
261+
#endif
256262
#endif
257263

258264
/* print some infos */
@@ -310,8 +316,8 @@ static NORETURN void IRAM system_init (void)
310316
intr_matrix_set(PRO_CPU_NUM, ETS_FROM_CPU_INTR0_SOURCE, CPU_INUM_SOFTWARE);
311317
#endif
312318
/* set thread yield handler and enable the software interrupt */
313-
intr_cntrl_ll_set_int_handler(CPU_INUM_SOFTWARE, thread_yield_isr, NULL);
314-
intr_cntrl_ll_enable_interrupts(BIT(CPU_INUM_SOFTWARE));
319+
esp_cpu_intr_set_handler(CPU_INUM_SOFTWARE, thread_yield_isr, NULL);
320+
esp_cpu_intr_enable(BIT(CPU_INUM_SOFTWARE));
315321

316322
/* initialize ESP system event loop */
317323
extern void esp_event_handler_init(void);
@@ -320,13 +326,29 @@ static NORETURN void IRAM system_init (void)
320326
/* initialize ESP-IDF timer task */
321327
esp_timer_init();
322328

329+
#if IS_USED(MODULE_ESP_IDF_SPI_FLASH)
330+
#if CONFIG_SPI_FLASH_ROM_IMPL
331+
spi_flash_rom_impl_init();
332+
#endif
333+
334+
extern void spi_flash_init_lock(void);
335+
336+
spi_flash_init_lock();
337+
spi_flash_guard_set(&g_flash_guard_default_ops);
338+
339+
esp_err_t flash_ret = esp_flash_init_default_chip();
340+
(void)flash_ret;
341+
assert(flash_ret == ESP_OK);
342+
#endif /* MODULE_ESP_IDF_SPI_FLASH */
343+
323344
/* starting RIOT */
324345
#if IS_USED(MODULE_ESP_LOG_STARTUP)
325346
LOG_STARTUP("Starting RIOT kernel on PRO cpu\n");
326-
esp_rom_uart_tx_wait_idle(CONFIG_ESP_CONSOLE_UART_NUM);
347+
esp_idf_esp_rom_output_tx_wait_idle(CONFIG_ESP_CONSOLE_UART_NUM);
327348
#else
328349
ets_printf("\n");
329350
#endif
351+
330352
kernel_init();
331353
UNREACHABLE();
332354
}

0 commit comments

Comments
 (0)