Hi,
I'd like to start developing automated tests for my custom NRF52840 board.
Currently I use the CLI library (with RTT backend) for communicating with the board.
Any ideas for how I could communicate with my board via a python script?
Thanks
Tim
Hi,
I'd like to start developing automated tests for my custom NRF52840 board.
Currently I use the CLI library (with RTT backend) for communicating with the board.
Any ideas for how I could communicate with my board via a python script?
Thanks
Tim
Hi Tim,
If you want to continue using CLI over RTT for your communication with the board, you can look into our pynrfjprog library. This enables you to read and write RTT channels from a python script.
Best regards,
Jørgen
Yes, that should work similarly. I updated the examples with read in application and write in Python script:
rtt_reader_writer_sdk_16.0.0.zip
from __future__ import print_function
# Import pynrfjprog API module
from pynrfjprog import LowLevel
from time import sleep
TEST_STRING = b'RTT Channel 1 write test #'
def run(snr=None):
"""
Run example script.
@param (optional) int snr: Specify serial number of DK to run example on.
"""
print('# RTT read example using pynrfjprog started...')
# Detect the device family of your device. Initialize an API object with UNKNOWN family and read the device's family. This step is performed so this example can be run in all devices without customer input.
print('# Opening API with device family UNKNOWN, reading the device family.')
with LowLevel.API(LowLevel.DeviceFamily.UNKNOWN) as api: # Using with construction so there is no need to open or close the API class.
if snr is not None:
api.connect_to_emu_with_snr(snr)
else:
api.connect_to_emu_without_snr()
device_family = api.read_device_family()
# Initialize an API object with the target family. This will load nrfjprog.dll with the proper target family.
api = LowLevel.API(device_family)
# Open the loaded DLL and connect to an emulator probe. If several are connected a pop up will appear.
api.open()
try:
if snr is not None:
api.connect_to_emu_with_snr(snr)
else:
api.connect_to_emu_without_snr()
# Erase all the flash of the device.
print('Starting RTT.')
api.rtt_start()
# rtt_start() API is non-blocking, need to wait for the control block to be found
while(api.rtt_is_control_block_found() != True):
print("waiting for control block")
sleep(0.1)
channel_count_down, channel_count_up = api.rtt_read_channel_count()
print("Found {} down channels and {} up channels".format(channel_count_down, channel_count_up))
cnt = 0
while(True):
api.rtt_write(1, TEST_STRING + str(cnt) + '\0')
cnt = cnt + 1
sleep(2);
api.close()
print('# Example done...')
except LowLevel.APIError:
api.close()
raise
if __name__ == '__main__':
run()
Thanks Jørgen, and apologies for the late response. I've been sidetracked by other tasks. Now I finally have time for this.
I currently use SDK 15.2.0. What peripheral example did you start with? (I'd like to have as close to your setup as possible to avoid nasty surprises).
I started out with the UART peripheral example. However, I do not think that any part of that example is used in the project I uploaded, so it should not really matter.
Looks like it's working. I just have one issue with the python environment (I use python 3.x). Did you test the scripts with python 2.x?
Yes, I tested with Python 2.7.15. I see from the release notes that pynrfjprog should support Python 3.6 at least, but you may have to modify the example to use it with Python 3.x.
Yes, I tested with Python 2.7.15. I see from the release notes that pynrfjprog should support Python 3.6 at least, but you may have to modify the example to use it with Python 3.x.
Great! I igot it working with python 3.x. Need to tweak the script for my own tests, but the basic read and write from both ends works! I have enough to get me running. Thanks Jørgen!