Skip to content

Commit 3077627

Browse files
mythbuster5radimkarnis
authored andcommitted
feat: Add new target esp32s31
1 parent d7f1adf commit 3077627

File tree

11 files changed

+1354
-0
lines changed

11 files changed

+1354
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from . import operations
2+
from .emulate_efuse_controller import EmulateEfuseController
3+
from .fields import EspEfuses
4+
5+
commands = operations.ESP32S31Commands
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# This file describes eFuses controller for ESP32-S31 chip
2+
#
3+
# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
4+
#
5+
# SPDX-License-Identifier: GPL-2.0-or-later
6+
7+
import reedsolo
8+
9+
from .mem_definition import EfuseDefineBlocks, EfuseDefineFields, EfuseDefineRegisters
10+
from ..emulate_efuse_controller_base import EmulateEfuseControllerBase, FatalError
11+
12+
13+
class EmulateEfuseController(EmulateEfuseControllerBase):
14+
"""The class for virtual efuse operation. Using for HOST_TEST."""
15+
16+
CHIP_NAME = "ESP32-S31"
17+
mem = None
18+
debug = False
19+
20+
def __init__(self, efuse_file=None, debug=False):
21+
self.Blocks = EfuseDefineBlocks
22+
self.Fields = EfuseDefineFields(None)
23+
self.REGS = EfuseDefineRegisters
24+
super().__init__(efuse_file, debug)
25+
self.write_reg(self.REGS.EFUSE_CMD_REG, 0)
26+
27+
""" esptool method start >>"""
28+
29+
def get_major_chip_version(self):
30+
return 0
31+
32+
def get_minor_chip_version(self):
33+
return 0
34+
35+
def get_crystal_freq(self):
36+
return 40 # MHz
37+
38+
def get_security_info(self):
39+
return {
40+
"flags": 0,
41+
"flash_crypt_cnt": 0,
42+
"key_purposes": 0,
43+
"chip_id": 0,
44+
"api_version": 0,
45+
}
46+
47+
""" << esptool method end """
48+
49+
def handle_writing_event(self, addr, value):
50+
if addr == self.REGS.EFUSE_CMD_REG:
51+
if value & self.REGS.EFUSE_PGM_CMD:
52+
self.copy_blocks_wr_regs_to_rd_regs(updated_block=(value >> 2) & 0xF)
53+
self.clean_blocks_wr_regs()
54+
self.check_rd_protection_area()
55+
self.write_reg(addr, 0)
56+
self.write_reg(self.REGS.EFUSE_CMD_REG, 0)
57+
elif value == self.REGS.EFUSE_READ_CMD:
58+
self.write_reg(addr, 0)
59+
self.write_reg(self.REGS.EFUSE_CMD_REG, 0)
60+
self.save_to_file()
61+
62+
def get_bitlen_of_block(self, blk, wr=False):
63+
if blk.id == 0:
64+
if wr:
65+
return 32 * 8
66+
else:
67+
return 32 * blk.len
68+
else:
69+
if wr:
70+
rs_coding = 32 * 3
71+
return 32 * 8 + rs_coding
72+
else:
73+
return 32 * blk.len
74+
75+
def handle_coding_scheme(self, blk, data):
76+
if blk.id != 0:
77+
# CODING_SCHEME RS applied only for all blocks except BLK0.
78+
coded_bytes = 12
79+
data.pos = coded_bytes * 8
80+
plain_data = data.readlist("32*uint:8")[::-1]
81+
# takes 32 bytes
82+
# apply RS encoding
83+
rs = reedsolo.RSCodec(coded_bytes)
84+
# 32 byte of data + 12 bytes RS
85+
calc_encoded_data = list(rs.encode([x for x in plain_data]))
86+
data.pos = 0
87+
if calc_encoded_data != data.readlist("44*uint:8")[::-1]:
88+
raise FatalError("Error in coding scheme data")
89+
data = data[coded_bytes * 8 :]
90+
if blk.len < 8:
91+
data = data[(8 - blk.len) * 32 :]
92+
return data

0 commit comments

Comments
 (0)