@@ -44,6 +44,7 @@ public enum ESPCommand : byte
4444 bool isStub = false ;
4545 bool isESP8266 = false ;
4646 bool isESP32S3 = false ;
47+ bool isESP32C3 = false ;
4748 string detectedChip = "ESP" ;
4849 byte [ ] _slipBuf = new byte [ 4096 ] ;
4950 public bool LegacyMode { get ; set ; } = false ;
@@ -291,7 +292,7 @@ uint RunSpiFlashCmd(byte cmd, int readBits = 0)
291292 mosiDlenOffs = 0 ; // not used for ESP8266
292293 misoDlenOffs = 0 ; // not used for ESP8266
293294 }
294- else if ( isESP32S3 )
295+ else if ( isESP32S3 || isESP32C3 )
295296 {
296297 baseAddr = ESP32S3_SPI_REG_BASE ;
297298 w0Offs = ESP32S3_SPI_W0_OFFS ;
@@ -480,7 +481,7 @@ public bool UploadStub()
480481 try
481482 {
482483 // Load chip-specific stub from embedded resource
483- string stubName = isESP8266 ? "ESP8266_Stub" : isESP32S3 ? "ESP32S3_Stub" : "ESP32_Stub" ;
484+ string stubName = isESP8266 ? "ESP8266_Stub" : isESP32S3 ? "ESP32S3_Stub" : isESP32C3 ? "ESP32C3_Stub" : "ESP32_Stub" ;
484485 string jsonContent = FLoaders . GetStringFromAssembly ( stubName ) ;
485486 addLogLine ( $ "Loaded stub: { stubName } ") ;
486487
@@ -914,7 +915,22 @@ public string ReadMac()
914915 mac = new byte [ ] { oui0 , oui1 , oui2 ,
915916 ( byte ) ( ( mac1 >> 8 ) & 0xFF ) , ( byte ) ( mac1 & 0xFF ) , ( byte ) ( ( mac0 >> 24 ) & 0xFF ) } ;
916917 }
917- else if ( isESP32S3 )
918+ else if ( isESP32C3 )
919+ {
920+ // ESP32-C3: EFUSE_BASE=0x60008800, MAC_EFUSE_REG=EFUSE_BASE+0x044
921+ uint mac0 = ReadReg ( 0x60008844 ) ;
922+ uint mac1 = ReadReg ( 0x60008848 ) ;
923+
924+ // esptool: struct.pack(">II", mac1, mac0)[2:] → 6 bytes big-endian
925+ mac = new byte [ 6 ] ;
926+ mac [ 0 ] = ( byte ) ( ( mac1 >> 8 ) & 0xFF ) ;
927+ mac [ 1 ] = ( byte ) ( ( mac1 >> 0 ) & 0xFF ) ;
928+ mac [ 2 ] = ( byte ) ( ( mac0 >> 24 ) & 0xFF ) ;
929+ mac [ 3 ] = ( byte ) ( ( mac0 >> 16 ) & 0xFF ) ;
930+ mac [ 4 ] = ( byte ) ( ( mac0 >> 8 ) & 0xFF ) ;
931+ mac [ 5 ] = ( byte ) ( ( mac0 >> 0 ) & 0xFF ) ;
932+ }
933+ else if ( isESP32S3 )
918934 {
919935 // ESP32-S3: EFUSE_BASE=0x60007000, MAC_EFUSE_REG=EFUSE_BASE+0x044
920936 uint mac0 = ReadReg ( 0x60007044 ) ;
@@ -975,25 +991,43 @@ public bool Connect()
975991
976992 if ( Sync ( ) )
977993 {
978- // Detect chip type from magic register / security info
994+ // Always use user-selected chipType for flags
995+ switch ( chipType )
996+ {
997+ case BKType . ESP32C3 :
998+ detectedChip = "ESP32-C3" ;
999+ isESP32C3 = true ;
1000+ break ;
1001+ case BKType . ESP32S3 :
1002+ detectedChip = "ESP32-S3" ;
1003+ isESP32S3 = true ;
1004+ break ;
1005+ case BKType . ESP8266 :
1006+ detectedChip = "ESP8266" ;
1007+ isESP8266 = true ;
1008+ break ;
1009+ case BKType . ESP32 :
1010+ detectedChip = "ESP32" ;
1011+ break ;
1012+ default :
1013+ detectedChip = chipType . ToString ( ) ;
1014+ break ;
1015+ }
1016+
1017+ // Try auto-detect and warn if it disagrees with user selection
9791018 uint ? chipMagic = GetChipId ( ) ;
9801019 if ( chipMagic . HasValue )
9811020 {
982- // Check if this is a chip ID from GET_SECURITY_INFO (small values)
1021+ string autoName = null ;
9831022 if ( ChipIDs . ContainsKey ( chipMagic . Value ) )
984- {
985- detectedChip = ChipIDs [ chipMagic . Value ] ;
986- isESP32S3 = ( chipMagic . Value == 9 ) ;
987- }
1023+ autoName = ChipIDs [ chipMagic . Value ] ;
9881024 else if ( ChipMagicValues . ContainsKey ( chipMagic . Value ) )
989- {
990- detectedChip = ChipMagicValues [ chipMagic . Value ] ;
991- }
992- else
993- {
994- detectedChip = $ "Unknown(0x{ chipMagic . Value : X} )";
995- }
996- isESP8266 = ( chipMagic . Value == 0xFFF0C101 ) ;
1025+ autoName = ChipMagicValues [ chipMagic . Value ] ;
1026+
1027+ if ( autoName != null && autoName != detectedChip )
1028+ addWarningLine ( $ "Warning: auto-detected chip is { autoName } , but user selected { detectedChip } ") ;
1029+ else if ( autoName != null )
1030+ addLogLine ( $ "Auto-detect confirmed: { autoName } ") ;
9971031 }
9981032
9991033 logger . setState ( $ "{ detectedChip } synced", Color . LightGreen ) ;
0 commit comments