Skip to content
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

pgm_read_word causes core panic in ESP32 #289

Open
danalvarez opened this issue May 20, 2023 · 1 comment
Open

pgm_read_word causes core panic in ESP32 #289

danalvarez opened this issue May 20, 2023 · 1 comment

Comments

@danalvarez
Copy link
Contributor

danalvarez commented May 20, 2023

I am posting this so that it might help others in the future. I am using an ESP32-devkitC-V4 board with an ESP32-WROOM-UE module. I am using the latest arduino-esp32 core (2.0.9). I am using this library to communicate with a lora module, I have used it before in an ATMEGA328P with no issues.

The problem

When running the DeviceInfo.ino example with the library as-is, it causes the ESP32 to go into a boot loop, throwing core panics each time. I ran the stack trace through EspExceptionDecoder and it pointed me to line 1339 in TheThingsNetwork.cpp, which is:

strcpy_P(command, (char *)pgm_read_word(&(radio_table[index])));

The solution

After some time, I found this very helpful post, in which a very similar behaviour is observed in an ESP8266. The user suggests to swap pgm_read_word for pgm_read_dword, since the latter returns a 32-bit pointer. I changed all the instances of pgm_read_word in TheThingsNetwork.cpp and, voilá, it worked! No more core panics, no more reboots.

Why?

I am still unsure why this solves the problem. I understand from the post I linked before, that pgm_read_word returns a 16-bit pointer and pgm_read_dword returns a 32-bit pointer. I've also read that an Arduino int in ESP32 is 32 bits (instead of 16 as in AVR). Maybe it's related to this? Anyone got any ideas?

Final remarks

When looking up whether this library supported ESP32, I found #241 (August 2018), which fixed a compilation error for ESP32 by adding some checks before including pgmspace.h. However, the library had a huge refactor in 8a7ee08 (April 2020), significantly reducing RAM usage by placing most strings in flash. As far as I can tell, this is when compatibility with ESP32 broke. In fact, #265 describes issues very similar to mine (i.e., a boot loop), but no other comments were given... Maybe @kevin192291 still remembers how he ended up solving the issue?

Hope this helps!

@Tatiblanblan
Copy link

Hi i have the same issue with my esp32 and my LoRa shield. i tried all that you said but nothing work. if i can make it work i tell you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants