Hello,
I'm writing a python script to flash batches of boards with NRF52's.
This is the part of the script that flashes the boards:
def flash_program(hex_file_path, serial_number):
# 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 NRF52."
# Initialize an API object with the target family. This will load nrfjprog.dll with the proper target family.
api = API.API('NRF52')
try:
# Open the loaded DLL and connect to an emulator probe. If several are connected a pop up will appear.
api.open()
api.connect_to_emu_without_snr(1000)
# Erase all the flash of the device.
print "# Erasing all flash in the microcontroller."
api.erase_all()
# Parse the hex file with the help of the HEX module
print "# Parsing hex file into segments."
test_program = Hex.Hex(hex_file_path)
# Program the parsed hex into the device's memory.
print('# Writing %s to device.' % hex_file_path)
for segment in test_program:
api.write(segment.address, segment.data, True)
# Free resources
test_program = None
print "# Writing serial number to memory address 0x10001080, use NVMC"
api.write_u32(0x10001080, ctypes.c_uint32(serial_number).value, True)
# Read back the serial number
print "# Programmed serial number: " + hex(api.read_u32(0x10001080))
# Reset the device and run.
api.sys_reset()
api.go()
print "# Application running."
# Close the loaded DLL to free resources.
api.close()
print "# Programming finished."
return 0
except Exception:
# Close the loaded DLL to free resources.
api.close()
return -1
I call that function inside a for-loop until all the boards are flashed. The code works, the boards are flashed, but after a while I get a segmentation fault -11. Is it maybe a memory leak?
Any clues will be appreciated.