<?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>ULINK UICR programming</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/9336/ulink-uicr-programming</link><description>Is there any way to program UICR registers using Keil ULINK programmers? 
 I know that the algorithm it uses to program Flash does not support UICR. However, I am able to enter debug mode manually, change the NVMC-CONFIG to 1 and write into UICR registers</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 04 Oct 2018 09:55:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/9336/ulink-uicr-programming" /><item><title>RE: ULINK UICR programming</title><link>https://devzone.nordicsemi.com/thread/151622?ContentTypeID=1</link><pubDate>Thu, 04 Oct 2018 09:55:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e9b4d65-04fe-48b0-b63f-80f0c0d21b00</guid><dc:creator>Ron</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Not sure I understand, is this suppose to apply to ULINK too ?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ULINK UICR programming</title><link>https://devzone.nordicsemi.com/thread/34475?ContentTypeID=1</link><pubDate>Tue, 10 May 2016 05:51:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2320a61-d2bf-4102-a5a3-7292e73b3cdb</guid><dc:creator>Jon (jono)</dc:creator><description>&lt;p&gt;Tested ok.
Either run with chip erase instead of block erase or rather, as I do, temporarily change to chip erase when content in UICR is changed.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ULINK UICR programming</title><link>https://devzone.nordicsemi.com/thread/34473?ContentTypeID=1</link><pubDate>Mon, 09 May 2016 16:57:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:db6f02ed-45b3-46d2-86ae-9ad495f6b6e1</guid><dc:creator>slo</dc:creator><description>&lt;ol&gt;
&lt;li&gt;It seems that nrf52xxx_uicr.flm is not shipped with the nrf-Tools, but with the nrf_DeviceFamilyPack&lt;/li&gt;
&lt;li&gt;It is not working with my ULINK ME nor ULINKpro.&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ULINK UICR programming</title><link>https://devzone.nordicsemi.com/thread/34474?ContentTypeID=1</link><pubDate>Wed, 04 May 2016 08:36:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4792977c-118d-41ca-bcb9-98a5c9272e0e</guid><dc:creator>Jon (jono)</dc:creator><description>&lt;p&gt;You can also build one for nRF51 for Keil. (Need Chip Erase from other algorighm to work).&lt;/p&gt;
&lt;p&gt;I Added a pre compiled binary as uuencode below as well: &lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/nRF51_5F00_UICR_5F00_Permobil.FLM"&gt;nRF51_UICR_Permobil.FLM&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This code is not so tested, but I&amp;#39;ll work on it the comming days I think.&lt;/p&gt;
&lt;p&gt;Source FlashDev.c&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;quot;..\FlashOS.H&amp;quot;        // FlashOS Structures

struct FlashDevice const FlashDevice  =  {
   FLASH_DRV_VERS,             // Driver Version, do not modify!
   &amp;quot;nRF51_UICR_Permobil&amp;quot;,      // Device Name 
   ONCHIP,                     // Device Type
   0x10001000,                 // Device Start Address
   0x00000100,                 // Device Size in Bytes (256B)
   4,                          // Programming Page Size
   0,                          // Reserved, must be 0
   0xFF,                       // Initial Content of Erased Memory
   100,                        // Program Page Timeout 100 mSec
   100,                        // Erase Sector Timeout 3000 mSec (set to short since this will fail anyway)

// Specify Size and Address of Sectors
   0x04, 0x0,                  // Sector Size  4B (64 Sectors)
   SECTOR_END
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Source FlashPrg.c&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;quot;..\FlashOS.H&amp;quot;        // FlashOS Structures

#define NVMC_BASE                 0x4001E000UL // Base address for NVMC
#define NRF_NVMC                  ((NVMC_Peripheral_t*)NVMC_BASE)

#define BLANK_DW                  0xFFFFFFFF
#define NRF_CONFIG_WRITE_ENABLE   1
#define NRF_CONFIG_WRITE_DISABLE  0

#define UICR_START                0x10001000
#define UICR_SIZE                 0x00000100

typedef unsigned long uint32_t;

typedef struct NVMC_Peripheral_t {
    uint32_t pad1[256];
    uint32_t READY;
    uint32_t pad2[64];
    uint32_t CONFIG;
} NVMC_Peripheral_t;


/**
 *  Initialize Flash Programming Functions
 *    Parameter:      adr:  Device Base Address
 *                    clk:  Clock Frequency (Hz)
 *                    fnc:  Function Code (1 - Erase, 2 - Program, 3 - Verify)
 *    Return Value:   0 - OK,  1 - Failed
 */
int Init(unsigned long adr, unsigned long clk, unsigned long fnc)
{
    return 0;
}

/**
 *  De-Initialize Flash Programming Functions
 *    Parameter:      fnc:  Function Code (1 - Erase, 2 - Program, 3 - Verify)
 *    Return Value:   0 - OK,  1 - Failed
 */
int UnInit(unsigned long fnc)
{
    return 0;
}

/**
 *  Erase complete Flash Memory
 *    Return Value:   0 - OK,  1 - Failed
 */
int EraseChip(void)
{
    // Report erase ok even though nothing is made
    // To fool programmer to think that erase was ok and allow programming
    return 0;
}


/**
 *  Erase Sector in Flash Memory
 *    Parameter:      adr:  Sector Address
 *    Return Value:   0 - OK,  1 - Failed
 */
int EraseSector(unsigned long adr)
{
    // Report erase ok even though nothing is made
    // To fool programmer to think that erase was ok and allow programming
    return 0;
}

/**
 * Perform bounds check and alignment check
 */
int AddrCheck(unsigned long adr, unsigned long sz)
{
    // Check bounds
    if ( (adr &amp;lt; UICR_START)
         || ((adr) &amp;gt;= (UICR_START + UICR_SIZE))
         || ((adr + sz) &amp;gt;= (UICR_START + UICR_SIZE)) )
        return 1;

    // Check alignment
    if ((adr | sz) &amp;amp; 0x03)
        return 1;

    return 0;
}

/**
 *  Program Page in Flash Memory
 *    Parameter:      adr:  Page Start Address
 *                    sz:   Page Size
 *                    buf:  Page Data
 *    Return Value:   0 - OK,  1 - Failed
 */
int ProgramPage(unsigned long adr, unsigned long sz, unsigned char *buf)
{
    if (AddrCheck(adr, sz))
        return 1;

    // Loop all dw:s in
    while (sz)
    {
        // Check for diff
        if ( *(uint32_t*)adr != *(uint32_t*)buf )
        {
            // Blank check
            if (*(uint32_t*)adr != BLANK_DW)
                return 1;

            // Enable write
            NRF_NVMC-&amp;gt;CONFIG = NRF_CONFIG_WRITE_ENABLE;
            while (!NRF_NVMC-&amp;gt;READY)
                ;

            // Write one DW
            *(uint32_t*)adr = *(uint32_t*)buf;
            while (!NRF_NVMC-&amp;gt;READY)
                ;

            // Disable write
            NRF_NVMC-&amp;gt;CONFIG = NRF_CONFIG_WRITE_DISABLE;
            while (!NRF_NVMC-&amp;gt;READY)
                ;

            // Verify write
            if ( *(uint32_t*)adr != *(uint32_t*)buf )
                return 1;
        }

        // Move to next location
        adr += 4;
        buf += 4;
        sz -= 4;
    }

    return 0;
}

/**
 * Verify content
 * Return end address checked, stop checking on error.
 * adr+sz on success
 */
unsigned long Verify(unsigned long adr, unsigned long sz, unsigned char *buf)
{
    if (AddrCheck(adr, sz))
        return adr;

    // Loop all dw:s in
    while (sz)
    {
        // Check for diff
        if ( *(uint32_t*)adr != *(uint32_t*)buf )
            return adr;

        // Move to next location
        adr += 4;
        buf += 4;
        sz -= 4;
    }

    return adr;
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ULINK UICR programming</title><link>https://devzone.nordicsemi.com/thread/34472?ContentTypeID=1</link><pubDate>Mon, 21 Sep 2015 14:01:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea498cff-250f-4698-b55d-9b5b8e5796e2</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;I have not found the algorithm for writing to UICR in KEIL for nRF51 but if you install latest nrf-Tools &lt;a href="https://www.nordicsemi.com/eng/nordic/Products/nRF51822/nRF5x-Tools/33444"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I see that it gives you option to write to nRF52 UICR registers in Keil settings like below
&lt;img src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/5282.Capture.PNG" alt="image description" /&gt;&lt;/p&gt;
&lt;p&gt;and after adding this we can see that it adds the UICR address range like below
&lt;img src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/6763.Capture1.PNG" alt="image description" /&gt;&lt;/p&gt;
&lt;p&gt;Because both nrf51 and nrf52 have same NVMC interface and have same UICR config, I think this algorithm must be the same for nRF51. After you add this, you should be able to flash normally from Keil. Worth a try :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>