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

How to store a few important parameters of codes in flash in nRF9160?

I want to store a few parameters in flash. I don't want to use an external EEPROM because it takes an additional space on a board.

Does anyone know how to do it or a sample code? 

Thank you in advance.

  • Hi

    Zephyr contains a couple of different libraries for writing data into internal flash. 

    I would suggest you take a look at the NVS library, which is a good place to start. The documentation describes how to use the library, and points to an example also. 

    Best regards
    Torbjørn

  • Thank you for your reply!

    I found the sample code related to nvs: ../nRF9160/ncs/zephyr/samples/subsys/nvs

    This zephyr firmware version was tags/v1.13.99-ncs2, which seems not to support nRF9160 flash writing and reading functions. I had some errors when I copied the main.c and prj.conf, and used it. Then I updated zephyr, mcuboot, nerf, and nrfxlib folders.

    zephyr: tags/v1.14.99-ncs1-rc2
    mcuboot: tags/v1.3.99-ncs1-rc2
    nerf: tags/v0.4.0-rc2
    nrfxlib: tags/v0.4.0-rc2

    The previous errors disappeared, but other errors ware caused.
    Can you give me any advice?
    I copy and use this code: https://github.com/NordicPlayground/fw-nrfconnect-zephyr/tree/master/samples/subsys/nvs

    Building ‘zephyr/zephyr_prebuilt.elf’ from solution ‘build’ in configuration ‘Common’
    1> Linking ‘zephyr_prebuilt.elf’
    1> Memory region         Used Size  Region Size  %age Used
    1>            FLASH:       27796 B       192 KB     14.14%
    1>             SRAM:        6216 B        64 KB      9.48%
    1>         IDT_LIST:         592 B         2 KB     28.91%
    1> /usr/local/opt/gnuarmemb/gcc-arm-none-eabi-7-2018-q2-update/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/bin/ld: warning: orphan section `.gnu.linkonce.sw_isr_table' from `zephyr/libzephyr.a(isr_tables.c.obj)' being placed in section `.gnu.linkonce.sw_isr_table'.
    1> zephyr/libzephyr.a(nrf5_power_clock.c.obj): In function `_clock_control_init':
    1> /Users/fukuharayuusuke/Documents/nRF9160/ncs/zephyr/drivers/clock_control/nrf5_power_clock.c:447: undefined reference to `_irq_priority_set'
    1> /Users/fukuharayuusuke/Documents/nRF9160/ncs/zephyr/drivers/clock_control/nrf5_power_clock.c:451: undefined reference to `_arch_irq_enable'
    1> zephyr/libzephyr.a(nrf5_power_clock.c.obj): In function `_m16src_start':
    1> /Users/fukuharayuusuke/Documents/nRF9160/ncs/zephyr/drivers/clock_control/nrf5_power_clock.c:67: undefined reference to `_arch_irq_disable'
    1> /Users/fukuharayuusuke/Documents/nRF9160/ncs/zephyr/drivers/clock_control/nrf5_power_clock.c:90: undefined reference to `_arch_irq_enable'
    1> zephyr/arch/arm/core/cortex_m/mpu/libarch__arm__core__cortex_m__mpu.a(arm_core_mpu.c.obj): In function `z_arch_configure_static_mpu_regions':
    1> /Users/fukuharayuusuke/Documents/nRF9160/ncs/zephyr/arch/arm/core/cortex_m/mpu/arm_core_mpu.c:130: undefined reference to `_ramfunc_ram_start'
    1> /Users/fukuharayuusuke/Documents/nRF9160/ncs/zephyr/arch/arm/core/cortex_m/mpu/arm_core_mpu.c:130: undefined reference to `_ramfunc_ram_size'
    1> zephyr/kernel/libkernel.a(init.c.obj): In function `z_data_copy':
    1> /Users/fukuharayuusuke/Documents/nRF9160/ncs/zephyr/kernel/init.c:182: undefined reference to `_ramfunc_ram_size'
    1> /Users/fukuharayuusuke/Documents/nRF9160/ncs/zephyr/kernel/init.c:182: undefined reference to `_ramfunc_rom_start'
    1> /Users/fukuharayuusuke/Documents/nRF9160/ncs/zephyr/kernel/init.c:182: undefined reference to `_ramfunc_ram_start'
    1> collect2: error: ld returned 1 exit status
    Build failed

  • Hi

    I have no problem building the example for either the nrf9160_pca10090 or the nrf52_pca10040 boards. 

    Can you delete the build folder and try opening the example again?

    Could you take a screenshot of the parameters in the SES project importer?

    Have you tried to open any of the 9160 examples in the nrf/samples/nrf9160 folder to see if they work?

    Best regards
    Torbjørn 

Related