-
Notifications
You must be signed in to change notification settings - Fork 7.6k
BLE isnt working properly while using Arduino as esp-idf component #2723
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
Comments
I also stumbled upon this recently. Seems there was a change the the queue code that "broke" semaphores. @igrr @projectgus could you comment on this please? Semaphores cause assert exception, even though they are properly given/taken from different threads. |
Hi @me-no-dev, It looks like the In FreeRTOS, mutex semaphores are a specialised semaphore type for implementing "simple mutual exclusion". As noted in the FreeRTOS docs, the mutex must always be given back otherwise the task which "owns" it can permanently have the wrong priority. This was the source of a lot of subtle bugs both in IDF and in IDF apps because the mutex semaphore semaphore is taken/given from different tasks, so we added this assert that the task which "takes" a mutex semaphore is the task which "gives" it back. In this case it looks like the semaphore is "given" in the btc_task callback but is probably taken by another task which is calling into the BLE library. This usage may be more suited to a FreeRTOS binary semaphore? |
@projectgus thanks for ur help. so you mean.. there's no way to use BLE Arduino library in esp-idf..? |
@happynet95 I mean that the BLE Arduino library probably had some subtle bugs with the incorrect semaphore type before, and now it has an obvious failure in the latest IDF. The fix may be as simple as changing the call to xSemaphoreCreateMutex() here and replacing the one line with these two lines:
However I haven't tested this, there might be some places where this class is used that need the mutex semaphore behaviour (ie priority inheritance). |
Awesome, I've been getting this assert occasionally when giving the semaphore in the callback for various BLE functions and have been scratching my head on this for a while. I'll try this change and report back. |
@projectgus this is exactly the info I needed :) binary semaphores it is! We will need to change a few libs here and there it seems. |
Tried out the change suggested by @projectgus. Been running fine for a couple hours now. |
I just created a pull request for this as well as taking care of another bug that can cause an assert when giving the semaphore from the callback. #2728 |
Still not working...
I think I've just have to move on to esp-idf, not using Arduino library. |
@h2zero Does your device work well? |
@happynet95, yes I’ve just ran for 12 hours or so without an issue. Not sure why that didn’t work for you, I’ll do some more testing on another device. |
Just checked again with another device from a fresh IDF and Arduino clone. Without the above changes I get the same error. As soon as I make the changes in the PR it works fine and has been for over an hour. Only differences I can think of is my IDF is a couple commits ahead of yours and my sdkconfig is a bit different. Double check you’ve made the changes in the PR. If it still doesn’t work try the IDF @ ca6cff7, as that is the commit I’m using. |
i've been testing the same changes in different code and also have no issues |
@me-no-dev You mean the m_owner position? I haven’t moved it back yet, I can do that right away for the PR if you want. Just be aware that it should be noted as a known bug that will occasionaly cause crashes for some people. Updated PR to restore m_owner position as requested. |
@h2zero can I check your sdkconfig please? seems like I've made some mistakes in menuconfig. |
@happynet95 |
@happynet95 |
@h2zero |
That’s odd, just be aware the IDF version you get now might need a couple modifications in the bledevice.cpp and Bluetoothserial.cpp files to compile. If you’re on windows you’ll have issues compiling anything after commit ca6cff7, due to the ld make file changes after that. |
@h2zero |
I changed: line 161 to:
I haven't tested it but it seemed logical, just needed to make it compile. |
@h2zero
to
but I think I've changed the latest version to old version(instead of substituting the old one to new one), so it made errors. |
@happynet95 Anyway here's what I did in BLEDevice.cpp: Line 508 This was just to make it compile and not really what should be done, but it works with most of my devices. It's on my todo list to correct. |
@h2zero Thank You! I finally got it! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This stale issue has been automatically closed. Thank you for your contributions. |
Hi. I'm working with ESP32 esp-idf. I'm trying to use Arduino as esp-idf component.
It works perfect when I run Blink example with make flash :
/// file name : main.cpp ///
However, It fails to send data BLE_notify example.
https://github.com/espressif/arduino-esp32/blob/master/libraries/BLE/examples/BLE_notify/BLE_notify.ino
when I run it with esp-idf(I mean, when I type make flash and make monitor)
I got this :
DId I do something wrong? I can't even guess what's wrong with it.
The text was updated successfully, but these errors were encountered: