Skip to content

Commit ca94040

Browse files
sylvioalvesnashif
authored andcommitted
soc: esp32: add reboot call
Add ESP32 reset function Signed-off-by: Sylvio Alves <[email protected]>
1 parent 72998f0 commit ca94040

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

soc/xtensa/esp32/linker.ld

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ PROVIDE ( gpio_output_set = 0x40009b24 );
3636
PROVIDE ( gpio_output_set_high = 0x40009b5c );
3737
PROVIDE ( roundup2 = 0x4000ab7c );
3838
PROVIDE ( crc32_le = 0x4005cfec );
39+
PROVIDE ( Cache_Read_Disable_rom = 0x40009ab8 );
40+
PROVIDE ( Cache_Read_Enable_rom = 0x40009a84 );
41+
PROVIDE ( Cache_Read_Init_rom = 0x40009950 );
3942

4043
PROVIDE ( esp32_rom_uart_tx_one_char = 0x40009200 );
4144
PROVIDE ( esp32_rom_uart_rx_one_char = 0x400092d0 );

soc/xtensa/esp32/soc.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
#include <toolchain/gcc.h>
1717
#include <zephyr/types.h>
1818

19+
#include "esp_private/system_internal.h"
20+
#include "esp32/rom/cache.h"
21+
#include "hal/soc_ll.h"
22+
#include "soc/cpu.h"
23+
#include "soc/gpio_periph.h"
24+
1925
extern void z_cstart(void);
2026

2127
/*
@@ -104,3 +110,76 @@ int arch_printk_char_out(int c)
104110
esp32_rom_uart_tx_one_char(c);
105111
return 0;
106112
}
113+
114+
void sys_arch_reboot(int type)
115+
{
116+
esp_restart_noos();
117+
}
118+
119+
void IRAM_ATTR esp_restart_noos(void)
120+
{
121+
/* Disable interrupts */
122+
z_xt_ints_off(0xFFFFFFFF);
123+
124+
const uint32_t core_id = cpu_hal_get_core_id();
125+
const uint32_t other_core_id = (core_id == 0) ? 1 : 0;
126+
127+
soc_ll_reset_core(other_core_id);
128+
soc_ll_stall_core(other_core_id);
129+
130+
/* Flush any data left in UART FIFOs */
131+
esp32_rom_uart_tx_wait_idle(0);
132+
esp32_rom_uart_tx_wait_idle(1);
133+
esp32_rom_uart_tx_wait_idle(2);
134+
135+
/* Disable cache */
136+
Cache_Read_Disable(0);
137+
Cache_Read_Disable(1);
138+
139+
/* 2nd stage bootloader reconfigures SPI flash signals. */
140+
/* Reset them to the defaults expected by ROM */
141+
WRITE_PERI_REG(GPIO_FUNC0_IN_SEL_CFG_REG, 0x30);
142+
WRITE_PERI_REG(GPIO_FUNC1_IN_SEL_CFG_REG, 0x30);
143+
WRITE_PERI_REG(GPIO_FUNC2_IN_SEL_CFG_REG, 0x30);
144+
WRITE_PERI_REG(GPIO_FUNC3_IN_SEL_CFG_REG, 0x30);
145+
WRITE_PERI_REG(GPIO_FUNC4_IN_SEL_CFG_REG, 0x30);
146+
WRITE_PERI_REG(GPIO_FUNC5_IN_SEL_CFG_REG, 0x30);
147+
148+
/* Reset wifi/bluetooth/ethernet/sdio (bb/mac) */
149+
DPORT_SET_PERI_REG_MASK(DPORT_CORE_RST_EN_REG,
150+
DPORT_BB_RST | DPORT_FE_RST | DPORT_MAC_RST |
151+
DPORT_BT_RST | DPORT_BTMAC_RST |
152+
DPORT_SDIO_RST | DPORT_SDIO_HOST_RST |
153+
DPORT_EMAC_RST | DPORT_MACPWR_RST |
154+
DPORT_RW_BTMAC_RST | DPORT_RW_BTLP_RST);
155+
DPORT_REG_WRITE(DPORT_CORE_RST_EN_REG, 0);
156+
157+
/* Reset timer/spi/uart */
158+
DPORT_SET_PERI_REG_MASK(
159+
DPORT_PERIP_RST_EN_REG,
160+
/* UART TX FIFO cannot be reset correctly on ESP32, */
161+
/* so reset the UART memory by DPORT here. */
162+
DPORT_TIMERS_RST | DPORT_SPI01_RST | DPORT_UART_RST |
163+
DPORT_UART1_RST | DPORT_UART2_RST | DPORT_UART_MEM_RST);
164+
DPORT_REG_WRITE(DPORT_PERIP_RST_EN_REG, 0);
165+
166+
/* Clear entry point for APP CPU */
167+
DPORT_REG_WRITE(DPORT_APPCPU_CTRL_D_REG, 0);
168+
169+
/* Reset CPUs */
170+
if (core_id == 0) {
171+
/* Running on PRO CPU: APP CPU is stalled. Can reset both CPUs. */
172+
soc_ll_reset_core(1);
173+
soc_ll_reset_core(0);
174+
} else {
175+
/* Running on APP CPU: need to reset PRO CPU and unstall it, */
176+
/* then reset APP CPU */
177+
soc_ll_reset_core(0);
178+
soc_ll_stall_core(0);
179+
soc_ll_reset_core(1);
180+
}
181+
182+
while (true) {
183+
;
184+
}
185+
}

0 commit comments

Comments
 (0)