IAR 7.50; KW40Z_Connectivity_Software_1.0.1 (KSDK_1.3.0)
As the Bluetooth stack comes pre-compiled a variable interface is gBDAddress_c.
How to change at runtime this address ?
KW40Z_Connectivity_Software_1.0.1\ConnSw\examples\bluetooth\common\ble_controller_task.c
/* Public Device Address */
const uint8_t gBDAddress_c[6] = {BD_ADDR};
app_preinclude.h
#define BD_ADDR 0x13,0x00,0x00,0x9F,0x04,0x00
I find it easy to change the definition by removing the const part, is it ok ?
Other ways that I can think of is some volatile keyword added ?
What is the solution as this definition may have an external counterpart linked in host stack.
Solved! Go to Solution.
Hi Lucian
You can change it if you remove the const type qualifier, but the BD address is used when scanning/advertising, initiating connections, when performing the BLE pairing using SMP, the BDADDR is used internally to confirm identity, etc. So it must not be changed in runtime this BD_ADDRS. Normally in a use case, in your application you set the BD_ADDRS, and you keep that address for the all the BLE application. Note: if you reset the device and this address is random generated, it remain the same logic, you only set it once and it doesn't change.
Hope this information helps you
Have a great day,
Jorge Alcala
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Lucian
You can change it if you remove the const type qualifier, but the BD address is used when scanning/advertising, initiating connections, when performing the BLE pairing using SMP, the BDADDR is used internally to confirm identity, etc. So it must not be changed in runtime this BD_ADDRS. Normally in a use case, in your application you set the BD_ADDRS, and you keep that address for the all the BLE application. Note: if you reset the device and this address is random generated, it remain the same logic, you only set it once and it doesn't change.
Hope this information helps you
Have a great day,
Jorge Alcala
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
So I can change the BLE MAC address inside hardware_init ?
ApplMain.c
....
void main_task(uint32_t param)
{
....hardware_init();
....
/* Initialize peripheral drivers specific to the application */
BleApp_Init();
/* BLE Radio Init */
XcvrInit(BLE);...
Hi Lucian
Yes, before any connection and it shouldn't change. Or you could change it in the macro define #define BD_ADDR
Hope this information helps you
Have a great day,
Jorge Alcala
This variable is most likely exported in the host stack ble_controller_lib.a
Changing is type can lead to unwanted unpredictable behaviour ?