Trying to write external flash with SDK 2.2.0

I've been porting an app written for SDK 1.8.0 to SDK 2.2.0

In the old app I've been accessing internal flash memory with  device_get_binding( "NRF_FLASH_DRV_NAME" );  It appears that with 2.2.0 moving to the partition manager that this no longer works.  I haven't been able to figure out how to access the flash controller device.  I was hoping I could get some pointers.

 

  • Hi, 

    device_get_binding() is indeed deprecated since v2.0.0, see this issue: https://github.com/zephyrproject-rtos/zephyr/issues/43230.

    Regards,
    Amanda H.

  • OK. well by using;

    flashDev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller));
    Seems to work.  But then when I try to erase sectors in there I get a security violation.  I've tried to update my _ns .dts to add the scratch partiion;
        chosen {
            zephyr,flash = &flash0;
            zephyr,sram = &sram0_ns;
            zephyr,code-partition = &slot0_ns_partition;
            zephyr,scratch-partition = &scratch_partition;
        };
    But I still get the security violation.  I'm trying ot figure out how to get this partition configured so that I can erase/write it from my non-secure app.
    Thanks.
  • Hi, 

    In NCS, we use the Partition Manager, not the device tree to partition the flash. The Partition Manager is enabled automatically in multi-image builds (such as when you build for non-secure, and get TF-M automatically)

    Which peripheral instance do you use to communicate with the flash?

    We have always used the Partition Manager, but we switched to TF-M somewhere around 2.0.0. And TF-M by default takes control over UART1

    Regards,
    Amanda H.

  • I have no idea what uart1 has to do with all of this.  I'm trying to write to flash.

    I'm getting my flash device like this; flashDev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller));
    Then I'm trying to erase like this; err = flash_erase( flashDev, FLASH_BIN_OFFSET, FLASH_BIN_SIZE ))
    Where FLASH_BIN_OFFSET = 0xF0000 (the start of the scratch_partition) and SIZE is the size of the partition.
    When the erase code gets to the following line;     *(volatile uint32_t *)page_addr = 0xFFFFFFFF; in file nrf_nvmc.h of the inline function nrf_nvmc_page_erase_start, it immediately goes to the C_SecureFault_Handler in faults.c
     and page_addr = 0xF0000, so it's as it should be.
    Randall
  • I just realized that I mistittled this ticket.  I'm not trying to write external flash, but internal flash.

    I've been looking at partitions.yml to try to figure things out.  It looks like this section is now defined;

    EMPTY_2:
      address: 0xf0000
      end_address: 0xf8000
      placement:
        after:
        - mcuboot_secondary
      region: flash_primary
      size: 0x8000
    That used to be the scratch image in the pre 2.x SDKs.  I combined the scratch and the storage partitions in my old builds because I needed 64K of internal storage for my application.  Is there anyway to define a 64k chunk somewhere that can be setup an non_secure?
Related