Utilize external flash with nrf9160 SiP on Custom board.

Hi,

I would like to use the external flash to increase the internal flash, no intention, at the moment, to use it for MCUBoot file or FOTA .

How do I configure it, if it is even possible.

Info:

- nRF Connect SDK: 2.0.0

- nrf9160 SiP on custom board.

- Flash commuincate over SPI.

- Flash is working.

Thanks in advance.

Parents
  • Hi,

    Yes, this is possible.

    On our nRF9160DK, we have an external flash, and you can see a sample for testing this at nRF9160: HTTP application update using the nRF9160DK's external flash.
    This sample is for v1.7.0, but it is possible to do the same for v2.0.0.

    Regards,
    Sigurd Hellesvik

  • Thank you.

    After setting up the external flash in the .overlay file:

    nordic,pm-ext-flash = &mx25r16;
    It builds fine but when running the program this is what I get:
    When getting the partition_manager_report:
    external_flash (0x200000 - 2048kB):
    +---------------------------------------------+
    | 0x0: mcuboot_secondary (0xe8000 - 928kB) |
    | 0xe8000: external_flash (0x118000 - 1120kB) |
    +---------------------------------------------+
    
    flash_primary (0x100000 - 1024kB):
    +--------------------------------------------------+
    | 0x0: mcuboot (0xc000 - 48kB) |
    | 0xc000: EMPTY_0 (0x4000 - 16kB) |
    +---0x10000: mcuboot_primary (0xe8000 - 928kB)-----+
    +---0x10000: tfm_secure (0xc200 - 48kB)------------+
    | 0x10000: mcuboot_pad (0x200 - 512B) |
    +---0x10200: mcuboot_primary_app (0xe7e00 - 927kB)-+
    | 0x10200: tfm (0xc000 - 48kB) |
    +---0x1c200: tfm_nonsecure (0xdbe00 - 879kB)-------+
    | 0x1c200: app (0xdbe00 - 879kB) |
    +---0xf8000: nonsecure_storage (0x2000 - 8kB)------+
    | 0xf8000: settings_storage (0x2000 - 8kB) |
    +--------------------------------------------------+
    | 0xfa000: EMPTY_1 (0x6000 - 24kB) |
    +--------------------------------------------------+
    
    otp (0x2f4 - 756B):
    +------------------------------+
    | 0xff8108: otp (0x2f4 - 756B) |
    +------------------------------+
    
    sram_primary (0x40000 - 256kB):
    +--------------------------------------------------+
    +---0x20000000: sram_secure (0x10000 - 64kB)-------+
    | 0x20000000: tfm_sram (0x10000 - 64kB) |
    +---0x20010000: sram_nonsecure (0x30000 - 192kB)---+
    +---0x20010000: nrf_modem_lib_sram (0x44e8 - 17kB)-+
    | 0x20010000: nrf_modem_lib_ctrl (0x4e8 - 1kB) |
    | 0x200104e8: nrf_modem_lib_tx (0x2000 - 8kB) |
    | 0x200124e8: nrf_modem_lib_rx (0x2000 - 8kB) |
    +--------------------------------------------------+
    | 0x200144e8: sram_primary (0x2bb18 - 174kB) |
    +--------------------------------------------------+
    When I tried to add this to the .prj file:
    CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=n
    This works as expected.
    My question is now; Is it possible to utilize the external flash compile time?
    The HTTP sample uses it run time, correct me if I'm wrong on that.
    Another question is: the external flash do not have the correct size, even though I have added the size to the spi setup in the .overlay file. Do I need to add a pm_static.yml for getting the correct sized configured?
  • If you build using VS Code, make sure that you do not have debugging options inthe build configuration screen here either.

    Other typical issues that cause MCUboot to run and not the application is that important configurations are missing for the MCUboot child image.

    How do you include mcuboot.conf into your project?

    Do you have configurations relevant for your custom board inside mcuboot.conf?

    Does you  project work without the Bootlaoder?

    Regards,
    Sigurd Hellesvik

  • If you build using VS Code, make sure that you do not have debugging options inthe build configuration screen here either.

    No debugging is enabled. No debugging in prj.conf and not in the configuration screen.

    child_image / mcuboot.conf:

    CONFIG_NORDIC_QSPI_NOR=n
    CONFIG_SPI=y
    CONFIG_SPI_NOR=y
    CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
    
    CONFIG_BOOT_SIGNATURE_KEY_FILE="C:/ncs/xxxx/certs/private_mcuboot.pem"
    
    CONFIG_MULTITHREADING=y
    
    CONFIG_SIZE_OPTIMIZATIONS=y
    
    # MCUboot requires a large stack size, otherwise an MPU fault will occur
    CONFIG_MAIN_STACK_SIZE=10240
    
    # Enable flash operations
    CONFIG_FLASH=y
    
    # This must be increased to accommodate the bigger images.
    CONFIG_BOOT_MAX_IMG_SECTORS=256

    How do you include mcuboot.conf into your project?

    I'm not sure what you are referring to.

    Do you have configurations relevant for your custom board inside mcuboot.conf?

    No, not by intention.

    Does you  project work without the Bootlaoder?

    I'll get back regarding this information. 

    (Edit): Yes, it runs as expected when removing bootloader.

  • Replay said:
    No, not by intention.

    This is a frequent source to problems similar to the one you see: The project fails if MCUboot is enabled.

    For example:  RE: Enabling MCUBOOT does not run application

    Try to explicitly set all configurations relevant for your custom board inside mcuboot.conf as well.

    Replay said:
    I'm not sure what you are referring to.

    I was asking if you used child_image/mcuboot.conf. You answered this in the same answer. This is the correct way to do it.

    Regards,
    Sigurd Hellesvik

  • Hi

    In build/zephyr/.config, the only difference from nrf9160 DK, is the TF-M UART pins:

    nrf9160 DK:

    CONFIG_TFM_UART0_TXD_PIN=29
    CONFIG_TFM_UART0_RXD_PIN=28
    CONFIG_TFM_UART0_RTS_PIN=27
    CONFIG_TFM_UART0_CTS_PIN=26
    Custom board:
    CONFIG_TFM_UART0_TXD_PIN=4294967295
    CONFIG_TFM_UART0_RXD_PIN=4294967295
    CONFIG_TFM_UART0_RTS_PIN=4294967295
    CONFIG_TFM_UART0_CTS_PIN=4294967295
    Can this has an effect on the problem?
  • Maybe, but that would be a bit odd.
    You can try to set them though.

    Also check build/mcuboot/zephyr/.config, as this is for the bootloader.

    On that topic, compare the following to see if you can find anything suspicious:

    • build/zephyr/.config
    • build/zephyr/zephyr.dts
    • build/mcuboot/zephyr/.config
    • build/mcuboot/zephyr/zephyr.dts

    Regards,
    Sigurd Hellesvik

Reply Children
  • Okay I have been looking in to this problem the past few days, and I'm totally lost on the cause for this failure.

    If you got time, I'll post the total overview for you to get the full picture.

    - NCS: 2.3.0

    - SiP: nrf9160 on custom board

    - External Flash: mx25r16

    Project setup:

    boards/arm/customBoard_nrf9160/customBoard_nrf9160_common-pinctrl.dtsi:

    &pinctrl {
    	spi0_default: spi0_default {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 2)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 1)>,
    				<NRF_PSEL(SPIM_MISO, 0, 0)>;
    		};
    	};
    
    	spi0_sleep: spi0_sleep {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 2)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 1)>,
    				<NRF_PSEL(SPIM_MISO, 0, 0)>;
    			low-power-enable;
    		};
    	};
    };

    boards/arm/customBoard_nrf9160/customBoard_nrf9160_common.dts:

    &spi0 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	pinctrl-0 = <&spi0_default>;
    	pinctrl-1 = <&spi0_sleep>;
    	pinctrl-names = "default", "sleep";
    	cs-gpios = <&gpio0 3 GPIO_ACTIVE_LOW>;
      mx25r16: mx25r1635f@0 {
        compatible = "jedec,spi-nor";
        reg = <0>;
        spi-max-frequency = <8000000>;
        jedec-id = [c2 28 15];
        size = <16777216>;
        reset-gpios = <&gpio0 4 GPIO_ACTIVE_LOW>;
      };
    };

    prj.conf:

    CONFIG_SPI=y
    CONFIG_SPI_NOR=y
    CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
    CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y
    CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y
    CONFIG_MULTITHREADING=y
    CONFIG_BUILD_WITH_TFM=y
    CONFIG_BOOTLOADER_MCUBOOT=y

    child_image\mcuboot.conf:

    CONFIG_SPI=y
    CONFIG_SPI_NOR=y
    CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
    
    CONFIG_BOOT_SIGNATURE_KEY_FILE="C:/ncs/xxx/certs/private_mcuboot.pem"
    
    CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y
    
    CONFIG_MULTITHREADING=y
    
    CONFIG_SIZE_OPTIMIZATIONS=y
    
    # MCUboot requires a large stack size, otherwise an MPU fault will occur
    CONFIG_MAIN_STACK_SIZE=10240
    
    # Enable flash operations
    CONFIG_FLASH=y
    
    # This must be increased to accommodate the bigger images.
    CONFIG_BOOT_MAX_IMG_SECTORS=256
    child_image/mcuboot/customBoard_nrf960.overlay:
    / {	
    	chosen {
        nordic,pm-ext-flash = &mx25r16;
    	};
    };
    customBoard_nrf960_ns.overlay:
    / {
    	chosen {
            nordic,pm-ext-flash = &mx25r16;
    	};
    };
    Partition manager report:
      external_flash (0x200000 - 2048kB):
    +---------------------------------------------+
    | 0x0: mcuboot_secondary (0xe8000 - 928kB)    |
    | 0xe8000: external_flash (0x118000 - 1120kB) |
    +---------------------------------------------+
    
      flash_primary (0x100000 - 1024kB):
    +--------------------------------------------------+
    | 0x0: mcuboot (0xc000 - 48kB)                     |
    | 0xc000: EMPTY_0 (0x4000 - 16kB)                  |
    +---0x10000: mcuboot_primary (0xe8000 - 928kB)-----+
    +---0x10000: tfm_secure (0x8000 - 32kB)------------+
    | 0x10000: mcuboot_pad (0x200 - 512B)              |
    +---0x10200: mcuboot_primary_app (0xe7e00 - 927kB)-+
    | 0x10200: tfm (0x7e00 - 31kB)                     |
    +---0x18000: tfm_nonsecure (0xe0000 - 896kB)-------+
    | 0x18000: app (0xe0000 - 896kB)                   |
    +---0xf8000: nonsecure_storage (0x2000 - 8kB)------+
    | 0xf8000: settings_storage (0x2000 - 8kB)         |
    +--------------------------------------------------+
    | 0xfa000: EMPTY_1 (0x6000 - 24kB)                 |
    +--------------------------------------------------+
    
      otp (0x2f4 - 756B):
    +------------------------------+
    | 0xff8108: otp (0x2f4 - 756B) |
    +------------------------------+
    
      sram_primary (0x40000 - 256kB):
    +--------------------------------------------------+
    +---0x20000000: mcuboot_sram (0x8000 - 32kB)-------+
    +---0x20000000: sram_secure (0x8000 - 32kB)--------+
    | 0x20000000: tfm_sram (0x8000 - 32kB)             |
    +---0x20008000: sram_nonsecure (0x38000 - 224kB)---+
    +---0x20008000: nrf_modem_lib_sram (0x4568 - 17kB)-+
    | 0x20008000: nrf_modem_lib_ctrl (0x4e8 - 1kB)     |
    | 0x200084e8: nrf_modem_lib_tx (0x2080 - 8kB)      |
    | 0x2000a568: nrf_modem_lib_rx (0x2000 - 8kB)      |
    +--------------------------------------------------+
    | 0x2000c568: sram_primary (0x33a98 - 206kB)       |
    +--------------------------------------------------+

    On that topic, compare the following to see if you can find anything suspicious:

    • build/zephyr/.config
    • build/zephyr/zephyr.dts
    • build/mcuboot/zephyr/.config
    • build/mcuboot/zephyr/zephyr.dts
    I have not found anything that is giving me an idea of why it should not work.
    Thank you for the help Smiley
    - Replay
Related