Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b054c12

Browse files
committedMar 17, 2025·
applications: nrf5340_audio: Buildprog, pristine and flashing issue
Buildprog issues with building and programming single cores. Signed-off-by: Graham Wacey <graham.wacey@nordicsemi.no>
1 parent 76259e0 commit b054c12

File tree

4 files changed

+89
-63
lines changed

4 files changed

+89
-63
lines changed
 

‎applications/nrf5340_audio/doc/building.rst

+10-3
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ The command can be run from any location, as long as the correct path to :file:`
113113

114114
The build files are saved in separate subdirectories in the :file:`applications/nrf5340_audio/build` directory.
115115
The script creates a directory for each application version and device type combination.
116-
For example, when running the command above, the script creates the :file:`dev_gateway/build_debug` and :file:`dev_headset/build_debug` directories.
116+
For example, when running the command above, the script creates the :file:`unicast/gateway/app` and :file:`unicast/headset/app` directories.
117117

118118
Script parameters for programming
119119
---------------------------------
@@ -259,6 +259,13 @@ Complete the following steps to build the application:
259259
* For headset device: ``-DCONFIG_AUDIO_DEV=1``
260260
* For gateway device: ``-DCONFIG_AUDIO_DEV=2``
261261

262+
#. Choose the configuration file for the device selected by using one of the following options:
263+
264+
* For unicast headset: ``-DEXTRA_CONF_FILE=".\unicast_server\overlay-unicast_server.conf"``
265+
* For unicast gateway: ``-DEXTRA_CONF_FILE=".\unicast_client\overlay-unicast_client.conf"``
266+
* For broadcast headset: ``-DEXTRA_CONF_FILE=".\broadcast_sink\overlay-broadcast_sink.conf"``
267+
* For broadcast gateway: ``-DEXTRA_CONF_FILE=".\broadcast_source\overlay-broadcast_source.conf"``
268+
262269
#. Choose the application version (:ref:`nrf53_audio_app_building_config_files`) by using one of the following options:
263270

264271
* For the debug version: No build flag needed.
@@ -269,9 +276,9 @@ Complete the following steps to build the application:
269276

270277
.. code-block:: console
271278
272-
west build -b nrf5340_audio_dk/nrf5340/cpuapp --pristine -- -DCONFIG_AUDIO_DEV=1 -DFILE_SUFFIX=release
279+
west build -b nrf5340_audio_dk/nrf5340/cpuapp --pristine -- -DCONFIG_AUDIO_DEV=1 -DEXTRA_CONF_FILE=".\unicast_server\overlay-unicast_server.conf" -DFILE_SUFFIX=release
273280
274-
This command creates the build files for headset device directly in the :file:`build` directory.
281+
This command creates the build files for a unicast headset device directly in the :file:`build` directory.
275282
What this means is that you cannot create build files for all devices you want to program, because the subsequent commands will overwrite the files in the :file:`build` directory.
276283

277284
To work around this standard west behavior, you can add the ``-d`` parameter to the ``west`` command to specify a custom build folder for each device.

‎applications/nrf5340_audio/doc/configuration.rst

+11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ By default, if you have not made any changes to :file:`.conf` files at :file:`ap
1313

1414
.. _nrf53_audio_app_configuration_select_build:
1515

16+
Selecting broadcast or unicast build
17+
************************************
18+
19+
Given the nRF5340 Audio :ref:`application architecture <nrf53_audio_app_overview>`, the nRF5340 Audio applications can be built for :ref:`either the broadcast or the unicast role <nrf53_audio_app_overview_broadcast_unicast>`:
20+
21+
* The unicast build is identified with :kconfig:option:`CONFIG_TRANSPORT_CIS` Kconfig option set to ``y``.
22+
This is the default configuration.
23+
* The broadcast build can be selected by adding :kconfig:option:`CONFIG_TRANSPORT_BIS` Kconfig option set to ``y`` to the :file:`prj.conf` file.
24+
25+
.. _nrf53_audio_app_configuration_select_transport:
26+
1627
Selecting gateway or headset build
1728
**********************************
1829

‎applications/nrf5340_audio/tools/buildprog/buildprog.py

+43-39
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@
4242
os.getenv("AUDIO_KIT_SERIAL_NUMBERS_JSON"))
4343
TARGET_BOARD_NRF5340_AUDIO_DK_APP_NAME = "nrf5340_audio_dk/nrf5340/cpuapp"
4444

45-
TARGET_CORE_APP_FOLDER = NRF5340_AUDIO_FOLDER
46-
TARGET_DEV_HEADSET_FOLDER = NRF5340_AUDIO_FOLDER / "build/dev_headset"
47-
TARGET_DEV_GATEWAY_FOLDER = NRF5340_AUDIO_FOLDER / "build/dev_gateway"
45+
TARGET_AUDIO_FOLDER = NRF5340_AUDIO_FOLDER
4846

4947
UNICAST_SERVER_OVERLAY = NRF5340_AUDIO_FOLDER / "unicast_server/overlay-unicast_server.conf"
5048
UNICAST_CLIENT_OVERLAY = NRF5340_AUDIO_FOLDER / "unicast_client/overlay-unicast_client.conf"
@@ -90,38 +88,34 @@ def __print_dev_conf(device_list):
9088
print(table)
9189

9290

93-
def __build_cmd_get(cores: Core, device: AudioDevice, build: BuildType,
91+
def __build_cmd_get(core: Core, device: AudioDevice, build: BuildType,
9492
pristine, options):
9593

96-
build_cmd = (f"west build {TARGET_CORE_APP_FOLDER} "
94+
build_cmd = (f"west build {TARGET_AUDIO_FOLDER} "
9795
f"-b {TARGET_BOARD_NRF5340_AUDIO_DK_APP_NAME} "
9896
f"--sysbuild")
99-
if Core.app in cores and Core.net in cores:
100-
# No changes to build command, build both cores
101-
pass
102-
elif Core.app in cores:
97+
98+
if core == Core.app:
10399
build_cmd += " --domain nrf5340_audio"
104-
elif Core.net in cores:
100+
elif core == Core.net:
105101
build_cmd += " --domain ipc_radio"
106102
else:
107103
raise Exception("Invalid core!")
108104

109105
if device == AudioDevice.headset:
110106
device_flag = "-DCONFIG_AUDIO_DEV=1"
111-
dest_folder = TARGET_DEV_HEADSET_FOLDER
112107
elif device == AudioDevice.gateway:
113108
device_flag = "-DCONFIG_AUDIO_DEV=2"
114-
dest_folder = TARGET_DEV_GATEWAY_FOLDER
115109
else:
116110
raise Exception("Invalid device!")
111+
117112
if build == BuildType.debug:
118113
release_flag = ""
119-
dest_folder /= TARGET_DEBUG_FOLDER
120114
elif build == BuildType.release:
121115
release_flag = " -DFILE_SUFFIX=release"
122-
dest_folder /= TARGET_RELEASE_FOLDER
123116
else:
124117
raise Exception("Invalid build type!")
118+
125119
if options.nrf21540:
126120
device_flag += " -Dnrf5340_audio_SHIELD=nrf21540ek"
127121
device_flag += " -Dipc_radio_SHIELD=nrf21540ek"
@@ -139,17 +133,22 @@ def __build_cmd_get(cores: Core, device: AudioDevice, build: BuildType,
139133
if options.transport == Transport.broadcast.name:
140134
if device == AudioDevice.headset:
141135
overlay_flag = f" -DEXTRA_CONF_FILE={BROADCAST_SINK_OVERLAY}"
142-
elif device == AudioDevice.gateway:
136+
else:
143137
overlay_flag = f" -DEXTRA_CONF_FILE={BROADCAST_SOURCE_OVERLAY}"
144138
elif options.transport == Transport.unicast.name:
145139
if device == AudioDevice.headset:
146140
overlay_flag = f" -DEXTRA_CONF_FILE={UNICAST_SERVER_OVERLAY}"
147-
elif device == AudioDevice.gateway:
141+
else:
148142
overlay_flag = f" -DEXTRA_CONF_FILE={UNICAST_CLIENT_OVERLAY}"
143+
else:
144+
raise Exception("Invalid transport type!")
145+
149146
if os.name == 'nt':
150147
release_flag = release_flag.replace('\\', '/')
151148
if pristine:
152-
build_cmd += " -p"
149+
build_cmd += " --pristine=auto"
150+
151+
dest_folder = TARGET_AUDIO_FOLDER / "build" / options.transport / device / core / build
153152

154153
return build_cmd, dest_folder, device_flag, release_flag, overlay_flag
155154

@@ -196,12 +195,11 @@ def __find_snr():
196195
def __populate_hex_paths(dev, options):
197196
"""Poplulate hex paths where relevant"""
198197

199-
_, temp_dest_folder, _, _, _ = __build_cmd_get(
200-
Core.app, dev.nrf5340_audio_dk_dev, options.build, options.pristine, options
201-
)
198+
_, temp_dest_folder, _, _, _ = __build_cmd_get(Core.app, dev.nrf5340_audio_dk_dev, options.build, options.pristine, options)
199+
dev.hex_path_app = temp_dest_folder / "nrf5340_audio/zephyr/zephyr.hex"
202200

203-
dev.hex_path_app = temp_dest_folder / "merged.hex"
204-
dev.hex_path_net = temp_dest_folder / "merged_CPUNET.hex"
201+
_, temp_dest_folder, _, _, _ = __build_cmd_get(Core.net, dev.nrf5340_audio_dk_dev, options.build, options.pristine, options)
202+
dev.hex_path_net = temp_dest_folder / "ipc_radio/zephyr/zephyr.hex"
205203

206204

207205
def __finish(device_list):
@@ -245,7 +243,10 @@ def __main():
245243
help="Select which cores to include in build",
246244
)
247245
parser.add_argument(
248-
"--pristine", default=False, action="store_true", help="Will build cleanly"
246+
"--pristine",
247+
default=False,
248+
action="store_true",
249+
help="Will build cleanly"
249250
)
250251
parser.add_argument(
251252
"-b",
@@ -312,7 +313,7 @@ def __main():
312313
parser.add_argument(
313314
"-t",
314315
"--transport",
315-
type=str,
316+
required=True,
316317
choices=[i.name for i in Transport],
317318
default=Transport.unicast.name,
318319
help="Select the transport type",
@@ -381,23 +382,25 @@ def __main():
381382
build_configs = []
382383

383384
if AudioDevice.headset in devices:
384-
build_configs.append(
385-
BuildConf(
386-
core=cores,
387-
device=AudioDevice.headset,
388-
pristine=options.pristine,
389-
build=options.build,
385+
for c in cores:
386+
build_configs.append(
387+
BuildConf(
388+
core=c,
389+
device=AudioDevice.headset,
390+
pristine=options.pristine,
391+
build=options.build,
392+
)
390393
)
391-
)
392394
if AudioDevice.gateway in devices:
393-
build_configs.append(
394-
BuildConf(
395-
core=cores,
396-
device=AudioDevice.gateway,
397-
pristine=options.pristine,
398-
build=options.build,
399-
)
400-
)
395+
for c in cores:
396+
build_configs.append(
397+
BuildConf(
398+
core=c,
399+
device=AudioDevice.gateway,
400+
pristine=options.pristine,
401+
build=options.build,
402+
)
403+
)
401404

402405
for build_cfg in build_configs:
403406
__build_module(build_cfg, options)
@@ -409,6 +412,7 @@ def __main():
409412
for dev in device_list:
410413
if dev.snr_connected:
411414
__populate_hex_paths(dev, options)
415+
412416
program_threads_run(device_list, sequential=options.sequential_prog)
413417

414418
# Program step finished

‎applications/nrf5340_audio/tools/buildprog/program.py

+25-21
Original file line numberDiff line numberDiff line change
@@ -41,31 +41,35 @@ def __populate_uicr(dev):
4141
def _program_cores(dev: DeviceConf) -> int:
4242
if dev.core_net_programmed == SelectFlags.TBD:
4343
if not path.isfile(dev.hex_path_net):
44-
print("NET core hex not found. Built as APP core image.")
45-
return 1
46-
47-
print(f"Programming net core on: {dev}")
48-
cmd = (f"nrfjprog --program {dev.hex_path_net} -f NRF53 -q "
49-
f"--snr {dev.nrf5340_audio_dk_snr} --sectorerase --coprocessor CP_NETWORK")
50-
ret_val = system(cmd)
51-
if ret_val != 0:
52-
if not dev.recover_on_fail:
53-
dev.core_net_programmed = SelectFlags.FAIL
54-
return ret_val
44+
print(f"NET core hex not found. Built as APP core image. {dev.hex_path_net}")
5545
else:
56-
dev.core_net_programmed = SelectFlags.DONE
46+
print(f"Programming net core on: {dev}")
47+
cmd = (f"nrfjprog --program {dev.hex_path_net} -f NRF53 -q "
48+
f"--snr {dev.nrf5340_audio_dk_snr} --sectorerase --coprocessor CP_NETWORK")
49+
ret_val = system(cmd)
50+
if ret_val != 0:
51+
if not dev.recover_on_fail:
52+
dev.core_net_programmed = SelectFlags.FAIL
53+
return ret_val
54+
else:
55+
dev.core_net_programmed = SelectFlags.DONE
5756

5857
if dev.core_app_programmed == SelectFlags.TBD:
59-
print(f"Programming app core on: {dev}")
60-
cmd = (f"nrfjprog --program {dev.hex_path_app} -f NRF53 -q "
61-
f"--snr {dev.nrf5340_audio_dk_snr} --chiperase --coprocessor CP_APPLICATION")
62-
ret_val = system(cmd)
63-
if ret_val != 0:
64-
if not dev.recover_on_fail:
65-
dev.core_app_programmed = SelectFlags.FAIL
66-
return ret_val
58+
if not path.isfile(dev.hex_path_app):
59+
print(f"APP core hex not found. Built as NET core image. {dev.hex_path_app}")
60+
return 1
6761
else:
68-
dev.core_app_programmed = SelectFlags.DONE
62+
print(f"Programming app core on: {dev}")
63+
cmd = (f"nrfjprog --program {dev.hex_path_app} -f NRF53 -q "
64+
f"--snr {dev.nrf5340_audio_dk_snr} --chiperase --coprocessor CP_APPLICATION")
65+
ret_val = system(cmd)
66+
if ret_val != 0:
67+
if not dev.recover_on_fail:
68+
dev.core_app_programmed = SelectFlags.FAIL
69+
return ret_val
70+
else:
71+
dev.core_app_programmed = SelectFlags.DONE
72+
6973
# Populate UICR data matching the JSON file
7074
if not __populate_uicr(dev):
7175
dev.core_app_programmed = SelectFlags.FAIL

0 commit comments

Comments
 (0)
Please sign in to comment.