Closed taherrera closed 1 year ago
I'm going to start looking into this. I hope to have an answer for you in the next few days.
A few things I noticed...
To use this library, I have to change the menuconfig and use these configurations:
This library being the esp-idf library?
Is Bluedroid being disabled by Amazon-FreeRTOS ? I am confused by this line.
I don't think so. This configuration looks to be set in an sdk configuration file provided by esp-idf. See this. You may need to set this value.
Can you provide a link to whatever you're basing your demo off of? Looking through your code I see where you create the Bluetooth task but I'm not seeing the scheduler being started anywhere. Is this being started somewhere else?
Near the very top of your stack trace points to this function in esp-idf. From there it spirals into the esp-idf framework a bit. Your post may be better answered by the Espressif/ESP32 forums as this might be as simple as a configuration issue.
Hello,
This library being the esp-idf library?
I mean the library I translated from here into my project.
I don't think so. This configuration looks to be set in an sdk configuration file provided by esp-idf. See this. You may need to set this value.
I changed the configurations on the file you are mentioning to:
CONFIG_BT_ENABLED=y
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=n
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=y
CONFIG_BTDM_CTRL_MODE_BTDM=n
CONFIG_BT_BLUEDROID_ENABLED=y
CONFIG_BT_NIMBLE_ENABLED=n
But I still see the line:
/tmp/confgen_tmptfuyjhj6:20 line was updated to CONFIG_BT_BLUEDROID_ENABLED=n
Can you provide a link to whatever you're basing your demo off of? Looking through your code I see where you create the Bluetooth task but I'm not seeing the scheduler being started anywhere. Is this being started somewhere else?
I am not sure how to start the scheduler, you mean vTaskStartScheduler()
? I was not calling this function, so I added this to the main.c but it still fails, now with a slightly different error though. I uploaded the entire project to: https://github.com/taherrera/AFR-Bluedroid. This is the error:
Re-enable cpu cache.
Guru Meditation Error: Core 0 panic'ed (Cache disabled but cached memory region accessed).
Core 0 register dump:
PC : 0x400d3754 PS : 0x00060034 A0 : 0x8008cf46 A1 : 0x3ffbe1f0
0x400d3754: xQueueGenericSendFromISR at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/freertos_kernel/queue.c:987
A2 : 0x3ffbc404 A3 : 0x3ffbe210 A4 : 0x3ffbe218 A5 : 0x3ffce250
A6 : 0x3ffbe68c A7 : 0x3ffd37fc A8 : 0x80080e25 A9 : 0x3ffbe1e0
A10 : 0x3ffbc404 A11 : 0x3ffbe210 A12 : 0x3ffbe218 A13 : 0x00000000
A14 : 0xfffff000 A15 : 0x00000100 SAR : 0x00000020 EXCCAUSE: 0x00000007
EXCVADDR: 0x00000000 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xffffffff
Core 0 was running in ISR context:
EPC1 : 0x40008544 EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x400d3754
0x400d3754: xQueueGenericSendFromISR at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/freertos_kernel/queue.c:987
Backtrace:0x400d3751:0x3ffbe1f0 0x4008cf43:0x3ffbe210 0x4008d1ed:0x3ffbe240 0x400813ee:0x3ffbe260 0x40008541:0x3ffce180 0x400835ad:0x3ffce1a0 0x40091523:0x3ffce1c0 0x40091436:0x3ffce200 0x40091725:0x3ffce220 0x400834c6:0x3ffce250 0x40083539:0x3ffce2a0 0x401224c5:0x3ffce2c0 0x40121689:0x3ffce2e0 0x40121809:0x3ffce300 0x401201b6:0x3ffce370 0x401206f9:0x3ffce3f0 0x40120d2f:0x3ffce460 0x4011fe73:0x3ffce480 0x401007f2:0x3ffce4b0 0x400d6626:0x3ffce510 0x400d678d:0x3ffce530 0x40105692:0x3ffce580 0x400ff721:0x3ffce740 0x40101607:0x3ffce760
0x400d3751: prvInitialiseMutex at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/freertos_kernel/queue.c:509
(inlined by) prvInitialiseMutex at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/freertos_kernel/queue.c:492
(inlined by) xQueueCreateMutex at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/freertos_kernel/queue.c:528
0x4008cf43: btdm_task_post_from_isr at ??:?
0x4008d1ed: r_rwbtdm_isr_wrapper at intc.c:?
0x400813ee: _xt_lowint1 at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/freertos_kernel/portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_vectors.S:1193
0x400835ad: delay_us at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/spi_flash/spi_flash_os_func_app.c:102
0x40091523: spi_flash_chip_generic_wait_idle at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/spi_flash/spi_flash_chip_generic.c:283
0x40091436: spi_flash_chip_generic_page_program at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/spi_flash/spi_flash_chip_generic.c:175
(inlined by) spi_flash_chip_generic_page_program at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/spi_flash/spi_flash_chip_generic.c:165
0x40091725: spi_flash_chip_generic_write at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/spi_flash/spi_flash_chip_generic.c:195
0x400834c6: esp_flash_write at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/spi_flash/esp_flash_api.c:616
0x40083539: spi_flash_write at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/spi_flash/esp_flash_api.c:756
0x401224c5: nvs::nvs_flash_write(unsigned int, void const*, unsigned int) at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/nvs_flash/src/nvs_ops.cpp:72
0x40121689: nvs::Page::writeEntryData(unsigned char const*, unsigned int) at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/nvs_flash/src/nvs_page.cpp:152
0x40121809: nvs::Page::writeItem(unsigned char, nvs::ItemType, char const*, void const*, unsigned int, unsigned char) at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/nvs_flash/src/nvs_page.cpp:247
0x401201b6: nvs::Storage::writeMultiPageBlob(unsigned char, char const*, void const*, unsigned int, nvs::VerOffset) at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/nvs_flash/src/nvs_storage.cpp:213
0x401206f9: nvs::Storage::writeItem(unsigned char, nvs::ItemType, char const*, void const*, unsigned int) at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/nvs_flash/src/nvs_storage.cpp:310
(inlined by) nvs::Storage::writeItem(unsigned char, nvs::ItemType, char const*, void const*, unsigned int) at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/nvs_flash/src/nvs_storage.cpp:266
0x40120d2f: nvs::NVSHandleSimple::set_blob(char const*, void const*, unsigned int) at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/nvs_flash/src/nvs_handle_simple.cpp:52
(inlined by) nvs::NVSHandleSimple::set_blob(char const*, void const*, unsigned int) at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/nvs_flash/src/nvs_handle_simple.cpp:47
0x4011fe73: nvs_set_blob at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/nvs_flash/src/nvs_api.cpp:441
0x401007f2: config_save at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/bt/common/osi/config.c:462
0x400d6626: btc_config_flush at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/bt/host/bluedroid/btc/core/btc_config.c:314
0x400d678d: btc_storage_add_bonded_device at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/bt/host/bluedroid/btc/core/btc_storage.c:54
0x40105692: btc_dm_auth_cmpl_evt at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/bt/host/bluedroid/btc/core/btc_dm.c:348
(inlined by) btc_dm_sec_cb_handler at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/bt/host/bluedroid/btc/core/btc_dm.c:656
0x400ff721: btc_thread_handler at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/bt/common/btc/core/btc_task.c:184
0x40101607: osi_thread_run at /home/tom/Documents/SLT/tecnocal/instacrop/fw/instacrop_test/build/../amazon-freertos/vendors/espressif/esp-idf/components/bt/common/osi/thread.c:68
Near the very top of your stack trace points to this function in esp-idf. From there it spirals into the esp-idf framework a bit. Your post may be better answered by the Espressif/ESP32 forums as this might be as simple as a configuration issue.
I will ask, but it is strange because this works on ESP-IDF, so there is something different going on with AFR, causing this error. The only difference in the implementation on ESP-IDF are these functions on my main.c which I do not know why I need them on AFR, but without them I cannot compile Amazon-FreeRTOS:
extern void esp_vApplicationTickHook();
void IRAM_ATTR vApplicationTickHook(){
esp_vApplicationTickHook();
}
extern void esp_vApplicationIdleHook();
void vApplicationIdleHook(){
esp_vApplicationIdleHook();
}
void vApplicationDaemonTaskStartupHook( void ){
}
Hey, I've cloned down your repository and have started looking into your problem. I'll continue this effort to see if I can better assist you with your issue.
In the meantime I was wondering if you had tried starting with an existing bluetooth demo for the STM32 board and then from there adding your needed functionality? This could ensure that you have the board and device properly working by following our documentation, at which point you could begin adding in your functions for your personal use case? We have a doc for our bluetooth demos available here, as well as a GitHub link to some demos here.
If any of these resources help you solve your problem please let me know!
Hello, @taherrera!
Currently, Amazon FreeRTOS uses ESP-IDF v4.2.2
. Thus, there is a great chance that the code you have (tested in ESP-IDF v4.4) might not work with AFR. Could you please try out the PR https://github.com/aws/amazon-freertos/pull/3541 and revert here if your code is working as expected?
Hello @laukik-hase ,
I tried PR #3541 , with these commands
git clone https://github.com/aws/amazon-freertos.git --recurse-submodules
cd amazon-freertos
git fetch origin pull/3541/head:afr_branch
git checkout afr_branch
git submodule update --init --recursive --checkout
But it fails on git submodule update --init --recursive --checkout
with this error:
fatal: reference is not a tree: 3ae7e4abf19a00196106d6aa4cdda27ce40cf165
fatal: reference is not a tree: b967ca054f48a36f82d8fcdd32e54ec5144f2751
Unable to checkout 'b967ca054f48a36f82d8fcdd32e54ec5144f2751' in submodule path 'vendors/espressif/esp-idf/components/nghttp/nghttp2/third-party/neverbleed'
Failed to recurse into submodule path 'vendors/espressif/esp-idf/components/nghttp/nghttp2'
Unable to checkout '3ae7e4abf19a00196106d6aa4cdda27ce40cf165' in submodule path 'freertos_kernel'
Failed to recurse into submodule path 'vendors/espressif/esp-idf'
However, I tried ESP-IDF checkout release/v4.2 and I can pair successfully, so it works con ESP-IDF 4.2 and 4.4. Now I am pretty sure there is something not allowing me to run this code with Amazon-FreeRTOS and it is not an issue originating in ESP-IDF.
Hello @Skptak,
In the meantime I was wondering if you had tried starting with an existing bluetooth demo for the STM32 board and then from there adding your needed functionality? This could ensure that you have the board and device properly working by following our documentation, at which point you could begin adding in your functions for your personal use case? We have a doc for our bluetooth demos available here, as well as a GitHub link to some demos here.
I have not tried other bluetooth solutions, because I think there is an underlying issue behind this that causes us not only not be able to use this bluetooth code, but also we have not been able to use NVS storage and cannot use the ESP-IDF 4.2 OTA functions. So since there are 3 problems related somehow to the flash storage in Amazon-FreeRTOS, we have not tried it. I first published this NVS problem as a bug but it was rapidly dismissed (see #3531) . So I lifted this issue with this bluetooth code which is more reproducible.
Hey again,
I have not tried other bluetooth solutions, because I think there is an underlying issue behind this that causes us not only not be able to use this bluetooth code
Sorry, my intention was not to tell you to use a different bluetooth solution. I was trying to offer that by starting with one of our bluetooth demos you could verify that everything in your build system and board is working correctly. For example if you take a look at this app_main() function from the demos. You can see that there are some additional checks that happen, and functions that are called when performing the BLE setup. I felt that it might relevant to look over some of this since you're running into several different issues, directly related to using the board.
Additionally, I can't speak to the error you're receiving on the update to that pull request. I was able to do the update to that PR and then perform the build. I don't currently have access to an ESP32 to run your code to further assist you, but I'm in the process of getting one so I can help you further.
If you have any updates while I work on getting a board, please let me know.
@taherrera
To reaffirm, you changed the esp32 configs as such?
Bluetooth controller -> BR/EDR Only
Bluetooth Host -> Bluedroid - Dual-mode
Bluedroid options -> Classic Bluetooth
Bluedroid options -> Classic Bluetooth -> SPP
If so then the the Bluetooth controller is configured for Classic Bluetooth only, but the amazon-freertos bluetooth services are GATT services that require BLE. Can you try setting Bluetooth controller to Bluetooth Dual Mode instead? You should be able to use Bluedroid, but building with amazon-freertos, NimBLE is set as the default.
Also amazon-freertos BLE services also directly use the bluedroid/nimBLE APIs. There may be some collision/clobbering, for example amazon-freertos bluetooth middleware also configures GAP.
Additionally, to clarify amazon-freertos does not technically use any version of ESP-IDF, rather it uses a fork specifically maintained for amazon-freertos, by Espressif: espressif/esp-afr-sdk. The version of it currently used by amazon-freertos is seeded from ESP-IDF v4.2.2 with some patches applied.
@mahavirj May have additional info to add.
Thanks @dachalco , I will try your suggested change and inform you asap.
Also, I forgot to mention, that when I do not initialize the nvs, the bluetooth implementation works (although I have to pair each time to the device before connecting).
Having to pair every time, due to omitting NVS, is expected. The bond information is supposed to persist, but if it doesn't then devices need to negotiate and exchange key information again, since it wasn't saved.
The thing I am trying to point out is that Bluetooth works as expected and does not panic if I do not initialize the nvs.
How are you building this code in amazon-freertos? From what I understand you've modifed the aws_demos/application_code/main.c
for the esp32? What's the full diff of changes made to main.c
? As mentioned earlier there's setup being done there for BLE and related NVS that should be retained. Furthermore the Arduino API should be reviewed to ensure it doesn't clobber configurations made by amazon-freertos demo.
Additionally, as I understand your code was based on IDF v4.4, but as mentioned amazon-freertos uses a fork based on v4.2. Have you reviewed that functions and usage are the same for both?
I set this in menuconfig:
Component config → Bluetooth → Bluetooth controller → Bluetooth controller mode (BR/EDR/BLE/DUALMODE)
but now this implementation cannot be compiled due missing reference to this function: btsnd_hcic_ble_update_adv_report_flow_control
The application that throws these errors is here: https://github.com/taherrera/AFR-Bluedroid)
In the AFR demos, there are a number of conflicts with a bluedroid SPP configuration. These conflicts are in iot_ble_hal_common_gap.c. This file configures the bluetooth for BLE GAP and only does incomplete for bluedroid intialization if the bluedroid menu option is selected. Compiling with the IDF 4.2 SPP demo incorporated is possible but a lot of work is required to get SPP functioning.
The Amazon FreeRTOS product does not support bluetooth classic. It does support bluedroid in BLE mode.
Hello,
I am trying to use bluetooth classic on the ESP32. For this I basically copied the Arduino implementation of bluetooth for the ESP32. On ESP-IDF v4.4, this bluetooth implementation works perfectly, however on Amazon-Freertos it does not work.
To use this library, I have to change the menuconfig and use these configurations: Bluetooth controller -> BR/EDR Only Bluetooth Host -> Bluedroid - Dual-mode Bluedroid options -> Classic Bluetooth Bluedroid options -> Classic Bluetooth -> SPP
When I build the project, these lines stand out for me:
Is Bluedroid being disabled by Amazon-FreeRTOS ? I am confused by this line.
When I initialize bluetooth I can see it broadcasting on my phone, however, when I try to pair I get this error:
As you can see, there seems to be a problem with writing to a partition. I can also see that the partition differs on Amazon FreeRTOS versus ESP-IDF.
System information
This is the Arduino Implementation of Bluetooth, I initialize Bluetooth by just calling
nvs_flash_init()
and thenBluetoothSerial_begin("test", 0)
And this is the .h file: