This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

WL1837MOD: Bluetopia - BSC_Initialize

Part Number: WL1837MOD
Other Parts Discussed in Thread: WL1835

Hello,

I'm working with the Wl1835 chipset and with bluetopia stack found here: www.ti.com/.../TI-BT-4-2-STACK-LINUX-ADDON

I need to set a random address for the Bluetooth hardware address and I can see that this is an option in GAPAPI.h with GAP_LE_Generate_Static_Address(unsigned int BluetoothStackID, BD_ADDR_t *StaticAddress_Result);

To get a BluetoothStackID, one must call BSC_Initialize which returns the id. I ran into this issue a while back and opened a ticket: https://e2e.ti.com/support/wireless-connectivity/wi-fi-group/wifi/f/wi-fi-forum/1021524/wl1837mod-bluetopia-bsc_initialize

I am encountering the same issue here. Running the following snippet of code yields the following result:


 HCI_DriverInformation_t driverInfo;
  char portName[32] = "/dev/ttymxc4";

  driverInfo.DriverType = hdtCOMM;
  driverInfo.DriverInformation.COMMDriverInformation.COMPortNumber = -1;
  driverInfo.DriverInformation.COMMDriverInformation.DriverInformationSize = sizeof(driverInfo.DriverInformation.COMMDriverInformation);
  driverInfo.DriverInformation.COMMDriverInformation.Protocol = cpUART;
  driverInfo.DriverInformation.COMMDriverInformation.BaudRate = 115200;
  driverInfo.DriverInformation.COMMDriverInformation.InitializationDelay = 100;
  driverInfo.DriverInformation.COMMDriverInformation.COMDeviceName = portName;
  driverInfo.DriverInformation.COMMDriverInformation.Flags = 0;

  int btStackId = BSC_Initialize(&driverInfo, 0);

  printf("application: bt stackid: %d\n\n", btStackId);

Executing:

root@QConnect:~# ./blooTest
Error: Can't open /proc/device-tree/tibt/dev_nameError: Can't open /proc/device-tree/tibt/baud_rateError: Can't open /proc/device-tree/tibt/flow_cntrlError: Can't open /proc/device-tree/tibt/nshutdown_gpioecho 0 > /sys/class/gpio/export
sh: write error: Resource busy
echo out > /sys/class/gpio/gpio0/direction
echo 0 > /sys/class/gpio/gpio0/value
echo 1 > /sys/class/gpio/gpio0/value
echo 0 > /sys/class/gpio/gpio0/value
echo 1 > /sys/class/gpio/gpio0/value
BT COMM PORT (): -5
application: bt stackid: -14

I'm unsure why its attempting to toggle gpio 0 when there is not a parameter to provide a gpio number.

  • Hi Andrew,

    As you point out, the error you're getting is probably the same as the one from your linked thread - BSC_Initialize() is not working as expected.

    Assuming you haven't called BSC_Initialize() or otherwise initialized the BT stack at some other point in your system, it seems like there might be some issue with getting the right HW configuration.

    Looking at your previous thread, it looks like the correct nShutdown GPIO to use for your system is GPIO 115. Yet it seems like your application is attempting to use GPIO0 for some reason. Debugging why your application appears to ignore the BT config you have (that the SDK examples are using) I think is the key.

    Looking at the MCU example code, it looks like the GPIO and HW setup is done in a separate HAL function, so that's not so useful to us. Of more use is the basic non-platform manager Linux demo code, which actually demonstrates the use of that BSC_Initialize() function. I unfortunately don't have access to that code since it's not online as far as I can tell. I also don't have access to a Linux dev platform to demo that function in any case. So a TI engineer will need to look at and ideally provide that example code that uses that BSC_Initialize() function.

    The one wrinkle is that if I remember correctly, the GPIO toggle needed to deassert nHib is not actually handled in that BSC_Initialize function. So TI will need to see where exactly that GPIO toggle happens for Linux platforms and provide guidance there.

    Regards,
    Michael

  • Hi Andrew and Michael,

    I'll look into this and follow up later this week.

    Thanks,
    Jacob

  • Hi Jacob,

    Update on where we're at:

    I'm able to use BSC_Initialize properly on the AM335x EVM. So it would seem the problem was related to our custom board and OS.  We were able to recompile the Bluetopia stack to get the BSC_init function to work properly.

    However, when trying to use GAP_LE_Set_Random_Address(unsigned int BluetoothStackID, BD_ADDR_t RandomAddress); then starting SS1BTPM and using a sample application to query the BLE address, the address I attempted to assign does not seem to take effect.

    Would you have any insight on how to set the BLE address properly?

  • Hi Andrew,

    Thanks for the update. I'll look into the stack and follow up by Wednesday.

    Thanks,
    Jacob

  • Hi Andrew,

    A few questions:

    1. How are you providing the random BT address? Is it a hardcoded value you provide in your function call?

    2. Do you see any different results when calling GAP_LE_Generate_Static_Address()?

    3. Are you receiving any error codes?

    I believe the GAP_LE_Set_Random_Address() is the correct function to use to generate a random BT address. If there are no errors in your function calls, I can try replicating this on my end.

    Thanks,
    Jacob

  • Hi Jacob,

    1. I am using a hardcoded value for test purposes. I set the structure BD_ADDR_t.

    2. When I use GAP_LE_Generate_Static_Address I can generate a unique static BD_ADDR_t, but then when I set this using GAP_LE_Set_Random_Address and then attempt to read back my address, it does not read back the value I set.

    3. I do not receive any error codes. GAP_LE_Set_Random_Address returns 0 (success).

    see reference code below:

        int btStackId = BSC_Initialize(&driverInfo, 0);

        printf("int: Bluetooth stack controller: %d\n\n", btStackId);

        InitializeGAPLEModule();

        GAP_LE_Generate_Static_Address(btStackId, &myAddr);

        BD_ADDRToStr(myAddr, addrStr);

        printf("generated addr: %s\n", addStr);

        result = GAP_LE_Set_Random_Address(btStackId, myAddr);

        printf("set mac address: %d\n\n", result);

    I then read it back with DEVM_QueryLocalDeviceProperties() and view the BLE address.
    Note that i tried this on the AM335x as well.

  • Hi Jacob,

    Another point worth mentioning, and what I believe may be the issue:


    I build a standalone program to set the BLE hardware address. This program is linked with object files BTPS, BTPS_OSA, and BTPS_PLA.
    This program is to be executed when our device boots.

    When a different program linked with BTPM_C, BTPM_HAL_C, BTPM_HAL_S, and BTPM_S is executed, it again toggles the GPIO pin to power on the BT module, therefore restarting Bluetopia platform manager and resetting the BLE hardware address.

    Please note: Attempting to link these two sets of object files together and then set and read the address in the same program causes compilation error. 

    Can these two sets of object files be linked together in the same program?

    Bluetopia compiler error.txt
    [main] Building folder: test_bluetopia 
    [build] Starting build
    [proc] Executing command: /usr/bin/cmake --build /home/acisneros/AM335x/test_bluetopia/build --config Debug --target all -j 6 --
    [build] Scanning dependencies of target setMac
    [build] [ 50%] Building C object CMakeFiles/setMac.dir/setMac.c.o
    [build] [100%] Linking C executable setMac
    [build] /home/acisneros/AM335x/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/../lib/gcc/arm-none-linux-gnueabihf/9.2.1/../../../../arm-none-linux-gnueabihf/bin/ld: /home/acisneros/AM335x/test_bluetopia/./bluetopia/libs/libBTPS.a(SDP.o): in function `SDP_Delete_Service_Record':
    [build] SDP.c:(.text+0x4710): multiple definition of `SDP_Delete_Service_Record'; /home/acisneros/AM335x/test_bluetopia/./bluetopia/libs/libBTPM_C.a(AVRCPUTIL_C.o):AVRCPUTIL.c:(.text+0x10): first defined here
    [build] /home/acisneros/AM335x/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/../lib/gcc/arm-none-linux-gnueabihf/9.2.1/../../../../arm-none-linux-gnueabihf/bin/ld: /home/acisneros/AM335x/test_bluetopia/./bluetopia/libs/libBTPS.a(SDP.o): in function `SDP_Add_Attribute':
    [build] SDP.c:(.text+0x4804): multiple definition of `SDP_Add_Attribute'; /home/acisneros/AM335x/test_bluetopia/./bluetopia/libs/libBTPM_C.a(AVRCPUTIL_C.o):AVRCPUTIL.c:(.text+0x8): first defined here
    [build] collect2: error: ld returned 1 exit status
    [build] make[2]: *** [CMakeFiles/setMac.dir/build.make:84: setMac] Error 1
    [build] make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/setMac.dir/all] Error 2
    [build] make: *** [Makefile:84: all] Error 2
    [build] Build finished with exit code 2

  • Hi Andrew,

    Thank you for the update. I would assume that these two programs should be able to be linked together as long as they do not have differing object files. In any case, are you able to combine your two programs to see if that is the root cause?

    Thanks,
    Jacob

  • Hi Jacob,

    I built a new program using only the BTPS set of object files. There's a separate api function call I can use to query the hardware address: GAP_Query_Local_BD_ADDR(btStackId, &newAddr);
    see attached source code and run output

    setting ble address.txt
    int main (void) 
    {
        HCI_DriverInformation_t driverInfo;
        BD_ADDR_t myAddr;
        BD_ADDR_t newAddr;
        char addrStr[32];
        int result;
        
        myAddr.BD_ADDR0 = 0xF3;
        myAddr.BD_ADDR1 = 0x12;
        myAddr.BD_ADDR2 = 0xCC;
        myAddr.BD_ADDR3 = 0x53;
        myAddr.BD_ADDR4 = 0x67;
        myAddr.BD_ADDR5 = 0x34;
        
        char portName[32] = "/dev/ttyS1";
        driverInfo.DriverType = hdtCOMM;
        driverInfo.DriverInformation.COMMDriverInformation.COMPortNumber = -1;
        driverInfo.DriverInformation.COMMDriverInformation.DriverInformationSize = sizeof(driverInfo.DriverInformation.COMMDriverInformation);
        driverInfo.DriverInformation.COMMDriverInformation.Protocol = cpUART;
        driverInfo.DriverInformation.COMMDriverInformation.BaudRate = 3000000;
        driverInfo.DriverInformation.COMMDriverInformation.InitializationDelay = 100;
        driverInfo.DriverInformation.COMMDriverInformation.COMDeviceName = portName;
        driverInfo.DriverInformation.COMMDriverInformation.Flags = 0;
        
        
        int btStackId = BSC_Initialize(&driverInfo, 0);
    
        printf("int: Bluetooth stack controller: %d\n\n", btStackId);
    
        result = InitializeGAPLEModule();
    
        printf("init gap le: %d\n", result);
    
        result = GAP_LE_Set_Random_Address(btStackId, myAddr);
    
        printf("set mac address: %d\n\n", result);
    
        GAP_Query_Local_BD_ADDR(btStackId, &newAddr);
    
        BD_ADDRToStr(newAddr, addrStr);
    
        printf("BLE address: %s\n\n", addrStr );
    
        return 0;
    }
    
    
    
    root@am335x-evm:~# ./setMac
    echo 117 > /sys/class/gpio/export
    sh: line 0: echo: write error: Device or resource busy
    echo out > /sys/class/gpio/gpio117/direction
    echo 0 > /sys/class/gpio/gpio117/value
    echo 1 > /sys/class/gpio/gpio117/value
    echo 0 > /sys/class/gpio/gpio117/value
    echo 1 > /sys/class/gpio/gpio117/value
    BT COMM PORT (/dev/ttyS1): 1
    Changing HCI baud rate to 3000000
    Status: Executing BTS Script /lib/firmware/TIInit_11.8.32.bts.
    Status: BTS Script successfully executed.
    int: Bluetooth stack controller: 1
    
    init gap le: 0
    set mac address: 0
    
    BLE address: 506583298F36
    
    root@am335x-evm:~#
    
    


    However, the address remains unchanged. I receive the same results on the AM335x.

    Could you please attempt to set your Bluetooth low energy address? Thank you

  • Hi Andrew,

    I can try to test this for you tomorrow.

    Best,
    Jacob

  • Hi Jacob,

    Thank you very much.

    Andrew

  • Hi Jacob,

    I resolved this issue by using a hci command to set the address. Thanks for the help.

    Andrew

  • Glad to hear it Andrew!

    Thank you for contributing to this forum.

    Best regards,

    Jacob

  • Out of curiosity, which HCI command solved your issue?

  • Hi Jacob,

    On each boot of our device we use SS1Tool to write the Bluetooth public address

    SS1Tool cmd 0x3f 0x0006 0x4c 0xbc 0x98 0x20 0x00 0x005, where 0x4c 0xbc 0x98 0x20 0x00 0x005  is the address.

    Command to read ./SS1Tool cmd 0x04 0x0009.
    Then when we advertising with DEVM_StartAdvertising(DEVM_Advertising_Information_t   AdvertisingInfo) ,
    The advertising flags is set to:
    AdvertisingInfo.AdvertisingFlags = 0x00000014 | 0x00000001
    0x00000001 flag allows us to advertise with the public address we set with the hci command
    #define DEVM_ADVERTISING_INFORMATION_FLAGS_USE_PUBLIC_ADDRESS                   0x00000001
    #define DEVM_ADVERTISING_INFORMATION_FLAGS_DISCOVERABLE                         0x00000002
    #define DEVM_ADVERTISING_INFORMATION_FLAGS_CONNECTABLE                          0x00000004
    #define DEVM_ADVERTISING_INFORMATION_FLAGS_ADVERTISE_DEVICE_NAME                0x00000010
    #define DEVM_ADVERTISING_INFORMATION_FLAGS_ADVERTISE_TX_POWER                   0x00000020
    #define DEVM_ADVERTISING_INFORMATION_FLAGS_ADVERTISE_APPEARANCE                 0x00000040
    #define DEVM_ADVERTISING_INFORMATION_FLAGS_PEER_USE_PUBLIC_ADDRESS              0x00000100
    #define DEVM_ADVERTISING_INFORMATION_FLAGS_DIRECT_CONNECTABLE_MODE              0X00000200
    #define DEVM_ADVERTISING_INFORMATION_FLAGS_LOW_DUTY_CYCLE_DIRECT_CONNECTABLE    0x00000400