@@ -2,7 +2,7 @@ use std::ops::Range;
22
33use super :: Esp32Params ;
44use crate :: {
5- chip:: { Chip , ChipType , ReadEFuse , SpiRegisters } ,
5+ chip:: { bytes_to_mac_addr , Chip , ChipType , ReadEFuse , SpiRegisters } ,
66 connection:: Connection ,
77 elf:: FirmwareImage ,
88 image_format:: { Esp32BootloaderFormat , ImageFormat , ImageFormatId } ,
@@ -54,6 +54,64 @@ impl ChipType for Esp32 {
5454 const SUPPORTED_TARGETS : & ' static [ & ' static str ] =
5555 & [ "xtensa-esp32-none-elf" , "xtensa-esp32-espidf" ] ;
5656
57+ fn chip_features ( & self , connection : & mut Connection ) -> Result < Vec < & str > , Error > {
58+ let word3 = self . read_efuse ( connection, 3 ) ?;
59+ let word4 = self . read_efuse ( connection, 4 ) ?;
60+ let word6 = self . read_efuse ( connection, 6 ) ?;
61+
62+ let mut features = vec ! [ "WiFi" ] ;
63+
64+ let chip_ver_dis_bt = word3 & 0x2 ;
65+ if chip_ver_dis_bt == 0 {
66+ features. push ( "BT" ) ;
67+ }
68+
69+ let chip_ver_dis_app_cpu = word3 & 0x1 ;
70+ if chip_ver_dis_app_cpu == 0 {
71+ features. push ( "Dual Core" ) ;
72+ } else {
73+ features. push ( "Single Core" ) ;
74+ }
75+
76+ let chip_cpu_freq_rated = word3 & ( 1 << 13 ) ;
77+ if chip_cpu_freq_rated != 0 {
78+ let chip_cpu_freq_low = word3 & ( 1 << 12 ) ;
79+ if chip_cpu_freq_low != 0 {
80+ features. push ( "160MHz" ) ;
81+ } else {
82+ features. push ( "240MHz" ) ;
83+ }
84+ }
85+
86+ let pkg_version = self . package_version ( connection) ?;
87+ if [ 2 , 4 , 5 , 6 ] . contains ( & pkg_version) {
88+ features. push ( "Embedded Flash" ) ;
89+ }
90+ if pkg_version == 6 {
91+ features. push ( "Embedded PSRAM" ) ;
92+ }
93+
94+ let adc_vref = ( word4 >> 8 ) & 0x1 ;
95+ if adc_vref != 0 {
96+ features. push ( "VRef calibration in efuse" ) ;
97+ }
98+
99+ let blk3_part_res = ( word3 >> 14 ) & 0x1 ;
100+ if blk3_part_res != 0 {
101+ features. push ( "BLK3 partially reserved" ) ;
102+ }
103+
104+ let coding_scheme = word6 & 0x3 ;
105+ features. push ( match coding_scheme {
106+ 0 => "Coding Scheme None" ,
107+ 1 => "Coding Scheme 3/4" ,
108+ 2 => "Coding Scheme Repeat (UNSUPPORTED)" ,
109+ _ => "Coding Scheme Invalid" ,
110+ } ) ;
111+
112+ Ok ( features)
113+ }
114+
57115 fn get_flash_segments < ' a > (
58116 image : & ' a FirmwareImage ,
59117 bootloader : Option < Vec < u8 > > ,
@@ -74,6 +132,17 @@ impl ChipType for Esp32 {
74132 }
75133 }
76134
135+ fn mac_address ( & self , connection : & mut Connection ) -> Result < String , Error > {
136+ let word1 = self . read_efuse ( connection, 1 ) ?;
137+ let word2 = self . read_efuse ( connection, 2 ) ?;
138+
139+ let words = ( ( word2 as u64 ) << 32 ) | word1 as u64 ;
140+ let bytes = words. to_be_bytes ( ) ;
141+ let bytes = & bytes[ 2 ..8 ] ;
142+
143+ Ok ( bytes_to_mac_addr ( bytes) )
144+ }
145+
77146 fn supports_target ( target : & str ) -> bool {
78147 target. starts_with ( "xtensa-esp32-" )
79148 }
@@ -103,6 +172,15 @@ impl Esp32 {
103172
104173 Ok ( revision)
105174 }
175+
176+ fn package_version ( & self , connection : & mut Connection ) -> Result < u32 , Error > {
177+ let word3 = self . read_efuse ( connection, 3 ) ?;
178+
179+ let pkg_version = ( word3 >> 9 ) & 0x7 ;
180+ let pkg_version = pkg_version + ( ( ( word3 >> 2 ) & 0x1 ) << 3 ) ;
181+
182+ Ok ( pkg_version)
183+ }
106184}
107185
108186#[ test]
0 commit comments