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.

  • 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

  • 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
  • DevZone does not let me reply inline to the last comment, so I reply in the "top" instead.

    Replay said:
    I have not found anything that is giving me an idea of why it should not work.

    If you upload these files, I can have a look myself.
    Also include the same files for the application alone (since it works).

    Replay said:
    boards/arm/customBoard_nrf9160/c

    If you post the board folder, I can have a look at this as well.

    If you do not want to upload your files in a public case, you can just create a new private ticket for these, and then   and I will find it.

    Do you have a nRF9160DK?
    Cause if you do, we can try to reproduce for the DK and then I can have a similar project on my end.

    Replay said:
    and I'm totally lost on the cause for this failure.

    This case is approaching the point where I struggle to help without being able to reproduce.
    If you have an extra custom PCB laying around, you can ship it to me, and I can reproduce the issue here.
    This way, I can use the experience and tools I got at my disposal to debug this issue.
    Let me know if you want this, and I will send you my shipping info on your DevZone-registered email.

    Regards,
    Sigurd Hellesvik

  • Hi Sigurd

    I really appreciate the support.

    There has been a development in the situation. I cannot explain how but the mcuboot secondary image is now placed in external flash and the user app is being booted.

    The problem is now that im getting this on boot:

     

    *** Booting Zephyr OS build v3.1.99-ncs1-2  ***
    I: Starting bootloader
    W: Failed reading sectors; BOOT_MAX_IMG_SECTORS=256 - too small?
    W: Cannot upgrade: not a compatible amount of sectors
    I: Bootloader chainload address offset: 0x10000
    I: Jumping to the first image slot
    *** Booting Zephyr OS build v3.1.99-ncs1-2  ***
    
    ... Main app started ...

    Maybe this can be solved with a easy setting?

    I have tried increasing CONFIG_BOOT_MAX_IMG_SECTORS=512.

    - Replay

  • Related