Skip to content

Commit 90927ea

Browse files
committed
ab: Change slot selection buttons
Change the behavior of the buttons in the A/B sample from toggling into the other slot to binding each button to a single slot (button 0 -> slot A, button 1 -> slot B). Ref: NCSDK-36121 Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 72c2093 commit 90927ea

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

samples/dfu/ab/README.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ Otherwise, it is running from slot A.
7272
If the project does not use the Partition Manager (a configuration currently only supported on the nRF54H20), the currently running slot can be identified by comparing the address pointed `zephyr,code-partition` to specific node addresses defined in the device tree.
7373
The following node partitions are used by default:
7474

75-
* ``slot0_partition`` - Application core, slot A
76-
* ``slot1_partition`` - Application core, slot B
75+
* ``cpuapp_slot0_partition`` - Application core, slot A
76+
* ``cpuapp_slot1_partition`` - Application core, slot B
7777
* ``cpurad_slot0_partition`` - Radio core, slot A
7878
* ``cpurad_slot1_partition`` - Radio core, slot B
7979

@@ -83,7 +83,7 @@ For example, verifying that the application is running from slot A can be done b
8383
8484
#define IS_RUNNING_FROM_SLOT_A \
8585
(FIXED_PARTITION_NODE_OFFSET(DT_CHOSEN(zephyr_code_partition)) == \
86-
FIXED_PARTITION_OFFSET(slot0_partition))
86+
FIXED_PARTITION_OFFSET(cpuapp_slot0_partition))
8787
8888
.. _ab_build_files:
8989

@@ -123,7 +123,11 @@ LED 1:
123123
It will remain off if the application is running from slot A.
124124

125125
Button 0:
126-
By pressing this button, the non-active slot will be selected as the preferred slot on the next reboot.
126+
By pressing this button, the slot A will be selected as the preferred slot on the next reboot.
127+
This preference applies only to the next boot and is cleared after the subsequent reset.
128+
129+
Button 1:
130+
By pressing this button, the slot B will be selected as the preferred slot on the next reboot.
127131
This preference applies only to the next boot and is cleared after the subsequent reset.
128132

129133
Configuration

samples/dfu/ab/src/ab_utils.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,18 @@ static void device_healthcheck(void)
164164
}
165165
}
166166

167-
static void toggle_slot_for_single_boot(void)
167+
static void select_slot_for_single_boot(enum ab_boot_slot slot)
168168
{
169169
int err = 0;
170-
enum ab_boot_slot active_slot = active_boot_slot_get();
170+
char active_slot = (active_boot_slot_get() == SLOT_A) ? 'A' : 'B';
171171
enum boot_slot new_slot = BOOT_SLOT_NONE;
172172

173-
if (active_slot == SLOT_A) {
174-
LOG_INF("Temporarily switching slots (A -> B)");
175-
new_slot = BOOT_SLOT_SECONDARY;
176-
} else if (active_slot == SLOT_B) {
177-
LOG_INF("Temporarily switching slots (B -> A)");
173+
if (slot == SLOT_A) {
174+
LOG_INF("Temporarily switching slots (%c -> A)", active_slot);
178175
new_slot = BOOT_SLOT_PRIMARY;
176+
} else if (slot == SLOT_B) {
177+
LOG_INF("Temporarily switching slots (%c -> B)", active_slot);
178+
new_slot = BOOT_SLOT_SECONDARY;
179179
} else {
180180
LOG_ERR("Cannot determine active slot, cannot toggle");
181181
return;
@@ -206,7 +206,9 @@ static void boot_state_report(void)
206206
static void button_handler(uint32_t button_state, uint32_t has_changed)
207207
{
208208
if ((has_changed & DK_BTN1_MSK) && (button_state & DK_BTN1_MSK)) {
209-
toggle_slot_for_single_boot();
209+
select_slot_for_single_boot(SLOT_A);
210+
} else if ((has_changed & DK_BTN2_MSK) && (button_state & DK_BTN2_MSK)) {
211+
select_slot_for_single_boot(SLOT_B);
210212
}
211213
}
212214

0 commit comments

Comments
 (0)