Skip to content

Commit

Permalink
Merge branch 'i2c_slave_by_bjoham' of https://github.com/thinx-cloud/…
Browse files Browse the repository at this point in the history
…Arduino into i2c_slave_by_bjoham

* 'i2c_slave_by_bjoham' of https://github.com/thinx-cloud/Arduino:
  Update debugging.rst (esp8266#5234)
  ESP8266httpClient crash-on-destructor bugfix (esp8266#5220)
  Add stack repainting call to ESP class (esp8266#5221)
  • Loading branch information
Matěj Sychra committed Oct 16, 2018
2 parents bfcbd71 + bd4a447 commit 542cf55
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 12 deletions.
5 changes: 5 additions & 0 deletions cores/esp8266/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ uint32_t EspClass::getFreeContStack()
return cont_get_free_stack(g_pcont);
}

void EspClass::resetFreeContStack()
{
cont_repaint_stack(g_pcont);
}

uint32_t EspClass::getChipId(void)
{
return system_get_chip_id();
Expand Down
1 change: 1 addition & 0 deletions cores/esp8266/Esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class EspClass {
void getHeapStats(uint32_t* free = nullptr, uint16_t* max = nullptr, uint8_t* frag = nullptr);

uint32_t getFreeContStack();
void resetFreeContStack();

const char * getSdkVersion();
String getCoreVersion();
Expand Down
6 changes: 6 additions & 0 deletions cores/esp8266/cont.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ int cont_get_free_stack(cont_t* cont);
// continuation stack
bool cont_can_yield(cont_t* cont);

// Repaint the stack from the current SP to the end, to allow individual
// routines' stack usages to be calculated by re-painting, checking current
// free, running the routine, then checking the max free
void cont_repaint_stack(cont_t *cont);


#ifdef __cplusplus
}
#endif
Expand Down
15 changes: 15 additions & 0 deletions cores/esp8266/cont_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,18 @@ bool ICACHE_RAM_ATTR cont_can_yield(cont_t* cont) {
return !ETS_INTR_WITHINISR() &&
cont->pc_ret != 0 && cont->pc_yield == 0;
}

// No need for this to be in IRAM, not expected to be IRQ called
void cont_repaint_stack(cont_t *cont)
{
register uint32_t *sp asm("a1");
// Ensure 64 bytes adjacent to the current SP don't get touched to endure
// we don't accidentally trounce over locals or IRQ temps.
uint32_t sp_safe = CONT_STACKSIZE/4 - ((sp - &cont->stack[0] - 64)/4);

// Fill stack with magic values
for(uint32_t pos = 0; pos < sp_safe; pos++)
{
cont->stack[pos] = CONT_STACKGUARD;
}
}
2 changes: 1 addition & 1 deletion doc/Troubleshooting/debugging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Debug Level
All defines for the different levels starts with ``DEBUG_ESP_``

a full list can be found here in the
`boards.txt <https://github.com/esp8266/Arduino/blob/master/boards.txt#L180>`__
`boards.txt <https://github.com/esp8266/Arduino/blob/master/tools/boards.txt.py#L1045-L1047>`__

Example for own debug messages
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ void loop() {
// wait for WiFi connection
if ((WiFiMulti.run() == WL_CONNECTED)) {

BearSSL::WiFiClientSecure client;
client.setFingerprint(fingerprint);
BearSSL::WiFiClientSecure *client = new BearSSL::WiFiClientSecure;

client->setFingerprint(fingerprint);

HTTPClient https;

Serial.print("[HTTPS] begin...\n");
if (https.begin(client, "https://jigsaw.w3.org/HTTP/connection.html")) { // HTTPS
if (https.begin(*client, "https://jigsaw.w3.org/HTTP/connection.html")) { // HTTPS


Serial.print("[HTTPS] GET...\n");
Expand All @@ -72,6 +73,8 @@ void loop() {
} else {
Serial.printf("[HTTPS] Unable to connect\n");
}

delete client;
}

delay(10000);
Expand Down
15 changes: 8 additions & 7 deletions libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ HTTPClient::HTTPClient()
HTTPClient::~HTTPClient()
{
if(_client) {
_client->stop();
DEBUG_HTTPCLIENT("[HTTP-Client][~HTTPClient] end() not called before destruction of HTTPClient\n");
}
if(_currentHeaders) {
delete[] _currentHeaders;
Expand Down Expand Up @@ -196,7 +196,7 @@ bool HTTPClient::begin(WiFiClient &client, String host, uint16_t port, String ur
#ifdef HTTPCLIENT_1_1_COMPATIBLE
bool HTTPClient::begin(String url, String httpsFingerprint)
{
if(_client) _canReuse = false;
_canReuse = false;
end();

_port = 443;
Expand All @@ -214,7 +214,7 @@ bool HTTPClient::begin(String url, String httpsFingerprint)

bool HTTPClient::begin(String url, const uint8_t httpsFingerprint[20])
{
if(_client) _canReuse = false;
_canReuse = false;
end();

_port = 443;
Expand All @@ -237,7 +237,7 @@ bool HTTPClient::begin(String url, const uint8_t httpsFingerprint[20])
*/
bool HTTPClient::begin(String url)
{
if(_client) _canReuse = false;
_canReuse = false;
end();

_port = 80;
Expand Down Expand Up @@ -299,7 +299,7 @@ bool HTTPClient::beginInternal(String url, const char* expectedProtocol)
#ifdef HTTPCLIENT_1_1_COMPATIBLE
bool HTTPClient::begin(String host, uint16_t port, String uri)
{
if(_client) _canReuse = false;
_canReuse = false;
end();

clear();
Expand All @@ -325,7 +325,7 @@ bool HTTPClient::begin(String host, uint16_t port, String uri, bool https, Strin

bool HTTPClient::begin(String host, uint16_t port, String uri, String httpsFingerprint)
{
if(_client) _canReuse = false;
_canReuse = false;
end();

clear();
Expand All @@ -343,7 +343,7 @@ bool HTTPClient::begin(String host, uint16_t port, String uri, String httpsFinge

bool HTTPClient::begin(String host, uint16_t port, String uri, const uint8_t httpsFingerprint[20])
{
if(_client) _canReuse = false;
_canReuse = false;
end();

clear();
Expand All @@ -367,6 +367,7 @@ bool HTTPClient::begin(String host, uint16_t port, String uri, const uint8_t htt
*/
void HTTPClient::end(void)
{
_canReuse = false;
disconnect();
clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ void fetchURL(BearSSL::WiFiClientSecure *client, const char *host, const uint16_
path = "/";
}

ESP.resetFreeContStack();
uint32_t freeStackStart = ESP.getFreeContStack();
Serial.printf("Trying: %s:443...", host);
client->connect(host, port);
if (!client->connected()) {
Expand Down Expand Up @@ -72,7 +74,8 @@ void fetchURL(BearSSL::WiFiClientSecure *client, const char *host, const uint16_
} while (millis() < to);
}
client->stop();
Serial.printf("\n-------\n\n");
uint32_t freeStackEnd = ESP.getFreeContStack();
Serial.printf("\nCONT stack used: %d\n-------\n\n", freeStackStart - freeStackEnd);
}

void fetchNoConfig() {
Expand Down

0 comments on commit 542cf55

Please sign in to comment.