Page 1 of 1

ledcWrite, LEDC_MUTEX_LOCK crash the ESP32

Posted: Fri Mar 30, 2018 5:04 pm
by VormsThierry
Hello,
I use the arduino IDE.
I write some simple sketch to test an infra red library. This library is based on Ledc functionality
This sketch run as expected.
I incormporate the library in a bigger project and when the esp32 run on ledcWrite() method, the call to LEDC_MUTEX_LOCK() will crash the ESP32.
Here is the dump of the system:

0x40084879: xQueueGenericReceive at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/./queue.c line 1995
0x40087308: invoke_abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/./panic.c line 572
0x40087407: abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/./panic.c line 572
0x40084879: xQueueGenericReceive at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/./queue.c line 1995
0x400d5beb: ledcWrite at D:\Users\Thierry\Documents\Arduino\hardware\espressif\esp32\cores\esp32/esp32-hal-ledc.c line 164
0x400d4d61: IRsend::mark(unsigned int) at D:\Users\Thierry\Documents\Arduino\libraries\ESP32-IRremote/irSend.cpp line 40
0x400d4ee1: IRsend::sendSony(unsigned long, int) at D:\Users\Thierry\Documents\Arduino\libraries\ESP32-IRremote/ir_Sony.cpp line 28
0x400d497d: MilesTag::sendIrCode(unsigned long) at D:\Users\Thierry\Documents\Arduino\libraries\MilesTag/MilesTag.cpp line 77
0x400d3ce5: BoxLib::cycleIrMessage(unsigned int, unsigned char, unsigned char, unsigned char, char*, bool) at D:\Users\Thierry\Documents\Arduino\libraries\BoxLib/BoxLib.cpp line 936
0x400d179e: IdBox::checkReceiveDone(bool) at D:\Users\Thierry\Documents\Arduino\libraries\IdBox/IdBox.cpp line 259
0x400d1087: loop() at D:\Users\Thierry\Documents\Arduino\idBox/idBox.ino line 53
0x400eab3d: loopTask(void*) at D:\Users\Thierry\Documents\Arduino\hardware\espressif\esp32\cores\esp32/main.cpp line 18 (discriminator 1)

As we can see the problem occurs from esp32/esp32-hal-ledc.c line 164: call to LEDC_MUTEX_LOCK()

Any help to solve this issue will be welcome.
My e_mail adress is: vormsty@gmail.com
Best regards and thanks for the very impressive micro controller

Re: ledcWrite, LEDC_MUTEX_LOCK crash the ESP32

Posted: Wed Nov 28, 2018 5:04 am
by MoretonBayKiting
I have a very similar problem to that posted above. Mine arises when using the ESP32Servo library - which calls the LEDC library, which is referred to above. The problem line appears to be 164 of esp32-hal-ledc.c :- LEDC_MUTEX_LOCK();. As with the original query, I can run my ESC (ie ESC library which uses ESP32Servo) in a test sketch which runs the motor fwd and rev under control from the serial monitor. But when that sketch is integrated into the larger project, which, for example, integrates sensors, it fails at runtime.

I've just updated to the current Arduino IDE (1.8.7) and reinstalled ESP32 support using the board manager in the IDE.

Although I had been using ISRs for sensing, they have been removed (at least temporarily) until this problem is sorted.

Re: ledcWrite, LEDC_MUTEX_LOCK crash the ESP32

Posted: Tue Dec 18, 2018 10:49 am
by MoretonBayKiting
I've managed to get around the problem. Unfortunately my knowledge of microprocessors is sufficiently slim that I don't know whether this may cause other problems. It hasn't so far.
I took up the suggestion, from https://thomasolson.com/PROJECTS/BLE/ESP32/, to set CONFIG_DISABLE_HAL_LOCKS to 1. This results, through the definition of LEDC_MUTEX_LOCK() in esp32-hal-ledc.c, in LEDC_MUTEX_LOCK() being empty. Otherwise it is defined as
do {} while (xSemaphoreTake(_ledc_sys_lock, portMAX_DELAY) != pdPASS)
....which looks potentially probalematic.