Skip to content

Commit 277f26e

Browse files
committed
ci: Add overclock and watchdog tests
This commit adds test for overclock and watchdog. The tests are executed only on ESP32-C3 as there would have to be a different register value for each chip.
1 parent eacc94a commit 277f26e

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

test/test_esptool.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,90 @@ def test_flash_not_aligned_nostub(self):
677677
)
678678
assert "Hard resetting via RTS pin..." in output
679679

680+
@pytest.mark.skipif(arg_preload_port is False, reason="USB-JTAG/Serial only")
681+
@pytest.mark.skipif(arg_chip != "esp32c3", reason="ESP32-C3 only")
682+
def test_flash_overclocked(self):
683+
SYSTEM_BASE_REG = 0x600C0000
684+
SYSTEM_CPU_PER_CONF_REG = SYSTEM_BASE_REG + 0x008
685+
SYSTEM_CPUPERIOD_SEL_S = 0
686+
SYSTEM_CPUPERIOD_MAX = 1 # CPU_CLK frequency is 160 MHz
687+
688+
SYSTEM_SYSCLK_CONF_REG = SYSTEM_BASE_REG + 0x058
689+
SYSTEM_SOC_CLK_SEL_S = 10
690+
SYSTEM_SOC_CLK_MAX = 1
691+
692+
output = self.run_esptool(
693+
"--after no_reset_stub write_flash 0x0 images/one_mb.bin", preload=False
694+
)
695+
faster = re.search(r"(\d+(\.\d+)?)\s+seconds", output)
696+
assert faster, "Duration summary not found in the output"
697+
698+
with esptool.cmds.detect_chip(
699+
port=arg_port, connect_mode="no_reset"
700+
) as reg_mod:
701+
reg_mod.write_reg(
702+
SYSTEM_SYSCLK_CONF_REG,
703+
0,
704+
mask=(SYSTEM_SOC_CLK_MAX << SYSTEM_SOC_CLK_SEL_S),
705+
)
706+
sleep(0.1)
707+
reg_mod.write_reg(
708+
SYSTEM_CPU_PER_CONF_REG,
709+
0,
710+
mask=(SYSTEM_CPUPERIOD_MAX << SYSTEM_CPUPERIOD_SEL_S),
711+
)
712+
713+
output = self.run_esptool(
714+
"--before no_reset write_flash 0x0 images/one_mb.bin", preload=False
715+
)
716+
slower = re.search(r"(\d+(\.\d+)?)\s+seconds", output)
717+
assert slower, "Duration summary not found in the output"
718+
assert (
719+
float(slower.group(1)) - float(faster.group(1)) > 1
720+
), "Overclocking failed"
721+
722+
@pytest.mark.skipif(arg_preload_port is False, reason="USB-JTAG/Serial only")
723+
@pytest.mark.skipif(arg_chip != "esp32c3", reason="ESP32-C3 only")
724+
def test_flash_watchdogs(self):
725+
RTC_WDT_ENABLE = 0xC927FA00 # Valid only for ESP32-C3
726+
727+
with esptool.cmds.detect_chip(port=arg_port) as reg_mod:
728+
# Enable RTC WDT
729+
reg_mod.write_reg(
730+
reg_mod.RTC_CNTL_WDTWPROTECT_REG, reg_mod.RTC_CNTL_WDT_WKEY
731+
)
732+
reg_mod.write_reg(reg_mod.RTC_CNTL_WDTCONFIG0_REG, RTC_WDT_ENABLE)
733+
reg_mod.write_reg(reg_mod.RTC_CNTL_WDTWPROTECT_REG, 0)
734+
735+
# Disable automatic feeding of SWD
736+
reg_mod.write_reg(
737+
reg_mod.RTC_CNTL_SWD_WPROTECT_REG, reg_mod.RTC_CNTL_SWD_WKEY
738+
)
739+
reg_mod.write_reg(
740+
reg_mod.RTC_CNTL_SWD_CONF_REG, 0, mask=reg_mod.RTC_CNTL_SWD_AUTO_FEED_EN
741+
)
742+
reg_mod.write_reg(reg_mod.RTC_CNTL_SWD_WPROTECT_REG, 0)
743+
744+
reg_mod.sync_stub_detected = False
745+
reg_mod.run_stub()
746+
747+
output = self.run_esptool(
748+
"--before no_reset --after no_reset_stub flash_id", preload=False
749+
)
750+
assert "Stub is already running. No upload is necessary." in output
751+
752+
time.sleep(10) # Wait if RTC WDT triggers
753+
754+
with esptool.cmds.detect_chip(
755+
port=arg_port, connect_mode="no_reset"
756+
) as reg_mod:
757+
output = reg_mod.read_reg(reg_mod.RTC_CNTL_WDTCONFIG0_REG)
758+
assert output == 0, "RTC WDT is not disabled"
759+
760+
output = reg_mod.read_reg(reg_mod.RTC_CNTL_SWD_CONF_REG)
761+
print(f"RTC_CNTL_SWD_CONF_REG: {output}")
762+
assert output & 0x80000000, "SWD auto feeding is not disabled"
763+
680764

681765
@pytest.mark.skipif(
682766
arg_chip in ["esp8266", "esp32"],

0 commit comments

Comments
 (0)