Closed hmmkay closed 4 years ago
Using the PC and LR register variables to track down in which function the crash occurs and what the calling function were respectively; and using the target_img2.asm disassembly file I was able to track the problem down to when the ble_peripheral_app_handle_at_cmd method calls parse_param. Interestingly from what I can determine the crash happens right at the beginning of parse_param method when the stack pointer gets decremented by 1600 (for the incoming parameters I think). This 1600 value comes from the LOG_SERVICE_BUFLEN constant, which in the platform_opts.h file has a comment saying this constant can't be larger than UART_LOG_CMD_BUFLEN (which is set to 127). So setting LOG_SERVICE_BUFLEN to 100 resolved the crashing problem for me, but I'm not 100% sure why!
I'll create a pull request for my request for this plus one or two other tiny changes.
Now to figure out how to get/set attribute characteristics using AT commands with the module in peripheral mode, since those functions don't seem to be implemented yet!
good job @hmmkay cant wait the implemnetation.
BACKGROUND
I'm wanting to make use of the bluetooth capabilities in a Wio Terminal that includes a RTL8720DN Wifi/Bluetooth module.
I compiled and loaded the firmware from this repo onto the RTL8720DN without problem, and am running the example script from tools/rtl8720dm_usi_spi/rtl8720dm_usi_spi.ino on the main processor of the Wio Terminal, with a small modification to enable the debug messages from the RTL module coming in on the Logging serial port to be displayed - ie: Enable the Log UART with the following line at the end of the init() function:
RTL8720D.begin(115200);
... and the following code in the body to print to the user terminal any debug information coming in over the Log UART from the WiFi module:Below is my terminal output from the .ino application running on the main Wio Terminal CPU showing the module starts okay ...:
The Wifi module is running the newly compiled firmware 2.2.0.2 to allow managing BLE via AT commands: AT+GMR output:
Starting the Bluetoothstack with ATBp=1 works fine ATBp=1 output:
At this point I can see the device from an app on my phone, I can pair with the device, and I can read attributes, so looking good!
=== THE PROBLEM === Once the bluetooth stack is running with ATBp=1 (and also ATBc=1), if I then try any other ATB-prefixed command such as ATBS=1,0 to start a bluetooth scan, or ATBC=P,XXXXXXXXXXXX to connect to another device, or ATBI to get information about connected devices, etc the module crashes with a Hard Fault Patch error and endlessly displays AT_READ ERR per the example below.
These crashes mean I am completely unable to do anything with BLE, rendering it useless - ie: I regard the bug as severe. I've tried different initialization sequences in case there's something else I'm supposed to configure on the module to have it work without any luck so far, but am open to this being a user error on my side, in which case I'd appreciate a quick example on how to use the AT commands to pair with another device and read/write Characteristics!
ATBS=1,0 output
Thanks for providing the library, and I look forward to being able to use it soon! In the meanwhile I'll squint at the datasheets and see if I can't work out from the register/stack dump what is causing the error ...