preload files to 9160?

Hello,

I'm working on an application that will use the nrf9160/nrf52.  I will need to make https REST calls where I will populate the http header with username/password credentials.  It's a huge security hole for me to hardcode those credentials AND we want to make it per-device specific (there will be many devices manufactured using the nrf91/nrf52 SoC.  So it would be ideal to preload some configuration file or something of the like which will represent the credentials to be accessed by the application that will be flashed after.  Also the production device will have no outside USB connection and the flash will be programmed using "pads".  Is there a way to send down something in some format to somewhere PRIOR to flashing the application?

Thanks

/Loren

Parents
  • Hi Loren

    If you have a debugger connected you could write a script that flashes some configuration data into a fixed location in flash. 

    As long as you make sure that the application and other modules don't use this area of the flash for storing anything (code or data), you can then read out this information from the application at a later time. 

    To access the flash through the debugger you can use the nrfjprog command line utility (or the pynrfjprog version, for Python). 

    Best regards
    Torbjørn

  • Hi Torbjorn!

    Thank you for the quick response!  The plan is to create a custom board using the nrf9160 chip (not using DK board).  There will be no USB connectors on this board. Is there a way to attach a debugger with no USB connector?

    /Loren

Reply Children
  • Hi Loren

    Yes, the programming interface is based on the SWD protocol, not USB, and you just need access to the SWDIO and SWDCLK pins from the nRF9160 (pin 33 and 34 in the pinout). 

    Typically you will also need to connect ground and VDD to the debugger, so keep this in mind if you want to put test points or pads for a connector on your board.

    On the nRF9160DK the interface chip handles the USB to SWD conversion, so you don't need a separate debugger connected. 

    Best regards
    Torbjørn

  • Wonderful, Torbjorn!

    I'm assuming I would have to specify the area in flash to put both the configuration data AND the application code?  I've always just let either west or SES decide where to flash my application.  Are there any examples that contain steps on how to specify where in flash to put "configuration data" and my application?

    Thanks!

    /Loren

  • Hi Loren

    You can use the partition manger for this. Please start by reading through the documentation, here, and let me know afterwards if anything is unclear. 

    The partition manager is a bit complex, so I would expect you to have some more questions after reading the documentation ;)

    Best regards
    Torbjørn

  • Yeah I found this yesterday.  It is very complex, lol.  Another thing I was hoping there would be samples for is writing data to flash.  Do I use UICR?  FDS?  I've been looking at nrfjprog command line arguments.  Would I want to use something like this: https://github-wiki-see.page/m/cristianoborgescardoso/nrf52/wiki/Write-and-read-data-at-UICR?  Is there something else I could use?  I've been reading the documentation and looking here on the forums, but I can't seem to find anything that is suited to what I am trying to achieve.  

    Thank you Torbjorn!

    /Loren

  • Hi Loren

    You mean in order to write to the flash from the debugger, right?

    Looking at the documentation it appears there are no user variables available in the UICR for the nRF9160, which means you will need to write your data into the normal application flash instead (address range 0x0-0x100000). 

    You need to find a free area of the flash that is not used for anything else, normally this would be at the top of the memory range, allowing room for the application at the bottom. 

    In order to write to the flash using the debugger you can use commands similar to the ones shared in the link you sent:

    nrfjprog -f NRF91 --memwr 0x000XXXXX --val 0x1234abcd

    To read from the flash internally from the MCU all you have to do is refer to the same memory address, something like this:

    const uint32_t * flash_ptr = (uint32_t*)0x00001234;
    uint32_t flash_data = *flash_ptr;
    Best regards
    Torbjørn




Related