<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Segmentation fault with pynrfjprog</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/30661/segmentation-fault-with-pynrfjprog</link><description>Hello, 
 I&amp;#39;m writing a python script to flash batches of boards with NRF52&amp;#39;s. 
 This is the part of the script that flashes the boards: 
 
 I call that function inside a for-loop until all the boards are flashed. The code works, the boards are flashed</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 20 Feb 2018 15:31:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/30661/segmentation-fault-with-pynrfjprog" /><item><title>RE: Segmentation fault with pynrfjprog</title><link>https://devzone.nordicsemi.com/thread/121413?ContentTypeID=1</link><pubDate>Tue, 20 Feb 2018 15:31:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02f38513-7197-4f1f-b9e5-6602a02b3570</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;It seems to have solved the problem. I&amp;#39;ll keep testing for a while more and I&amp;#39;ll mark your reply as an answer once I&amp;#39;m sure :) Otherwise, I&amp;#39;ll update again here. Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Segmentation fault with pynrfjprog</title><link>https://devzone.nordicsemi.com/thread/121392?ContentTypeID=1</link><pubDate>Tue, 20 Feb 2018 13:40:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2cd2639c-ca4c-4a5c-8ac5-79663ade3a11</guid><dc:creator>Simen August Tinderholt</dc:creator><description>&lt;p&gt;Sorry, that should be API.API(&amp;#39;NRF52&amp;#39;).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Segmentation fault with pynrfjprog</title><link>https://devzone.nordicsemi.com/thread/121389?ContentTypeID=1</link><pubDate>Tue, 20 Feb 2018 13:34:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f09c8bd7-8072-434d-9119-458e0d95526d</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;With that code I get this error:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;pre class="ui-code" data-mode="text"&gt;# Opening API with device family NRF52.
Traceback (most recent call last):
  File &amp;quot;main.py&amp;quot;, line 309, in &amp;lt;module&amp;gt;
    main()
  File &amp;quot;main.py&amp;quot;, line 304, in main
    flash_batch(programmer, uart)
  File &amp;quot;main.py&amp;quot;, line 203, in flash_batch
    result = flash_program(programmer)
  File &amp;quot;main.py&amp;quot;, line 82, in flash_program
    with API(&amp;#39;NRF52&amp;#39;) as api:
TypeError: &amp;#39;module&amp;#39; object is not callable&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Segmentation fault with pynrfjprog</title><link>https://devzone.nordicsemi.com/thread/121363?ContentTypeID=1</link><pubDate>Tue, 20 Feb 2018 09:34:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b1ffb5e7-2d64-46f2-9efd-03fe6d60dca5</guid><dc:creator>Simen August Tinderholt</dc:creator><description>&lt;p&gt;If that doesn&amp;#39;t work you might be dealing with a memory leak in the Segger DLL.&lt;/p&gt;
&lt;p&gt;You can fix that by instantiating a single API, and passing it around, instead of creatnig a new one for every device.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Segmentation fault with pynrfjprog</title><link>https://devzone.nordicsemi.com/thread/121355?ContentTypeID=1</link><pubDate>Tue, 20 Feb 2018 09:22:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d027ce8e-26c9-4a93-b1d8-6bc043276327</guid><dc:creator>Simen August Tinderholt</dc:creator><description>&lt;p&gt;Hm, I can&amp;#39;t see anything wrong with the script, but the garbage collection in python can be unreliable. Can you try:&lt;br /&gt;&lt;pre class="ui-code" data-mode="python"&gt;with API(&amp;#39;NRF52&amp;#39;) as api:
    api.connect_to_emu_without_snr(1000)

    # Erase all the flash of the device.
    print &amp;quot;# Erasing all flash in the microcontroller.&amp;quot;
    api.erase_all()

    # Parse the hex file with the help of the HEX module
    print &amp;quot;# Parsing hex file into segments.&amp;quot;
    test_program = Hex.Hex(hex_file_path)

    # Program the parsed hex into the device&amp;#39;s memory.
    print(&amp;#39;# Writing %s to device.&amp;#39; % hex_file_path)
    for segment in test_program:
        api.write(segment.address, segment.data, True)

    # Free resources
    test_program = None

    print &amp;quot;# Writing serial number to memory address 0x10001080, use NVMC&amp;quot;
    api.write_u32(0x10001080, ctypes.c_uint32(serial_number).value, True)

    # Read back the serial number
    print &amp;quot;# Programmed serial number: &amp;quot; + hex(api.read_u32(0x10001080))

    # Reset the device and run.
    api.sys_reset()
    api.go()
    print &amp;quot;# Application running.&amp;quot;

print &amp;quot;# Programming finished.&amp;quot;
return 0&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;That should ensure that the close() is called whatever happens (it&amp;#39;s always called when exiting the with statement), and (maybe) help the python garbage collector out.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>