This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

What are the raw JLink.exe commands sent by nrfjprog.exe?

My devices require calibration and self test to be carried out after programming. To implement this, my device checks the JLink reset pin (configured as a GPIO on my NRF52 device) if it has been pulled low on startup - if it has, it performs calibration and self test.

In order to automate this process, I have implemented a script which takes the JLink reset pin high (using Jlink.exe command), performs a chip recovery by NRFJPROG, programs the chip by NRFJPROG, takes reset pin low (using JLink.exe) and then finally power cycles the board with a Python script written to interface with the Nordic PPK (at which point it performs self test and calibration).

Currently the calls to Jlink.exe, followed by nrfjprog and Jlink.exe result in establishing a new jlink connection with each call. This slows the script down. As I'd like to use this script in production, this script needs to be as fast as possible.

I was hoping to combine all the JLink commands (namely those in the nrfjprog program) into a single JLink script, so I only need to establish one connection to this JLink.

Is there a way to find out what jlink.exe commands are being sent by the nrfjprog.exe? I am particulary interested in the recover and programming commands.

Parents Reply Children
  • Thanks for that - that does help. I've also found this: http://infocenter.nordicsemi.com/pdf/nwp_027.pdf.

    Based on these articles, I've changed my code to this. Both in the nrfjprog.sh github link you posted and from Nordic Devzone posts, I have seen people use short "sleep" commands instead of polling the ready register (as recommended in the Nordic Production Programming White Paper). Hopefully this is ok....any advice from Nordic would be appreciated on this though.

    r0
    
    //RECOVER NRF52 from APPROTECT
    SWDSelect //Selects the SWD Interface
    SWDWriteDP 1 0x50000000 //Enables power
    SWDWriteDP 2 0x01000000 //Selects the 0x01XXXXXX Access Port and 0xXXXX00XX Register bank in the access port
    SWDWriteAP 1 0x00000001 //CTRL-AP Bank 0, register offset 1 (ERASEALL 0x004): Erase all command
    sleep 1000 
    SWDReadAP 2 //CTRL-AP Bank 0, register offset 2 (ERASEALL 0x008): Erase all command status
    SWDReadAP 2 //Second read returns the value
    SWDWriteAP 0 0x00000001 //RESET register write - soft reset
    SWDWriteAP 0 0x00000000 //RESET register write
    SWDWriteAP 1 0x00000000 //ERASEALL register write
    SWDReadAP 3 //CTRL-AP Bank 0, register offset 3 (APPROTECTSTATUS 0x00C): Access port protection status
    SWDReadAP 3 //Second read returns the value: 0: enabled 1: not enabled
    
    sleep 500 //probably not necessary
    
    //JLink connection parameters
    device nrf52
    speed 50000
    
    //ERASE ALL HERE
    h
    w4 4001e504 2 //CONFIG register of NVMC
    sleep 100 //TODO read ready register of NVMC (4001e400). Wait until value is 0x00000001
    w4 4001e50c 1
    sleep 100 //TODO read ready register of NVMC (4001e400). Wait until value is 0x00000001
    w4 4001e504 0 //NVM back to read only
    sleep 100
    r //reset and halt
    h //halt
    
    //FLASH DEVICE HERE
    w4 4001e504 1 //Configure NVM for writing
    sleep 100 //TODO read ready register (4001E504) of NVMC until value is 1
    loadfile myCombinedHexFile.hex //softdevice and application combined using mergehex.exe
    sleep 100 //TODO read ready register (4001E504) of NVMC until value is 1
    w4 4001e504 0 //CONFIG register back to read only
    sleep 100
    verifybin myCombinedHexFile.bin 0x00000000 //converted using JFlash
    r //reset and halt
    
    //ENTER CALIBRATION ROUTINE ON NRF52
    r0 //take reset pin low
    g //Enable CPU of NRF52
    //CALIBRATION ROUTINE STARTS ON NRF52 HERE
    exit
    
    

Related