1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-29 05:21:37 +03:00

Merge branch 'master' into wifi_mesh_update_2.2

This commit is contained in:
Earle F. Philhower, III
2020-06-21 13:35:33 -07:00
committed by GitHub
34 changed files with 737 additions and 300 deletions

View File

@ -110,10 +110,13 @@ void fetchFingerprint() {
Serial.printf(R"EOF(
The SHA-1 fingerprint of an X.509 certificate can be used to validate it
instead of the while certificate. This is not nearly as secure as real
X.509 validation, but is better than nothing.
X.509 validation, but is better than nothing. Also be aware that these
fingerprints will change if anything changes in the certificate chain
(i.e. re-generating the certificate for a new end date, any updates to
the root authorities, etc.).
)EOF");
BearSSL::WiFiClientSecure client;
static const char fp[] PROGMEM = "5F:F1:60:31:09:04:3E:F2:90:D2:B0:8A:50:38:04:E8:37:9F:BC:76";
static const char fp[] PROGMEM = "59:74:61:88:13:CA:12:34:15:4D:11:0A:C1:7F:E6:67:07:69:42:F5";
client.setFingerprint(fp);
fetchURL(&client, host, port, path);
}

View File

@ -170,8 +170,8 @@ bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* passphrase, int ch
if(ip.ip.addr == 0x00000000) {
// Invalid config
DEBUG_WIFI("[AP] IP config Invalid resetting...\n");
//192.168.244.1 , 192.168.244.1 , 255.255.255.0
ret = softAPConfig(0x01F4A8C0, 0x01F4A8C0, 0x00FFFFFF);
//192.168.4.1 , 192.168.4.1 , 255.255.255.0
ret = softAPConfig(0x0104A8C0, 0x0104A8C0, 0x00FFFFFF);
if(!ret) {
DEBUG_WIFI("[AP] softAPConfig failed!\n");
ret = false;

View File

@ -203,6 +203,7 @@ void SPIClass::setFrequency(uint32_t freq) {
static uint32_t lastSetRegister = 0;
if(freq >= ESP8266_CLOCK) {
// magic number to set spi sysclock bit (see below.)
setClockDivider(0x80000000);
return;
}
@ -215,7 +216,7 @@ void SPIClass::setFrequency(uint32_t freq) {
const spiClk_t minFreqReg = { 0x7FFFF020 };
uint32_t minFreq = ClkRegToFreq((spiClk_t*) &minFreqReg);
if(freq < minFreq) {
// use minimum possible clock
// use minimum possible clock regardless
setClockDivider(minFreqReg.regValue);
lastSetRegister = SPI1CLK;
lastSetFrequency = freq;
@ -227,8 +228,14 @@ void SPIClass::setFrequency(uint32_t freq) {
spiClk_t bestReg = { 0 };
int32_t bestFreq = 0;
// find the best match
while(calN <= 0x3F) { // 0x3F max for N
// aka 0x3F, aka 63, max for regN:6
const uint8_t regNMax = (1 << 6) - 1;
// aka 0x1fff, aka 8191, max for regPre:13
const int32_t regPreMax = (1 << 13) - 1;
// find the best match for the next 63 iterations
while(calN <= regNMax) {
spiClk_t reg = { 0 };
int32_t calFreq;
@ -239,8 +246,8 @@ void SPIClass::setFrequency(uint32_t freq) {
while(calPreVari++ <= 1) { // test different variants for Pre (we calculate in int so we miss the decimals, testing is the easyest and fastest way)
calPre = (((ESP8266_CLOCK / (reg.regN + 1)) / freq) - 1) + calPreVari;
if(calPre > 0x1FFF) {
reg.regPre = 0x1FFF; // 8191
if(calPre > regPreMax) {
reg.regPre = regPreMax;
} else if(calPre <= 0) {
reg.regPre = 0;
} else {
@ -254,19 +261,21 @@ void SPIClass::setFrequency(uint32_t freq) {
calFreq = ClkRegToFreq(&reg);
//os_printf("-----[0x%08X][%d]\t EQU: %d\t Pre: %d\t N: %d\t H: %d\t L: %d = %d\n", reg.regValue, freq, reg.regEQU, reg.regPre, reg.regN, reg.regH, reg.regL, calFreq);
if(calFreq == (int32_t) freq) {
if(calFreq == static_cast<int32_t>(freq)) {
// accurate match use it!
memcpy(&bestReg, &reg, sizeof(bestReg));
break;
} else if(calFreq < (int32_t) freq) {
} else if(calFreq < static_cast<int32_t>(freq)) {
// never go over the requested frequency
if(abs(freq - calFreq) < abs(freq - bestFreq)) {
auto cal = std::abs(static_cast<int32_t>(freq) - calFreq);
auto best = std::abs(static_cast<int32_t>(freq) - bestFreq);
if(cal < best) {
bestFreq = calFreq;
memcpy(&bestReg, &reg, sizeof(bestReg));
}
}
}
if(calFreq == (int32_t) freq) {
if(calFreq == static_cast<int32_t>(freq)) {
// accurate match use it!
break;
}

View File

@ -22,7 +22,6 @@
#define _SPI_H_INCLUDED
#include <Arduino.h>
#include <stdlib.h>
#define SPI_HAS_TRANSACTION 1

View File

@ -3,6 +3,7 @@
// released to public domain
#include <ESP8266WiFi.h>
#include <umm_malloc/umm_malloc.h>
void stats(const char* what) {
// we could use getFreeHeap() getMaxFreeBlockSize() and getHeapFragmentation()
@ -21,9 +22,53 @@ void tryit(int blocksize) {
void** p;
int blocks;
// heap-used ~= blocks*sizeof(void*) + blocks*blocksize
blocks = ((ESP.getMaxFreeBlockSize() / (blocksize + sizeof(void*))) + 3) & ~3; // rounded up, multiple of 4
/*
heap-used ~= blocks*sizeof(void*) + blocks*blocksize
This calculation gets deep into how umm_malloc divides up memory and
understanding it is not important for this example. However, some may find
the details useful when creating memory restricted test cases and possibly
other manufactured failures.
Internally the umm_malloc works with memory in 8-byte increments and aligns
to 8 bytes. The creation of an allocation adds about 4-bytes of overhead
plus alignment to the allocation size and more for debug builds. This
complicates the calculation of `blocks` a little.
ESP.getMaxFreeBlockSize() does not indicate the amount of memory that is
available for use in a single malloc call. It indicates the size of a
contiguous block of (raw) memory before the umm_malloc overhead is removed.
It should also be pointed out that, if you allow for the needed overhead in
your malloc call, it could still fail in the general case. An IRQ handler
could have allocated memory between the time you call
ESP.getMaxFreeBlockSize() and your malloc call, reducing the available
memory. In this particular sketch, with "WiFi off" we are not expecting this
to be an issue.
The macro UMM_OVERHEAD_ADJUST provides a value that can be used to adjust
calculations when trying to dividing up memory as we are here. However, the
calculation of multiple elements combined with the rounding up for the
8-byte alignment of each allocation can make for some tricky calculations.
*/
int rawMemoryMaxFreeBlockSize = ESP.getMaxFreeBlockSize();
// Remove the space for overhead component of the blocks*sizeof(void*) array.
int maxFreeBlockSize = rawMemoryMaxFreeBlockSize - UMM_OVERHEAD_ADJUST;
// Initial estimate to use all of the MaxFreeBlock with multiples of 8 rounding up.
blocks = maxFreeBlockSize /
(((blocksize + UMM_OVERHEAD_ADJUST + 7) & ~7) + sizeof(void*));
/*
While we allowed for the 8-byte alignment overhead for blocks*blocksize we
were unable to compensate in advance for the later 8-byte aligning needed
for the blocks*sizeof(void*) allocation. Thus blocks may be off by one count.
We now validate the estimate and adjust as needed.
*/
int rawMemoryEstimate =
blocks * ((blocksize + UMM_OVERHEAD_ADJUST + 7) & ~7) +
((blocks * sizeof(void*) + UMM_OVERHEAD_ADJUST + 7) & ~7);
if (rawMemoryMaxFreeBlockSize < rawMemoryEstimate) {
--blocks;
}
Serial.printf("\nFilling memory with blocks of %d bytes each\n", blocksize);
stats("before");
@ -41,7 +86,7 @@ void tryit(int blocksize) {
}
stats("freeing every other blocks");
for (int i = 0; i < blocks; i += 4) {
for (int i = 0; i < (blocks - 1); i += 4) {
if (p[i + 1]) {
free(p[i + 1]);
}

View File

@ -120,6 +120,7 @@ coreVersionNumeric LITERAL1
# Filesystem objects
SPIFFS KEYWORD1
LittleFS KEYWORD1
SDFS KEYWORD1
File KEYWORD1
Dir KEYWORD1