-
Notifications
You must be signed in to change notification settings - Fork 7.7k
getFlashFrequencyMHz #11898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getFlashFrequencyMHz #11898
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -9,13 +9,15 @@ | |||||
#include "soc/efuse_reg.h" | ||||||
#include "soc/rtc.h" | ||||||
#include "soc/spi_reg.h" | ||||||
#include "soc/soc.h" | ||||||
#if CONFIG_IDF_TARGET_ESP32S2 | ||||||
#include "esp32s2/rom/spi_flash.h" | ||||||
#endif | ||||||
#include "esp_bit_defs.h" | ||||||
|
||||||
#include "Arduino.h" | ||||||
#include "esp32-hal-periman.h" | ||||||
#include "chip-debug-report.h" | ||||||
|
||||||
#define chip_report_printf log_printf | ||||||
|
||||||
|
@@ -138,25 +140,19 @@ static void printFlashInfo(void) { | |||||
chip_report_printf(" Block Size : %8lu B (%6.1f KB)\n", g_rom_flashchip.block_size, b2kb(g_rom_flashchip.block_size)); | ||||||
chip_report_printf(" Sector Size : %8lu B (%6.1f KB)\n", g_rom_flashchip.sector_size, b2kb(g_rom_flashchip.sector_size)); | ||||||
chip_report_printf(" Page Size : %8lu B (%6.1f KB)\n", g_rom_flashchip.page_size, b2kb(g_rom_flashchip.page_size)); | ||||||
esp_image_header_t fhdr; | ||||||
esp_flash_read(esp_flash_default_chip, (void *)&fhdr, ESP_FLASH_IMAGE_BASE, sizeof(esp_image_header_t)); | ||||||
if (fhdr.magic == ESP_IMAGE_HEADER_MAGIC) { | ||||||
uint32_t f_freq = 0; | ||||||
switch (fhdr.spi_speed) { | ||||||
#if CONFIG_IDF_TARGET_ESP32H2 | ||||||
case 0x0: f_freq = 32; break; | ||||||
case 0x2: f_freq = 16; break; | ||||||
case 0xf: f_freq = 64; break; | ||||||
#else | ||||||
case 0x0: f_freq = 40; break; | ||||||
case 0x1: f_freq = 26; break; | ||||||
case 0x2: f_freq = 20; break; | ||||||
case 0xf: f_freq = 80; break; | ||||||
#endif | ||||||
default: f_freq = fhdr.spi_speed; break; | ||||||
} | ||||||
chip_report_printf(" Bus Speed : %lu MHz\n", f_freq); | ||||||
|
||||||
// Runtime flash frequency detection from hardware registers | ||||||
uint32_t actual_freq = getFlashFrequencyMHz(); | ||||||
uint8_t source_freq = getFlashSourceFrequencyMHz(); | ||||||
uint8_t divider = getFlashClockDivider(); | ||||||
|
||||||
chip_report_printf(" Bus Speed : %lu MHz\n", actual_freq); | ||||||
chip_report_printf(" Flash Frequency : %lu MHz (source: %u MHz, divider: %u)\n", actual_freq, source_freq, divider); | ||||||
|
||||||
if (isFlashHighPerformanceModeEnabled()) { | ||||||
chip_report_printf(" HPM Mode : Enabled (> 80 MHz)\n"); | ||||||
} | ||||||
|
||||||
chip_report_printf(" Bus Mode : "); | ||||||
#if CONFIG_ESPTOOLPY_OCT_FLASH | ||||||
chip_report_printf("OPI\n"); | ||||||
|
@@ -345,3 +341,115 @@ void printAfterSetupInfo(void) { | |||||
chip_report_printf("============ After Setup End =============\n"); | ||||||
delay(20); //allow the print to finish | ||||||
} | ||||||
|
||||||
// ============================================================================ | ||||||
// Flash Frequency Runtime Detection | ||||||
// ============================================================================ | ||||||
|
||||||
// Define SPI0 base addresses for different chips | ||||||
#if CONFIG_IDF_TARGET_ESP32S3 | ||||||
#define FLASH_SPI0_BASE 0x60003000 | ||||||
#elif CONFIG_IDF_TARGET_ESP32S2 | ||||||
#define FLASH_SPI0_BASE 0x3f402000 | ||||||
#elif CONFIG_IDF_TARGET_ESP32C3 | ||||||
#define FLASH_SPI0_BASE 0x60002000 | ||||||
#elif CONFIG_IDF_TARGET_ESP32C2 | ||||||
#define FLASH_SPI0_BASE 0x60002000 | ||||||
#elif CONFIG_IDF_TARGET_ESP32C6 | ||||||
#define FLASH_SPI0_BASE 0x60003000 | ||||||
#elif CONFIG_IDF_TARGET_ESP32H2 | ||||||
#define FLASH_SPI0_BASE 0x60003000 | ||||||
#elif CONFIG_IDF_TARGET_ESP32 | ||||||
#define FLASH_SPI0_BASE 0x3ff42000 | ||||||
#else | ||||||
#define FLASH_SPI0_BASE 0x60003000 // Default for new chips | ||||||
|
#define FLASH_SPI0_BASE 0x60003000 // Default for new chips | |
#error "Unsupported chip variant: FLASH_SPI0_BASE is not defined for this target. Please add support for your chip." |
Copilot uses AI. Check for mistakes.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number 0x3 should be defined as a named constant (e.g., #define CORE_CLK_SEL_MASK 0x3
) to improve code readability and maintainability.
Copilot uses AI. Check for mistakes.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bit position 31 should be defined as a named constant (e.g., #define CLOCK_1_TO_1_BIT 31
) to improve code readability and maintainability.
Copilot uses AI. Check for mistakes.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shift amount 16 and mask 0xFF should be defined as named constants (e.g., #define CLKDIV_PRE_SHIFT 16
and #define CLKDIV_PRE_MASK 0xFF
) to improve code readability and maintainability.
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line duplicates the frequency information already displayed in the 'Bus Speed' line above. Consider removing this redundant output or consolidating the information into a single, more comprehensive line.
Copilot uses AI. Check for mistakes.