1:name: nRF52840 BLE on Zephyr
2
3# This script runs Zephyr BLE HR demo on nRF52840. It creates 2 machines: `central` and `peripheral`.
4# `central` looks for active heart-rate monitors using BLE and establishes
5# a connection to the first device with the strongest signal.
6# `peripheral` works as such a monitor and generates dummy heart-rate values.
7# Having established the connection, `central` will report heart-rate readings from `peripheral``.
8
9# The `using` command allows the user to omit a prefix when referring to a peripheral.
10# Here `using sysbus` allows to refer to `uart0` instead of `sysbus.uart0`.
11using sysbus
12
13# Lines below declare binary files for Zephyr BLE devices. One for central device and one for peripheral device.
14# Binaries used here are defaults and can be replaced by changing variables below before running this script.
15$central_bin?=@https://dl.antmicro.com/projects/renode/nrf52840--zephyr-bluetooth_central_hr.elf-s_3380332-316e27f81dcda3c2b0e7f2c3516001e7b27ad051
16$peripheral_bin?=@https://dl.antmicro.com/projects/renode/nrf52840--zephyr-bluetooth_peripheral_hr.elf-s_3217940-7b59adc9629f8be90067b131e663a13d2d4bb711
17
18# Create a wireless medium for communication.
19emulation CreateBLEMedium "wireless"
20
21# Create a machine named "central" based on the nRF52840 platform and set it as active.
22mach create "central"
23machine LoadPlatformDescription @platforms/cpus/nrf52840.repl
24connector Connect sysbus.radio wireless
25
26# Create a UART analyzer for the "central" machine.
27# UART analyzer is a window which will pop-up after starting the emulation.
28# In general it works as an I/O interface for the user to communicate with the running machine.
29# In this script both analyzers just print output from the machines.
30showAnalyzer uart0
31
32# Create a machine named "peripheral" based on the nRF52840 platform and set it as active.
33mach create "peripheral"
34machine LoadPlatformDescription @platforms/cpus/nrf52840.repl
35connector Connect sysbus.radio wireless
36
37# Create a UART analyzer for the "peripheral" machine.
38showAnalyzer uart0
39
40# Set Quantum value for CPUs. This is required by BLE stack.
41# Moreover, it allows better synchronisation between machines.
42emulation SetGlobalQuantum "0.00001"
43
44# The following series of commands is executed everytime the machine is reset.
45macro reset
46"""
47    mach set "central"
48    sysbus LoadELF $central_bin
49
50    mach set "peripheral"
51    sysbus LoadELF $peripheral_bin
52"""
53runMacro $reset
54
55echo "Script loaded. Now start with with the 'start' command."
56echo ""
57