Bluetooth SPP in VFS mode and select()
Posted: Fri Sep 09, 2022 6:12 am
Hi!
Is it possible to use Bluetooth SPP in VFS mode with select()?
I'm trying to implement non-blocking reading, but my application crashes at select() operation.
write() and read() to the SPP file descriptor works fine.
Code example:
Panic back trace, but it's not so usefull:
Is it possible to use Bluetooth SPP in VFS mode with select()?
I'm trying to implement non-blocking reading, but my application crashes at select() operation.
write() and read() to the SPP file descriptor works fine.
Code example:
- static void spp_read_handle(void *param)
- {
- int size = 0;
- int read_bytes;
- int spp_fd = (int)param;
- uint8_t *spp_data = (uint8_t *)malloc(SPP_DATA_LEN);
- if (!spp_data) {
- ESP_LOGE(TAG, "malloc spp_data failed, fd:%d", spp_fd);
- }
- while (true) {
- int s = 0;
- fd_set rfds;
- struct timeval tv = {
- .tv_sec = 5,
- .tv_usec = 0,
- };
- FD_ZERO(&rfds);
- FD_SET(spp_fd, &rfds);
- s = select(spp_fd + 1, &rfds, NULL, NULL, &tv); // crashed here
- if (s < 0) {
- ESP_LOGE(TAG, "Select failed: errno %d", errno);
- } else if (s == 0) {
- ESP_LOGI(TAG, "Timeout has been reached and nothing has been received");
- } else {
- ESP_LOGE(TAG, "Select: data is ready for reading");
- }
- };
- }
Code: Select all
Guru Meditation Error: Core 0 panic'ed (Instr
FetchProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x00000000 PS : 0x00060230 A0 : 0x800f38a6 A1 : 0x3fffa540
A2 : 0x3ffef6f0 A3 : 0x00000005 A4 : 0x00000001 A5 : 0x00000000
A6 : 0x00000005 A7 : 0x3ffc311c A8 : 0x800d3d60 A9 : 0x3fffa520
A10 : 0x00000000 A11 : 0x0000001c A12 : 0x80095cf5 A13 : 0x3ffdb7d0
A14 : 0x00000003 A15 : 0x00060323 SAR : 0x0000001b EXCCAUSE: 0x00000014
EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000
Backtrace:0xfffffffd:0x3fffa5400x400f38a3:0x3fffa5b0 0x40095b9d:0x3fffa5e0
0x400f38a3: spp_read_handle(void*) at /home/ilia.lutchenko/workspace/project/build/../firmware/bluetooth/bt_classic.cpp:115
0x40095b9d: vPortTaskWrapper at /home/ilia.lutchenko/workspace/project/build/../esp-idf/components/freertos/port/xtensa/port.c:131