Alternative to ESP_ERROR_CHECK

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Alternative to ESP_ERROR_CHECK

Postby kolban » Tue Feb 14, 2017 2:30 am

The ESP-IDF provides a useful macro called ESP_ERROR_CHECK() that takes a statement as a parameter. If the statement does NOT return ESP_OK, then we assert and log the line. Unfortunately, this doesn't include the error code value that was actually returned by the statement.

Here is an alternative definition which logs the error code in addition to throwing an assertion:

Code: Select all

#undef ESP_ERROR_CHECK
#define ESP_ERROR_CHECK(x)   do { esp_err_t rc = (x); if (rc != ESP_OK) { ESP_LOGE("err", "esp_err_t = %d", rc); assert(0 && #x);} } while(0);
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Alternative to ESP_ERROR_CHECK

Postby ESP_Angus » Tue Feb 14, 2017 3:14 am

Hi Kolban,

Good addition. Could you please send this as a pull request on github? We'll likely incorporate it into esp-idf.

Angus

BuddyCasino
Posts: 263
Joined: Sun Jun 19, 2016 12:00 am

Re: Alternative to ESP_ERROR_CHECK

Postby BuddyCasino » Fri Mar 31, 2017 6:53 pm

Very nice! This has bugged me too, didn't know it is that easy to contribute.

Bmillier
Posts: 3
Joined: Sun Aug 13, 2017 12:52 am

Re: Alternative to ESP_ERROR_CHECK

Postby Bmillier » Mon Sep 25, 2017 5:34 pm

Hi Neil
This is off topic: I love your book. Have used it on several projects, the latest being a learning IR remote/ wifi blaster using RMT peripheral. I note on page 255 you show max values of 65535 for the 15- bit timing value saved by the RMT peripheral. This should be 32767.
Using the Arduino IDE and my own drivers, I have gotten the IR transmit function working fine using
LIRC conf files for the IR data structure, as a test. I just got the basic IR receive function working for the "learning" part, but there's more work needed to handle the wide range of IR signals that the different remotes emit.
This would be easier to do if I were using the Espressif IDF, but that's more than I want to bite off right now.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Alternative to ESP_ERROR_CHECK

Postby kolban » Mon Oct 30, 2017 4:45 am

Thank you sir. Documentation changes to 32767.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

jeanleflambeur
Posts: 10
Joined: Sun Oct 08, 2017 4:26 pm

Re: Alternative to ESP_ERROR_CHECK

Postby jeanleflambeur » Wed Nov 01, 2017 8:48 pm

Pls use a mangled name for the internal macro variable rc.
That's because in C/C++ this statement actually compiles:

Code: Select all

int a = a;
It results in variable a being uninitialized essentially.
So with your macro, this code would have unexpected results:

Code: Select all

int rc = 7;
ESP_ERROR_CHECK(initialize_remote_control(rc));
The rc value passed to initialize_remote_control is actually random, not 7.

Also, this code would not compile because what is passed to the function is the internal esp_err_t instead of the string:

Code: Select all

esp_err_t  initialize_db(const string& name)
{
	//...
}
int  main(int argc, const char* argv[])
{
	string rc = "db1";
	ESP_ERROR_CHECK(initialize_db(rc));
	return 0;
}
I have a PR about this issue without any answer so far: https://github.com/espressif/esp-idf/pull/1109

The solution is simple - just call that internal variable smth else like __internal_rc__

Who is online

Users browsing this forum: No registered users and 62 guests