Skip to content

Commit 63f67f6

Browse files
ludvigsjrlubos
authored andcommitted
Samples: Bluetooth: ISO time sync fixes
This commit fixes the following: * Fix a bug in the initialization of `init_val` in the GPIOTE task used for the LED, where it would always be initialized to `NRF_GPIOTE_INITIAL_VALUE_HIGH` and not take the dt_flags into account. This made the LED toggle with inverted polarity on platforms where the LEDs are active high. * Change the LED used when `CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE` is enabled to not conflict with the LED used to display synchronized toggling. * Update references to LED numbers in the README to match the actual sample behavior. Signed-off-by: Ludvig Jordet <[email protected]>
1 parent a10710c commit 63f67f6

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

samples/bluetooth/iso_time_sync/README.rst

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ The sample demonstrates the following features:
4040
.. group-tab:: nRF52 and nRF53 DKs
4141

4242
This sample configures a single device as a transmitter of its **Button 1** state.
43-
The transmitting and receiving devices toggle **LED 1** synchronously with the accuracy of a few microseconds.
44-
When the :ref:`CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE <CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE>` Kconfig option is enabled, **LED 2** is toggled upon sending or receiving data.
43+
The transmitting and receiving devices toggle **LED 2** synchronously with the accuracy of a few microseconds.
44+
When the :ref:`CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE <CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE>` Kconfig option is enabled, **LED 1** is toggled upon sending or receiving data.
4545
This allows you to measure the minimal end-to-end latency.
4646

4747
.. group-tab:: nRF54 DKs
4848

4949
This sample configures a single device as a transmitter of its **Button 0** state.
50-
The transmitting and receiving devices toggle **LED 0** synchronously with the accuracy of a few microseconds.
51-
When the :ref:`CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE <CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE>` Kconfig option is enabled, **LED 1** is toggled upon sending or receiving data.
50+
The transmitting and receiving devices toggle **LED 1** synchronously with the accuracy of a few microseconds.
51+
When the :ref:`CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE <CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE>` Kconfig option is enabled, **LED 0** is toggled upon sending or receiving data.
5252
This allows you to measure the minimal end-to-end latency.
5353

5454
.. note::
@@ -69,7 +69,7 @@ Check and configure the following Kconfig options:
6969
.. _CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE:
7070

7171
CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE
72-
This configuration option enables immediate toggling of **LED 2** (nRF52 and nRF53 DKs) or **LED 1** (nRF54 DKs) when isochronous data is sent or received.
72+
This configuration option enables immediate toggling of **LED 1** (nRF52 and nRF53 DKs) or **LED 0** (nRF54 DKs) when isochronous data is sent or received.
7373
It allows for measurement of the minimum end-to-end latency.
7474

7575
.. _CONFIG_SDU_INTERVAL_US:
@@ -180,9 +180,9 @@ The sample code is divided into multiple source files, which makes it easier to
180180

181181
When a valid SDU is received, the following operations are performed:
182182

183-
* If the :ref:`CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE <CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE>` Kconfig option is enabled, **LED 2** is toggled immediately.
183+
* If the :ref:`CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE <CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE>` Kconfig option is enabled, **LED 1** is toggled immediately.
184184
You can use this to observe that different receivers may receive the SDU at different points in time.
185-
* A timer trigger is configured to toggle **LED 1** :ref:`CONFIG_TIMED_LED_PRESENTATION_DELAY_US <CONFIG_TIMED_LED_PRESENTATION_DELAY_US>` after the received timestamp.
185+
* A timer trigger is configured to toggle **LED 2** :ref:`CONFIG_TIMED_LED_PRESENTATION_DELAY_US <CONFIG_TIMED_LED_PRESENTATION_DELAY_US>` after the received timestamp.
186186
This ensures that all receivers and the transmitter toggle it at the same time.
187187

188188
``iso_tx.c``
@@ -195,9 +195,9 @@ The sample code is divided into multiple source files, which makes it easier to
195195
* The SDU is transmitted on all the established isochronous channels with the same timestamp.
196196
This ensures that all the receivers can toggle their corresponding LEDs at the same time.
197197
The very first SDU is provided without a timestamp, because the timestamp is not known at this point in time.
198-
* **LED 1** is configured to toggle synchronously with the **LED 1** on all the receivers.
198+
* **LED 2** is configured to toggle synchronously with the **LED 2** on all the receivers.
199199
The toggle time is determined by the TX timestamp and defined relative to the synchronization reference on the receiver.
200-
* If the :ref:`CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE <CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE>` Kconfig option is enabled, **LED 2** is toggled right before sending the SDU.
200+
* If the :ref:`CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE <CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE>` Kconfig option is enabled, **LED 1** is toggled right before sending the SDU.
201201
You can use this to observe the end-to-end latency.
202202

203203
``timed_led_toggle.c``
@@ -257,9 +257,9 @@ The sample code is divided into multiple source files, which makes it easier to
257257

258258
When a valid SDU is received, the following operations are performed:
259259

260-
* If the :ref:`CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE <CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE>` Kconfig option is enabled, **LED 1** is toggled immediately.
260+
* If the :ref:`CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE <CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE>` Kconfig option is enabled, **LED 0** is toggled immediately.
261261
You can use this to observe that different receivers may receive the SDU at different points in time.
262-
* A timer trigger is configured to toggle **LED 0** :ref:`CONFIG_TIMED_LED_PRESENTATION_DELAY_US <CONFIG_TIMED_LED_PRESENTATION_DELAY_US>` after the received timestamp.
262+
* A timer trigger is configured to toggle **LED 1** :ref:`CONFIG_TIMED_LED_PRESENTATION_DELAY_US <CONFIG_TIMED_LED_PRESENTATION_DELAY_US>` after the received timestamp.
263263
This ensures that all receivers and the transmitter toggle it at the same time.
264264

265265
``iso_tx.c``
@@ -272,9 +272,9 @@ The sample code is divided into multiple source files, which makes it easier to
272272
* The SDU is transmitted on all the established isochronous channels with the same timestamp.
273273
This ensures that all the receivers can toggle their corresponding LEDs at the same time.
274274
The very first SDU is provided without a timestamp, because the timestamp is not known at this point in time.
275-
* **LED 0** is configured to toggle synchronously with the **LED 0** on all the receivers.
275+
* **LED 1** is configured to toggle synchronously with the **LED 1** on all the receivers.
276276
The toggle time is determined by the TX timestamp and defined relative to the synchronization reference on the receiver.
277-
* If the :ref:`CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE <CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE>` Kconfig option is enabled, **LED 1** is toggled right before sending the SDU.
277+
* If the :ref:`CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE <CONFIG_LED_TOGGLE_IMMEDIATELY_ON_SEND_OR_RECEIVE>` Kconfig option is enabled, **LED 0** is toggled right before sending the SDU.
278278
You can use this to observe the end-to-end latency.
279279

280280
``timed_led_toggle.c``
@@ -318,7 +318,7 @@ After programming the sample to the development kits, perform the following step
318318
#. Select which BIS the receiver should synchronize to.
319319
#. Observe that the device(s) synchronize to the broadcaster and start receiving isochronous data.
320320
#. Press **Button 1** on the broadcaster.
321-
#. Observe that **LED 1** toggles on both the broadcaster and the receivers.
321+
#. Observe that **LED 2** toggles on both the broadcaster and the receivers.
322322

323323
.. group-tab:: nRF54 DKs
324324

@@ -331,7 +331,7 @@ After programming the sample to the development kits, perform the following step
331331
#. Select which BIS the receiver should synchronize to.
332332
#. Observe that the device(s) synchronize to the broadcaster and start receiving isochronous data.
333333
#. Press **Button 0** on the broadcaster.
334-
#. Observe that **LED 0** toggles on both the broadcaster and the receivers.
334+
#. Observe that **LED 1** toggles on both the broadcaster and the receivers.
335335

336336
Testing connected isochronous streams
337337
=====================================
@@ -353,7 +353,7 @@ After programming the sample to the development kits, perform the following step
353353
#. Select data direction.
354354
#. Observe that the peripheral(s) connect to the central and start receiving isochronous data.
355355
#. Press **Button 1** on the central device.
356-
#. Observe that **LED 1** toggles on both the central and peripheral devices.
356+
#. Observe that **LED 2** toggles on both the central and peripheral devices.
357357

358358
.. group-tab:: nRF54 DKs
359359

@@ -368,7 +368,7 @@ After programming the sample to the development kits, perform the following step
368368
#. Select data direction.
369369
#. Observe that the peripheral(s) connect to the central and start receiving isochronous data.
370370
#. Press **Button 0** on the central device.
371-
#. Observe that **LED 0** toggles on both the central and peripheral devices.
371+
#. Observe that **LED 1** toggles on both the central and peripheral devices.
372372

373373

374374
Observe time-synchronized ISO data processing
@@ -378,12 +378,12 @@ Observe time-synchronized ISO data processing
378378

379379
.. group-tab:: nRF52 and nRF53 DKs
380380

381-
When you press **Button 1** on the transmitting device, you can observe that **LED 1** toggles simultaneously on all devices.
381+
When you press **Button 1** on the transmitting device, you can observe that **LED 2** toggles simultaneously on all devices.
382382
To observe the accurate toggling, use a logic analyzer or an oscilloscope.
383383

384384
.. group-tab:: nRF54 DKs
385385

386-
When you press **Button 0** on the transmitting device, you can observe that **LED 0** toggles simultaneously on all devices.
386+
When you press **Button 0** on the transmitting device, you can observe that **LED 1** toggles simultaneously on all devices.
387387
To observe the accurate toggling, use a logic analyzer or an oscilloscope.
388388

389389
Sample output

samples/bluetooth/iso_time_sync/src/iso_rx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static void iso_disconnected(struct bt_iso_chan *chan, uint8_t reason);
2626

2727
static void (*iso_chan_disconnected_cb)(void);
2828

29-
static struct gpio_dt_spec led_sdu_received = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led1), gpios, {0});
29+
static struct gpio_dt_spec led_sdu_received = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios, {0});
3030

3131
static struct bt_iso_chan_ops iso_ops = {
3232
.recv = iso_recv,

samples/bluetooth/iso_time_sync/src/iso_tx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "iso_time_sync.h"
3131

3232
static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(DT_ALIAS(sw0), gpios, {0});
33-
static struct gpio_dt_spec led_on_sdu_send = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led1), gpios, {0});
33+
static struct gpio_dt_spec led_on_sdu_send = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios, {0});
3434

3535
static void iso_sent(struct bt_iso_chan *chan);
3636
static void iso_connected(struct bt_iso_chan *chan);

samples/bluetooth/iso_time_sync/src/timed_led_toggle.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ int timed_led_toggle_init(void)
5454
const nrfx_gpiote_task_config_t task_cfg_led_toggle = {
5555
.task_ch = gpiote_chan_led_toggle,
5656
.polarity = NRF_GPIOTE_POLARITY_TOGGLE,
57-
.init_val = (led.dt_flags & GPIO_ACTIVE_HIGH) ?
58-
NRF_GPIOTE_INITIAL_VALUE_LOW : NRF_GPIOTE_INITIAL_VALUE_HIGH,
57+
.init_val = (led.dt_flags & GPIO_ACTIVE_LOW) ?
58+
NRF_GPIOTE_INITIAL_VALUE_HIGH : NRF_GPIOTE_INITIAL_VALUE_LOW,
5959
};
6060

6161
if (nrfx_gpiote_output_configure(&gpiote, LED_PIN, &gpiote_output_cfg,

0 commit comments

Comments
 (0)