This section shows some simple examples of a typical pynrfjprog use case.
To initialize the API module to work with nRF52 Series SoCs, establish a connection to a SEGGER debug emulator, erase all user flash of the nRF52 SoC, and finally disconnect the emulator and close the connection, type the following commands in a Python interpreter:
from pynrfjprog import HighLevel
api = HighLevel.API(‘NRF52’)
api.open()
api.connect_to_emu_without_snr()
api.erase_all()
api.close()
The API object includes enter
and exit
methods so the
with
construct can be used. When using with
, then
open()
and close()
are called automatically.
Pynrfjprog also allows you to work with multiple devices at once. To do this, type the following:
from pynrfjprog import MultiAPI
api = MultiAPI.MultiAPI(‘NRF52’)
api.open()
api2 = MultiAPI.MultiAPI(‘NRF51’)
api2.open()
api1.close()
api2.close()
The two MultiAPI modules are initialized to work with different nRF families. Their APIs are
initialized through .open()
, and closed without calling any of the API
functions.
Other examples on how to use pynrfjprog can be found in the examples module provided with
the package. The examples can be found in the installed pynrfjprog
directory/examples folder. These examples can be run either from
within the folder, for example calling python memory_read_write.py
, or they
can be run from an interpreter by importing the examples module >>> import
examples
, and calling >>> examples.memory_read_write.run()
.