Bluetooth SPP in VFS mode and select()

Air_Hamster
Posts: 3
Joined: Wed May 26, 2021 12:04 pm

Bluetooth SPP in VFS mode and select()

Postby Air_Hamster » 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:
  1. static void spp_read_handle(void *param)
  2. {
  3.     int size = 0;
  4.     int read_bytes;
  5.     int spp_fd = (int)param;
  6.  
  7.     uint8_t *spp_data = (uint8_t *)malloc(SPP_DATA_LEN);
  8.     if (!spp_data) {
  9.         ESP_LOGE(TAG, "malloc spp_data failed, fd:%d", spp_fd);
  10.     }
  11.  
  12.     while (true) {
  13.         int s = 0;
  14.         fd_set rfds;
  15.         struct timeval tv = {
  16.             .tv_sec = 5,
  17.             .tv_usec = 0,
  18.         };
  19.  
  20.         FD_ZERO(&rfds);
  21.         FD_SET(spp_fd, &rfds);
  22.  
  23.         s = select(spp_fd + 1, &rfds, NULL, NULL, &tv); // crashed here
  24.  
  25.         if (s < 0) {
  26.             ESP_LOGE(TAG, "Select failed: errno %d", errno);
  27.         } else if (s == 0) {
  28.             ESP_LOGI(TAG, "Timeout has been reached and nothing has been received");
  29.         } else {
  30.             ESP_LOGE(TAG, "Select: data is ready for reading");
  31.         }
  32.     };
  33. }
Panic back trace, but it's not so usefull:

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
Ilia Lutchenko
Embedded Engineer

lin_yi
Posts: 4
Joined: Fri Feb 03, 2023 9:54 am

Re: Bluetooth SPP in VFS mode and select()

Postby lin_yi » Thu Jul 27, 2023 12:50 am

Hello, did you solve the problem? I've met it now. Thank you.

Who is online

Users browsing this forum: No registered users and 105 guests