There is a bug in SDK versions prior to 3.5.2 (included), where the device fails to pair with a peer after the stock API "wiced_bt_set_local_bdaddr" is called.
And here are some workarounds for this issue. (without using the stock API at all)
1. assign BLE MAC address at compile time
2. change BLE MAC address at run time
The default BLE MAC used at run time is stored in APP_CODE binary.
It actually comes from libraries/drivers/bluetooth/firmware/<MODEL>/<FREQUENCY>/bt_firmware_image.c
Where <MODEL> and <FREQUENCY> can be found in platform definitions.
For example, in my case <MODEL>=43438A1, <FREQUENCY>=37_4MHz.
Find the stock BLE MAC address in the file and modify as you want. (the byte order may be different from your convention)
const uint8_t brcm_patchram_buf =
With the above modification BLE MAC address should be assigned at compile time.
To change BLE MAC address at run time we need to modify the content in APP_CODE (MCU internal flash) before BLE is brought up.
I do this right after "wiced_init" is called.
extern const uint8_t brcm_patchram_buf;
platform_write_flash_chunk((uint32_t)&brcm_patchram_buf[OFFSET_TO_MAC], new_mac, 6);
I'm still testing if this cause any further problems, but so far so good.
I'll be happy if this helps anyone, and I'll be appreciated if any bug/fix is provided as feedback.