Skip to content
This repository has been archived by the owner on Jul 20, 2022. It is now read-only.

Commit

Permalink
Fix chip detection for ESP8266 (#27)
Browse files Browse the repository at this point in the history
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
  • Loading branch information
conradopoole and balloob committed Jun 23, 2021
1 parent e0114be commit 7eb9cdf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export type ChipFamily =
| typeof CHIP_FAMILY_ESP32H2;

export const CHIP_DETECT_MAGIC_VALUES = {
0xfff0c101: { name: "ESP8266", family: CHIP_FAMILY_ESP8266 },
[-999167]: { name: "ESP8266", family: CHIP_FAMILY_ESP8266 },
0x00f01d83: { name: "ESP32", family: CHIP_FAMILY_ESP32 },
0x000007c6: { name: "ESP32-S2", family: CHIP_FAMILY_ESP32S2 },
0x9: { name: "ESP32-S3", family: CHIP_FAMILY_ESP32S3 },
Expand Down
13 changes: 10 additions & 3 deletions src/esp_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ export class ESPLoader extends EventTarget {
let chipMagicValue = await this.readRegister(CHIP_DETECT_MAGIC_REG_ADDR);
let chip = CHIP_DETECT_MAGIC_VALUES[chipMagicValue];
if (chip === undefined) {
throw new Error(`Unknown Chip: ${toHex(chipMagicValue)}`);
throw new Error(
`Unknown Chip: Hex: ${toHex(
chipMagicValue,
8
).toLowerCase()} Number: ${chipMagicValue}`
);
}
this.chipName = chip.name;
this.chipFamily = chip.family;
Expand Down Expand Up @@ -829,8 +834,10 @@ export class ESPLoader extends EventTarget {

this.logger.log("Image being flashed is a bootloader");

let flashMode = FLASH_MODES["dio"]; // For now we always select dio, a common value supported by many flash chips and ESP boards
let flashFreq = FLASH_FREQUENCIES["80m"]; // For now we always select 40m, a common value supported by many flash chips and ESP boards
// For now we always select dio, a common value supported by many flash chips and ESP boards
let flashMode = FLASH_MODES["dio"];
// For now we always select 40m, a common value supported by many flash chips and ESP boards
let flashFreq = FLASH_FREQUENCIES["40m"];
let flashSize = getFlashSizes(this.getChipFamily())[
this.flashSize ? this.flashSize : "4MB"
]; // If size was autodetected we use it otherwise we default to 4MB
Expand Down
7 changes: 6 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ export const unpack = (format: string, bytes: number[]) => {
};

export const toHex = (value: number, size = 2) => {
return "0x" + value.toString(16).toUpperCase().padStart(size, "0");
let hex = value.toString(16).toUpperCase();
if (hex.startsWith("-")) {
return "-0x" + hex.substring(1).padStart(size, "0");
} else {
return "0x" + hex.padStart(size, "0");
}
};

export const sleep = (ms: number) =>
Expand Down

0 comments on commit 7eb9cdf

Please sign in to comment.