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

nrfjprog.dll Issue with NRFJPROG_qspi_custom function

nrfjprogdll_err_t NRFJPROG_qspi_custom(uint8_t instruction_code, uint32_t instruction_length, const uint8_t * data_in, uint8_t * data_out);

Trying to use the call writing in c code but not sure how to implement. 

When using the QspiDefault.ini, we have the following instructions:

InitializationCustomInstruction = 0x06 ; Write enable (wren). Set the Write enable Latch (WEL) bit. it resets after every write operation.
InitializationCustomInstruction = 0x01, [0x40] ; Enable quad spi
InitializationCustomInstruction = 0xb7 ; 32 bit addressing enable

How would I convert to sending the cmds with the dll? Was given the QspiDefault.ini now sure how all the commands word but need to convert to dll.

Thought I could write the code like this but does not work properly when I flash the file to the external memory.

nrfjprogdll_err_t cmdRes;
uint8_t inst01 = 0x06;
uint8_t inst02 = 0x01;
uint8_t inst03 = 0xb7;
uint32_t instrLen = 1;
const unsigned char dataIn[1] = {'0x40'};

cmdRes = NRFJPROG_qspi_custom(inst01, instrLen, NULL, NULL);
cmdRes = NRFJPROG_qspi_custom(inst02, instrLen, dataIn, NULL);
cmdRes = NRFJPROG_qspi_custom(inst03, instrLen, NULL, NULL);

Parents
  • The length is the instruction + data, so in your case length should not be 1, but 2.

    Best regards,
    Kenneth

  • Thank you for the response but it still doesn't seem to work.

    Here is more information.

    This is the batch file programming that I am trying to run with the dll.

    If something is on the 1st byte of the internal chip it will run
    nrfjprog -c 9600 -e --qspieraseall

    or just below

    nrfjprog -c 9600 --program app_wrapped-v1_0_1_12_postRelease.hex
    nrfjprog -c 9600 --program boot_v1_0_1_1.hex
    nrfjprog -c 9600 --qspicustominit --program resource_wrapped-v1_0_1_2.hex --reset --log

    Attached is the QspiDefault.ini that was used.
    pause4572.QspiDefault.ini

    Here is my main

    int main (int x)
    {

    FileHndl = OpenFile("_Log.txt",VAL_READ_WRITE,VAL_TRUNCATE,VAL_ASCII);

    HINSTANCE hinstLib = NULL; //Handle to the DLL

    hinstLib = LoadLibrary("nrfjprog.dll");

    Dll_NRFJPROG_is_dll_open_t NRFJPROG_is_dll_open =(Dll_NRFJPROG_is_dll_open_t)GetProcAddress(hinstLib,"NRFJPROG_is_dll_open");
    Dll_NRFJPROG_open_dll_t NRFJPROG_open_dll =(Dll_NRFJPROG_open_dll_t)GetProcAddress(hinstLib,"NRFJPROG_open_dll");
    Dll_NRFJPROG_close_dll_t NRFJPROG_close_dll =(Dll_NRFJPROG_close_dll_t)GetProcAddress(hinstLib,"NRFJPROG_close_dll");
    Dll_NRFJPROG_is_connected_to_emu_t NRFJPROG_is_connected_to_emu =(Dll_NRFJPROG_is_connected_to_emu_t)GetProcAddress(hinstLib,"NRFJPROG_is_connected_to_emu");
    Dll_NRFJPROG_connect_to_emu_with_snr_t NRFJPROG_connect_to_emu_with_snr =(Dll_NRFJPROG_connect_to_emu_with_snr_t)GetProcAddress(hinstLib,"NRFJPROG_connect_to_emu_with_snr");
    Dll_NRFJPROG_disconnect_from_emu_t NRFJPROG_disconnect_from_emu =(Dll_NRFJPROG_disconnect_from_emu_t)GetProcAddress(hinstLib,"NRFJPROG_disconnect_from_emu");
    Dll_NRFJPROG_is_connected_to_device_t NRFJPROG_is_connected_to_device =(Dll_NRFJPROG_is_connected_to_device_t)GetProcAddress(hinstLib,"NRFJPROG_is_connected_to_device");
    Dll_NRFJPROG_connect_to_device_t NRFJPROG_connect_to_device =(Dll_NRFJPROG_connect_to_device_t)GetProcAddress(hinstLib,"NRFJPROG_connect_to_device");
    Dll_NRFJPROG_disconnect_from_device_t NRFJPROG_disconnect_from_device =(Dll_NRFJPROG_disconnect_from_device_t)GetProcAddress(hinstLib,"NRFJPROG_disconnect_from_device");
    Dll_NRFJPROG_read_region_0_size_and_source_t NRFJPROG_read_region_0_size_and_source =(Dll_NRFJPROG_read_region_0_size_and_source_t)GetProcAddress(hinstLib,"NRFJPROG_read_region_0_size_and_source");
    Dll_NRFJPROG_sys_reset_t NRFJPROG_sys_reset =(Dll_NRFJPROG_sys_reset_t)GetProcAddress(hinstLib,"NRFJPROG_sys_reset");
    Dll_NRFJPROG_disable_bprot_t NRFJPROG_disable_bprot =(Dll_NRFJPROG_disable_bprot_t)GetProcAddress(hinstLib,"NRFJPROG_disable_bprot");
    Dll_NRFJPROG_erase_all_t NRFJPROG_erase_all =(Dll_NRFJPROG_erase_all_t)GetProcAddress(hinstLib,"NRFJPROG_erase_all");
    Dll_NRFJPROG_read_u32_t NRFJPROG_read_u32 =(Dll_NRFJPROG_read_u32_t)GetProcAddress(hinstLib,"NRFJPROG_read_u32");
    Dll_NRFJPROG_write_t NRFJPROG_write =(Dll_NRFJPROG_write_t)GetProcAddress(hinstLib,"NRFJPROG_write");
    Dll_NRFJPROG_go_t NRFJPROG_go =(Dll_NRFJPROG_go_t)GetProcAddress(hinstLib,"NRFJPROG_go");
    Dll_NRFJPROG_power_ram_all_t NRFJPROG_power_ram_all =(Dll_NRFJPROG_power_ram_all_t)GetProcAddress(hinstLib,"NRFJPROG_power_ram_all");
    Dll_NRFJPROG_is_qspi_init_t NRFJPROG_is_qspi_init =(Dll_NRFJPROG_is_qspi_init_t)GetProcAddress(hinstLib,"NRFJPROG_is_qspi_init");
    Dll_NRFJPROG_qspi_init_t NRFJPROG_qspi_init =(Dll_NRFJPROG_qspi_init_t)GetProcAddress(hinstLib,"NRFJPROG_qspi_init");
    Dll_NRFJPROG_qspi_uninit_t NRFJPROG_qspi_uninit =(Dll_NRFJPROG_qspi_uninit_t)GetProcAddress(hinstLib,"NRFJPROG_qspi_uninit");
    Dll_NRFJPROG_qspi_write_t NRFJPROG_qspi_write =(Dll_NRFJPROG_qspi_write_t)GetProcAddress(hinstLib,"NRFJPROG_qspi_write");
    Dll_NRFJPROG_qspi_erase_t NRFJPROG_qspi_erase =(Dll_NRFJPROG_qspi_erase_t)GetProcAddress(hinstLib,"NRFJPROG_qspi_erase");
    Dll_NRFJPROG_qspi_custom_t NRFJPROG_qspi_custom =(Dll_NRFJPROG_qspi_custom_t)GetProcAddress(hinstLib,"NRFJPROG_qspi_custom");

    const char jlink_path[] = "C:\\Program Files (x86)\\Nordic Semiconductor\\nrf5x\\bin\\JLinkARM.dll";

    nrfjprogdll_err_t cmdRes = NOT_IMPLEMENTED_ERROR;

    qspi_init_params_t aspiInitParams;
    region_0_source_t source;

    bool dllOpen = FALSE;
    bool connectedToEmu = FALSE;
    bool connectedToDevice = FALSE;
    bool qspiInitialized = FALSE;

    uint32_t addrToRead = 0;
    uint32_t dataRead;

    uint32_t size = 0;
    int data_len = 0;

    //************************************************************************************
    //**************************** Setup for QSPI ****************************************
    //************************************************************************************
    aspiInitParams.read_mode = READ4IO;
    aspiInitParams.write_mode = PP4O;
    aspiInitParams.address_mode = BIT32;
    aspiInitParams.frequency = M16;
    aspiInitParams.spi_mode = MODE0;
    aspiInitParams.sck_delay = 0x1;
    aspiInitParams.custom_instruction_io2_level = LEVEL_LOW;
    aspiInitParams.custom_instruction_io3_level = LEVEL_HIGH;
    aspiInitParams.CSN_pin = 22;
    aspiInitParams.CSN_port = 0;
    aspiInitParams.SCK_pin = 17;
    aspiInitParams.SCK_port = 0;
    aspiInitParams.DIO0_pin = 19;
    aspiInitParams.DIO0_port = 0;
    aspiInitParams.DIO1_pin = 21;
    aspiInitParams.DIO1_port = 0;
    aspiInitParams.DIO2_pin = 20;
    aspiInitParams.DIO2_port = 0;
    aspiInitParams.DIO3_pin = 16;
    aspiInitParams.DIO3_port = 0;
    aspiInitParams.WIP_index = 0;
    aspiInitParams.pp_size = PAGE256;
    //************************************************************************************
    //************************** End Setup for QSPI **************************************
    //************************************************************************************

    //Check to see if the dll is open
    cmdRes = NRFJPROG_is_dll_open(&dllOpen);
    if (dllOpen == FALSE)
    {
    //Open the dll and set the bool for dllOpen after the call
    cmdRes = NRFJPROG_open_dll(jlink_path,&msg_callback_main,NRF52_FAMILY);
    cmdRes = NRFJPROG_is_dll_open(&dllOpen);
    }

    //Connect to emulator
    cmdRes = NRFJPROG_is_connected_to_emu(&connectedToEmu);
    if (connectedToEmu == FALSE)
    {
    cmdRes = NRFJPROG_connect_to_emu_with_snr(752001312,9600);
    cmdRes = NRFJPROG_is_connected_to_emu(&connectedToEmu);
    }

    cmdRes = NRFJPROG_is_connected_to_device(&connectedToDevice);
    if (connectedToDevice == FALSE)
    {
    cmdRes = NRFJPROG_connect_to_device();
    cmdRes = NRFJPROG_is_connected_to_device(&connectedToDevice);
    }

    //Read Byte on chip.
    cmdRes = NRFJPROG_read_u32(addrToRead, &dataRead);

    // Check to see if byte is all FFs, if not erase
    if(dataRead != 4294967295)
    {
    //Erase chip
    cmdRes = NRFJPROG_erase_all();

    cmdRes = NRFJPROG_is_qspi_init(&qspiInitialized);
    if(qspiInitialized == FALSE)
    {
    //Initialize the qspi
    cmdRes = NRFJPROG_qspi_init(1, &aspiInitParams);
    cmdRes = NRFJPROG_is_qspi_init(&qspiInitialized);
    }

    if(qspiInitialized == TRUE)
    //cmdRes = NRFJPROG_qspi_erase(0, ERASEALL);
    cmdRes = NRFJPROG_qspi_erase(301989888, ERASEALL);
    }

    cmdRes = NRFJPROG_power_ram_all();
    cmdRes = NRFJPROG_read_region_0_size_and_source(&size, &source);
    cmdRes = NRFJPROG_disable_bprot();

    //Read binary for boot, option 0
    data_len = ReadBinary(0);
    if(data_len > 0)
    cmdRes = NRFJPROG_write(0,gBootArray,data_len,1);

    ////Read binary for app_wrapped, option 1
    data_len = ReadBinary(1);
    if(data_len > 0)
    cmdRes = NRFJPROG_write(196608,gAppWrappedArray,data_len,1);



    //Read binary for boot, option 0
    data_len = ReadBinary(2);
    if(data_len > 0)
    {
    //gResourcWrappedArray
    uint8_t inst01 = 0x06;
    uint8_t inst02 = 0x01;
    uint8_t inst03 = 0xb7;
    uint8_t dataIn[1];

    dataIn[0] = 0x40;

    cmdRes = NRFJPROG_is_qspi_init(&qspiInitialized);
    if(qspiInitialized == FALSE)
    {
    //Initialize the qspi
    cmdRes = NRFJPROG_qspi_init(1, &aspiInitParams);
    cmdRes = NRFJPROG_is_qspi_init(&qspiInitialized);
    }

    cmdRes = NRFJPROG_qspi_custom(inst01, 1, NULL, NULL);
    cmdRes = NRFJPROG_qspi_custom(inst02, 2, dataIn, NULL);
    cmdRes = NRFJPROG_qspi_custom(inst03, 1, NULL, NULL);

    cmdRes = NRFJPROG_qspi_write(302964736,gResourcWrappedArray,data_len);

    cmdRes = NRFJPROG_sys_reset();

    cmdRes = NRFJPROG_go();

    }


    //************************************************************************************
    //******************************** Cleanup *******************************************
    //************************************************************************************
    if(qspiInitialized == TRUE)
    cmdRes = NRFJPROG_qspi_uninit();

    if (connectedToDevice == TRUE)
    cmdRes = NRFJPROG_disconnect_from_device();

    if (connectedToEmu == TRUE)
    cmdRes = NRFJPROG_disconnect_from_emu();

    if (dllOpen == TRUE)
    NRFJPROG_close_dll();

    FreeLibrary(hinstLib);

    CloseFile(FileHndl);
    //************************************************************************************
    //****************************** End Cleanup *****************************************
    //************************************************************************************

    return 0;
    }

    The qspi is still not working properly and I am running out of things to try.

  • if(qspiInitialized == TRUE)
    //cmdRes = NRFJPROG_qspi_erase(0, ERASEALL);
    cmdRes = NRFJPROG_qspi_erase(301989888, ERASEALL);
    }

    Here is the commented line correct, and the other wrong. qspi_erase() use local address on external memory, the same applies for qspi_write().

    hope that help,
    Kenneth

Reply Children
No Data
Related