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

Creating partitions on external SPI flash

I have added an external SPI flash on the nRF9160 DK board, and wired it up to SPI3.  I want to partition the flash into two ares for separate uses, but the partition_manager script is not generating the partitions for the external flash.  I have added the flash device and the partitions to the overlay file and I can see that the device tree compiler and the #defines generated from it are correct (i.e. I see all of the DT_FLASH_AREA_* values I expect from the partition on the external flash). But because the partition manager does not generate equivalent values in the generated pm_config.h file, I can't use the flash_area_open, flash_area_erase, etc. routines because the partition ID values are not added to the flash_map list.

Is there some way to get these partitions to be included in the generated pm_config.h file?

Thanks for any assistance!

  • Could you share the overlay file, src/main.c, prj.conf and the other files necessary files in order to recreate your behavior. I can make the case private if you would like to.

    Best regards,

    Simon

  • I was able to create a small test case that shows the issue that I am having with the partitions.  The test case has a overlay file for the 9160 DK that adds an external flash on SPI3.  The external flash has two partitions, and the code in main.c attempts to open one of these areas with the "flash_area_open" routine.

    The console shows:

    uart:~$ ***** Booting Zephyr OS v1.14.99-ncs2-3-gf91b3336b61f *****
    Flash LOG failed to open (ret = -2)

    The -2 return is ENOENT, which is returned from flash_area_open when the id value is not found in the list of flash areas.

    I can see the partition information is making it into the generated files (i.e. build/zephyr/include/generated/generated_dts_board_unfixed.h) but because the USE_PARTITION_MANAGER value is set to 1 by the compilation environment, the code in the zephyr/subsys/storage/flash_map/flash_map_default.c looks for PM_* defines instead of DT_FLASH_AREA_* defines.  These are coming from the generated "pm_config.h" file which only contains two partitions for SPM.

    I have attached a small tar file with the files.  I build it from the directory above src with the following steps:

    rm -rf build; mkdir build; cd build
    cmake -GNinja -DBOARD=nrf9160_pca10090ns ..
    ninja
    

    Thanks for the help,

    -paul

    8420.testcase.tgz

  • Thank you, I will take a look at it and try to recreate your error.

    Best regards,

    Simon

  • How is it going? Have you been able to solve this? I have been quite busy the last days and have not been able to make any progress on your issue, my apologies for that. I will look into it the next couple of days.

    Best regards,

    Simon

  • Hello Simon,

    I haven't solved this but I did implement a workaround that helps in this case.  I replaced the flash_area_open() call with this code:

        static const struct flash_area fake_area =
        {
            .fa_id = DT_FLASH_AREA_LOG_ID,
            .fa_off = DT_FLASH_AREA_LOG_OFFSET,
            .fa_size = DT_FLASH_AREA_LOG_SIZE,
            .fa_dev_name = DT_JEDEC_SPI_NOR_0_LABEL,        /* MX25R64 */
        };
    
        flash_area = &fake_area;
    

    and the remainder of the flash area routines, like flash_area_erase, flash_area_read, etc. were able to use this "flash_area" to run.

    This works in my specific case, but I'm not sure if it would be applicable in other cases.

    Thanks for the update,

    -paul

Related