本节主要是对于Esp.h文件的理解,在该头文件中主要是实现了对内核中的RAM资源的管理、片外SPI RAM管理、获取芯片的基本信息、Flash管理。
其中分为片内与片外RAM的管理。
//Internal RAM uint32_t getHeapSize(); //total heap size 全部的片内内存大小 uint32_t getFreeHeap(); //available heap 可以内存大小 uint32_t getMinFreeHeap(); //lowest level of free heap since boot uint32_t getMaxAllocHeap(); //largest block of heap that can be allocated at once //SPI RAM 外设需要自己设计 uint32_t getPsramSize(); uint32_t getFreePsram(); uint32_t getMinFreePsram(); uint32_t getMaxAllocPsram();
获取芯片基本信息,包括了芯片的id物理地址、版本、运行频率等
uint8_t getChipRevision(); uint32_t getCpuFreqMHz(){ return getCpuFrequencyMhz(); } inline uint32_t getCycleCount() __attribute__((always_inline)); const char * getSdkVersion(); uint64_t getEfuseMac();
例子:
1 #include <Arduino.h> 2 3 void setup() 4 { 5 Serial.begin(9600); 6 Serial.println(""); 7 } 8 9 uint64_t chipid; 10 11 void loop() 12 { 13 chipid=ESP.getEfuseMac();//The chip ID is essentially its MAC address(length: 6 bytes). 14 Serial.printf("ESP32 Chip ID = %04X",(uint16_t)(chipid>>32));//print High 2 bytes 15 Serial.printf("%08X\n",(uint32_t)chipid);//print Low 4bytes. 16 17 Serial.printf("total heap size = %u\n",ESP.getHeapSize()); 18 Serial.printf("available heap = %u\n",ESP.getFreeHeap()); 19 Serial.printf("lowest level of free heap since boot = %u\n",ESP.getMinFreeHeap()); 20 Serial.printf("largest block of heap that can be allocated at once = %u\n",ESP.getMaxAllocHeap()); 21 22 Serial.printf("total Psram size = %u\n",ESP.getPsramSize()); 23 Serial.printf("available Psram = %u\n",ESP.getFreePsram()); 24 Serial.printf("lowest level of free Psram since boot = %u\n",ESP.getMinFreePsram()); 25 Serial.printf("largest block of Psram that can be allocated at once = %u\n",ESP.getMinFreePsram()); 26 27 Serial.printf("get Chip Revision = %u\n",ESP.getChipRevision()); 28 Serial.printf("getCpuFreqMHz = %u\n",ESP.getCpuFreqMHz()); 29 Serial.printf("get Cycle Count = %u\n",ESP.getCycleCount()); 30 Serial.printf("get SdkVersion = %s\n",ESP.getSdkVersion()); 31 32 delay(5000); 33 }
原文:https://www.cnblogs.com/zy-cnblogs/p/13295736.html