Skip to content

Commit 82e5fe8

Browse files
TD-erme-no-dev
andauthored
Add platform specific flash speed to magicFlashChipSpeed (#8864)
Various ESP32-variants like the C6, H2, etc. differ in their used flash frequencies. Also the maximum possible flash size wasn't handled in `magicFlashChipSize` Co-authored-by: Me No Dev <[email protected]>
1 parent 3daa302 commit 82e5fe8

File tree

1 file changed

+91
-20
lines changed

1 file changed

+91
-20
lines changed

Diff for: cores/esp32/Esp.cpp

+91-20
Original file line numberDiff line numberDiff line change
@@ -391,38 +391,109 @@ FlashMode_t EspClass::getFlashChipMode(void)
391391

392392
uint32_t EspClass::magicFlashChipSize(uint8_t byte)
393393
{
394+
/*
395+
FLASH_SIZES = {
396+
"1MB": 0x00,
397+
"2MB": 0x10,
398+
"4MB": 0x20,
399+
"8MB": 0x30,
400+
"16MB": 0x40,
401+
"32MB": 0x50,
402+
"64MB": 0x60,
403+
"128MB": 0x70,
404+
}
405+
*/
394406
switch(byte & 0x0F) {
395-
case 0x0: // 8 MBit (1MB)
396-
return (1_MB);
397-
case 0x1: // 16 MBit (2MB)
398-
return (2_MB);
399-
case 0x2: // 32 MBit (4MB)
400-
return (4_MB);
401-
case 0x3: // 64 MBit (8MB)
402-
return (8_MB);
403-
case 0x4: // 128 MBit (16MB)
404-
return (16_MB);
405-
default: // fail?
407+
case 0x0: return (1_MB); // 8 MBit (1MB)
408+
case 0x1: return (2_MB); // 16 MBit (2MB)
409+
case 0x2: return (4_MB); // 32 MBit (4MB)
410+
case 0x3: return (8_MB); // 64 MBit (8MB)
411+
case 0x4: return (16_MB); // 128 MBit (16MB)
412+
case 0x5: return (32_MB); // 256 MBit (32MB)
413+
case 0x6: return (64_MB); // 512 MBit (64MB)
414+
case 0x7: return (128_MB); // 1 GBit (128MB)
415+
default: // fail?
406416
return 0;
407417
}
408418
}
409419

410420
uint32_t EspClass::magicFlashChipSpeed(uint8_t byte)
411421
{
422+
#if CONFIG_IDF_TARGET_ESP32C2
423+
/*
424+
FLASH_FREQUENCY = {
425+
"60m": 0xF,
426+
"30m": 0x0,
427+
"20m": 0x1,
428+
"15m": 0x2,
429+
}
430+
*/
431+
switch(byte & 0x0F) {
432+
case 0xF: return (60_MHz);
433+
case 0x0: return (30_MHz);
434+
case 0x1: return (20_MHz);
435+
case 0x2: return (15_MHz);
436+
default: // fail?
437+
return 0;
438+
}
439+
440+
441+
#elif CONFIG_IDF_TARGET_ESP32C6
442+
/*
443+
FLASH_FREQUENCY = {
444+
"80m": 0x0, # workaround for wrong mspi HS div value in ROM
445+
"40m": 0x0,
446+
"20m": 0x2,
447+
}
448+
*/
449+
switch(byte & 0x0F) {
450+
case 0x0: return (80_MHz);
451+
case 0x2: return (20_MHz);
452+
default: // fail?
453+
return 0;
454+
}
455+
456+
#elif CONFIG_IDF_TARGET_ESP32H2
457+
458+
/*
459+
FLASH_FREQUENCY = {
460+
"48m": 0xF,
461+
"24m": 0x0,
462+
"16m": 0x1,
463+
"12m": 0x2,
464+
}
465+
*/
412466
switch(byte & 0x0F) {
413-
case 0x0: // 40 MHz
414-
return (40_MHz);
415-
case 0x1: // 26 MHz
416-
return (26_MHz);
417-
case 0x2: // 20 MHz
418-
return (20_MHz);
419-
case 0xf: // 80 MHz
420-
return (80_MHz);
421-
default: // fail?
467+
case 0xF: return (48_MHz);
468+
case 0x0: return (24_MHz);
469+
case 0x1: return (16_MHz);
470+
case 0x2: return (12_MHz);
471+
default: // fail?
422472
return 0;
423473
}
474+
475+
476+
#else
477+
/*
478+
FLASH_FREQUENCY = {
479+
"80m": 0xF,
480+
"40m": 0x0,
481+
"26m": 0x1,
482+
"20m": 0x2,
483+
}
484+
*/
485+
switch(byte & 0x0F) {
486+
case 0xF: return (80_MHz);
487+
case 0x0: return (40_MHz);
488+
case 0x1: return (26_MHz);
489+
case 0x2: return (20_MHz);
490+
default: // fail?
491+
return 0;
492+
}
493+
#endif
424494
}
425495

496+
426497
FlashMode_t EspClass::magicFlashChipMode(uint8_t byte)
427498
{
428499
FlashMode_t mode = (FlashMode_t) byte;

0 commit comments

Comments
 (0)