samples: bluetooth: add Device Name sample#745
Conversation
4ef7306 to
56936e4
Compare
|
You can find the documentation preview for this PR here. |
243b4e7 to
a8dce41
Compare
| #define STORAGE_OFFSET DT_REG_ADDR(STORAGE_NODE) | ||
| #define STORAGE_SIZE DT_REG_SIZE(STORAGE_NODE) |
There was a problem hiding this comment.
use partition macros for this
There was a problem hiding this comment.
@nordicjm Please give a suggestion here. This is the pattern used in other samples.
There was a problem hiding this comment.
DT_FIXED_PARTITION_ADDR() for address with #include <zephyr/devicetree/fixed-partitions.h>
There was a problem hiding this comment.
I tried DT_FIXED_PARTITION_ADDR() but it doesn't work for storage0_partition in this sample due to the DT layout:
rram@0
└── partitions
└── storage_partition (compatible = "fixed-subpartitions", reg = <0x61800 0x2000>)
├── peer_manager_partition (reg = <0x0 0x1000>)
└── storage0_partition (reg = <0x1000 0x1000>)
DT_FIXED_PARTITION_ADDR() is defined as DT_REG_ADDR(node) + DT_REG_ADDR(DT_GPARENT(node)), which assumes the standard flash → partitions → partition layout. With the extra fixed-subpartitions level in this project, the grandparent of storage0_partition is the partitions node, which has no reg property for the macro to read. This causes a compile error:
'DT_N_..._partitions_REG_IDX_0_VAL_ADDRESSU' undeclared
Pointing at storage_partition instead does compile, but then we'd be writing across the entire 0x2000 region and overlap with peer_manager_partition, which defeats the purpose of the sub-partition split.
I switched to the flash_map helpers, which handle this correctly:
#include <zephyr/storage/flash_map.h>
#define STORAGE_OFFSET FIXED_PARTITION_OFFSET(storage0_partition)
#define STORAGE_SIZE FIXED_PARTITION_SIZE(storage0_partition)That said, given the constraints here, maybe the original DT_REG_ADDR/DT_REG_SIZE was the cleaner solution after all.
@nordicjm what do you think?
There was a problem hiding this comment.
update to mapped partitions then this becomes a non-issue
There was a problem hiding this comment.
Oki, I will open a separate PR for the partition layout change since it's out of scope here.
There was a problem hiding this comment.
@nordicjm We are using
#define STORAGE_OFFSET DT_REG_ADDR(STORAGE_NODE)
#define STORAGE_SIZE DT_REG_SIZE(STORAGE_NODE)
in other samples in BM main, that is pointing to a NCS revision before mapped-partitions are introduced. We would like to get this in with the same pattern now and update the partition layout and usage repo-wide in a separate PR once the manifest is updated.
There was a problem hiding this comment.
Reverted back to using DT_REG_ADDR and DT_REG_SIZE for now until Device Tree is restructured properly
| :local: | ||
| :depth: 2 | ||
|
|
||
| The Device Name sample demonstrates how to read and write the BLE GAP Device Name characteristic using |BMlong|. |
There was a problem hiding this comment.
| The Device Name sample demonstrates how to read and write the BLE GAP Device Name characteristic using |BMlong|. | |
| The Device Name sample demonstrates how to read and write the Bluetooth LE GAP Device Name characteristic using |BMlong|. |
| :depth: 2 | ||
|
|
||
| The Device Name sample demonstrates how to read and write the BLE GAP Device Name characteristic using |BMlong|. | ||
| A connected peer can change the device name over BLE. The new name takes effect immediately, persists across disconnects, and survives power cycles. |
There was a problem hiding this comment.
| A connected peer can change the device name over BLE. The new name takes effect immediately, persists across disconnects, and survives power cycles. | |
| A connected peer can change the device name over Bluetooth LE. | |
| The new name takes effect immediately, persists across disconnects, and survives power cycles. |
a8dce41 to
9081805
Compare
| static struct ble_adv_config adv_cfg = { | ||
| .conn_cfg_tag = CONFIG_NRF_SDH_BLE_CONN_TAG, | ||
| .evt_handler = ble_adv_evt_handler, | ||
| .adv_data = { | ||
| .name_type = BLE_ADV_DATA_FULL_NAME, | ||
| .flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE, | ||
| }, | ||
| }; |
There was a problem hiding this comment.
We only need adv_data part for updating advertising data. Config can be in main or wherever adv_init is called.
There was a problem hiding this comment.
Oki, I think I understand what you meant, only adv_data really needs global scope since the BLE event handler uses it for ble_adv_data_update(). The rest of the config (conn_cfg_tag, evt_handler) is only needed once at ble_adv_init() time, so I moved that into main() as a local.
Please take a look and let me know if this is what you had in mind?
| goto idle; | ||
| } | ||
|
|
||
| LOG_INF("Device name set to: %.*s", saved_len, saved_name); |
There was a problem hiding this comment.
This is in practice the same information as the "advertising as ..." log below. I think this can be removed.
There was a problem hiding this comment.
I think it's worth keeping it. Setting the device name and initializing advertising are separate steps, so this log specifically confirms sd_ble_gap_device_name_set() succeeded. Might be useful if something later in the advertising setup fails. It's also consistent with the step-by-step logs used throughout init.
| nrf_gpio_pin_write(BOARD_PIN_LED_0, !BOARD_LED_ACTIVE_STATE); | ||
| nrf_gpio_pin_write(BOARD_PIN_LED_1, !BOARD_LED_ACTIVE_STATE); | ||
|
|
||
| LOG_INF("LEDs enabled"); |
There was a problem hiding this comment.
Not necessary for this sample.
There was a problem hiding this comment.
I'm not sure I follow what's unnecessary here. Most of the other Bluetooth samples use LEDs (and buttons) for interaction and visual feedback, why should this one be different?
There was a problem hiding this comment.
The log entry I mean.
There was a problem hiding this comment.
Ah ok, fixed
e4f3a11 to
25cf9fc
Compare
dc22253 to
c5bc75a
Compare
Add a new BLE sample demonstrating how a peer can read and write the GAP Device Name characteristic (UUID 0x2A00) over BLE. The sample: - Advertises with a configurable default device name. - Allows connected peers to write a new name with open permissions. - Updates the SoftDevice GAP name and advertising data immediately. - Persists the new name to flash (BM ZMS) so it survives reboots. - Loads the saved name from storage on boot, falling back to the Kconfig default if none exists. Includes sample documentation and changelog entry. Signed-off-by: Martynas Smilingis <martynas.smilingis@nordicsemi.no>
c5bc75a to
7b46fea
Compare
Add a new BLE sample demonstrating how a peer can read and write the GAP Device Name characteristic (UUID 0x2A00) over BLE.
The sample:
Includes sample documentation and changelog entry.