ESP32 Bluetooth sending a string crashes if string len >12char

Any bugs you encounter with Flowcode should be discussed here.
stefan.erni
Valued Contributor
Posts: 738
http://meble-kuchenne.info.pl
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 149 times
Been thanked: 170 times

ESP32 Bluetooth sending a string crashes if string len >12char

Post by stefan.erni »

Hi Ben

If I send a string by bluetooth to the computer it's working fine if the string is less than 12char.

But if I send a string with more than 12 char, the ESP Bluetooth crash and need a reset(power on/off)

Sending a array of char is working fine even it's more than 20 byte.
I tested 512byte and it was working fine


regards

Stefan

mnfisher
Valued Contributor
Posts: 938
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: ESP32 Bluetooth sending a string crashes if string len >12char

Post by mnfisher »

Something is still wrong with the Bluetooth SendString.

If I send "Hello world\r\n" the serial program received a variable number of bytes from 'Hello' most commonly up to the full string occasionally.

Using SendArray works perfectly..

Looking at the code - SendString uses SendByte where SendArray uses PutBytes..

SendString also declares a 1 byte array buff - although this is never used?

Martin

stefan.erni
Valued Contributor
Posts: 738
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 149 times
Been thanked: 170 times

Re: ESP32 Bluetooth sending a string crashes if string len >12char

Post by stefan.erni »

Hi Martin

I have two device. One with a PIC32 and a RN4677 BT- Modul, the another device is a ESP32 (Bluetooth integrated)
With the RN4677 BT- Modul sending string is working fine. Maybe this has something to do with a buffer

regards

Stefan
BT_Capture.JPG
BT_Capture.JPG (85.71 KiB) Viewed 3876 times

mnfisher
Valued Contributor
Posts: 938
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: ESP32 Bluetooth sending a string crashes if string len >12char

Post by mnfisher »

Hi Stefan,

The problem occurs when sending from the ESP32 can you test this? - I don't think it's a reception issue as SendArray data is received perfectly.
(I used Blue Serial under Android to check the data..)

Martin

BenR
Matrix Staff
Posts: 1706
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: ESP32 Bluetooth sending a string crashes if string len >12char

Post by BenR »

Many thanks for letting us know. I've replicated the issue here and am now trying to work around it.

BenR
Matrix Staff
Posts: 1706
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: ESP32 Bluetooth sending a string crashes if string len >12char

Post by BenR »

Ok after a fair bit of digging and chopping and changing the CAL code I wasn't able to solve the problem. Even long delays and trying to add blocking calls to not call the write function until the last write function was complete did not yield any positive results.

However I did find a couple of leads via Google and found editing a line in the IDF library that does solve the problem.

It seems to be to do with flow control credits which are negotiated by the client and so the problem may not always manifest as we are seeing. Note I too was using an Android phone based serial monitor to see the data output.

Anyway to solve the problem I edited the file here.

esp-idf\components\bt\host\bluedroid\stack\rfcomm\rfc_utils.c

On line 468 comment out the line and save.

Code: Select all

p_port->tx.peer_fc = TRUE;
The end function now looks like this.

Code: Select all

void rfc_dec_credit (tPORT *p_port)
{
    if (p_port->rfc.p_mcb->flow == PORT_FC_CREDIT) {
        if (p_port->credit_tx > 0) {
            p_port->credit_tx--;
        }

        if (p_port->credit_tx == 0) {
            //p_port->tx.peer_fc = TRUE;
        }
    }
}
and now after compiling again it's working perfectly.

For reference this was the page I found with the fix.
https://www.esp32.com/viewtopic.php?t=5613

mnfisher
Valued Contributor
Posts: 938
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: ESP32 Bluetooth sending a string crashes if string len >12char

Post by mnfisher »

Thanks Ben,

Yes - seems to work AOK :-)

Martin

stefan.erni
Valued Contributor
Posts: 738
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 149 times
Been thanked: 170 times

Re: ESP32 Bluetooth sending a string crashes if string len >12char

Post by stefan.erni »

Hi Ben, Hi Martin

I have tested

I made the line as comment, but my sdkconfig was rewritten so I had to make the correction for Blutooth SPP again and long string sending works now. Then I made the lines active again and it still works. The RFC_utils.c may not be compiled every time.

a short time ago i was asking for an ESP32 pico. I think this is a good idea to prevent such a problem with the sdkconfig file
For this ESP32 PICO D4:
There is currently no BLE profile supported in Flowcode 9,
Unfortunately, the standard configuration from Flowcode for all ESP32 Device is set to Bluetooth BLE.
The configuration must always be changed manually to Bluetooth SPP and if you are not careful it will be set back later during compilation from Bluetooth SPP back to Bluetooth BLE.
Wouldn't the standard for Bluetooth be better
BluetoothSPP (and without debugger messages)?

viewtopic.php?f=4&t=375&start=10






regards

Stefan

stefan.erni
Valued Contributor
Posts: 738
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 149 times
Been thanked: 170 times

Re: ESP32 Bluetooth sending a string crashes if string len >12char

Post by stefan.erni »

Hi Ben,

You wrote:
Many thanks for letting us know. I've replicated the issue here and am now trying to work around it.
I did not understand that completely. Do you solve the problem somehow? or do I have to change this file?

regards

Stefan

stefan.erni
Valued Contributor
Posts: 738
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 149 times
Been thanked: 170 times

Re: ESP32 Bluetooth sending a string crashes if string len >12char

Post by stefan.erni »

Hi Ben

The file is changed but still a problem sending longer string. So I tried send

P1 15x char 0 //and it crashed
P2 15x byte char "0" (decimal 48) //working fine
P3 5x char 0 //working fine

Testet on Windows and Android

regards

Stefan
crash2_2022-01-26_18-52-41.jpg
crash2_2022-01-26_18-52-41.jpg (40.79 KiB) Viewed 3455 times

Code: Select all

/*******************************************************************************
**
** Function         rfc_dec_credit
**
** Description      The function is called when a UIH frame of user data is
**                  sent.  It decrements the credit count.  If credit count
**                  Reaches zero, peer_fc is set.
**
** Returns          void
**
*******************************************************************************/
void rfc_dec_credit (tPORT *p_port)
{
    if (p_port->rfc.p_mcb->flow == PORT_FC_CREDIT) {
        if (p_port->credit_tx > 0) {
            p_port->credit_tx--;
        }

        if (p_port->credit_tx == 0) {
            //p_port->tx.peer_fc = TRUE;
        }
    }
}


Post Reply