PaulStoffregen / XPT2046_Touchscreen

Touchscreen Arduino Library for XPT2046 Touch Controller Chip
240 stars 84 forks source link

Fails with ESP32 - solution provided #14

Open hsgentry opened 6 years ago

hsgentry commented 6 years ago

I have used this library many times with the ESP2866 with excellent results. I recently ported a project to the ESP32. It worked about 90% of the time, but occasionally it would crash with:"Guru Meditation Error: Core 1 panic'ed (Cache disabled but cached memory region accessed)". I also use preferences.h to store data in NV ram. The crash was caused by an interrupt from the touch screen while preferences was saving data to NV ram. I added IRAM_ATTR to the interrupt service routine in the .cpp file in the touch library.

Changed: void isrPin( void )

to: void IRAM_ATTR isrPin( void )

and the touch library is now 100% reliable on the ESP32.

The development environment is Arduino IDE 1.8.2

touch library version 1.20

CelliesProjects commented 6 years ago

Good catch!

https://esp-idf.readthedocs.io/en/v2.0/general-notes.html#iram-instruction-ram

I may have the same issue here. Guru Meditation Error: Core 1 panic'ed (Cache disabled but cached memory region accessed)

I will try your fix and report back.

nrdmtt commented 4 years ago

The same issue is present when this lib is used with an ESP8266 using latest toolchain version.

The solution is to expand the #ifdef statement to

#ifdef ESP32
void IRAM_ATTR isrPin( void )
#elif ESP8266
void ICACHE_RAM_ATTR isrPin ( void )
#else
void isrPin( void )
#endif