nrf5340: Evaluating Power Consumption of XIP Functions

Hello,

I am looking into evaluating the nrf5340 with different functions running out of external flash, and how current draw is affected by these functions. We are looking at running some code out of qspi flash, and other code internally. We plan to measure the power consumption of different types of code running from the different resources, so we can decide what code is OK to run out of external flash. Is there a simple Zephyr sample project that I can start with where I can set some functions to run XIP out of the external QSPI flash, and others to run internally?

Walt

  • Recently we did some measurements to evaluate performance of the nRF5340 XIP. Execute in place (XIP) allows the CPU to execute program code directly from the external flash: https://infocenter.nordicsemi.com/topic/ps_nrf5340/qspi.html?cp=3_0_0_6_24_4#execute_in_place. Maybe this is something useful for you.

    For the experiment nRF Connect SDK Machine Learning application has been chosen: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/applications/machine_learning/README.html#. Application design allows to separate Edge Impulse library to an external memory. There is only one call to this library from Edge Impulse wrapper module, and therefore this call is used to measure time of execution. Additional measurements of current allowed us to compare total energy used. Please note that given numbers include current consumed only by the nRF5340 alone. To have a complete number you should add an additional current used by an external Flash, which will vary between manufacturers.

    If you plan to run radio operations and use QSPI/XIP concurrently, you should only compare numbers for 1.8V. This is because of the following errata: https://infocenter.nordicsemi.com/topic/errata_nRF5340_Rev1/ERR/nRF5340/Rev1/latest/anomaly_340_133.html?cp=3_0_1_0_1_18

     

    The best results for execution from an external Flash were achieved for CPU freq == 128 MHz, with cache enabled and QSPI speed == 96 MHz. Execution time was 10% longer, and energy used was 27% higher comparing to the same setup while running from the internal Flash.

    Please note that execution time 10% longer, and energy used 27% higher does not apply to the entire solution, but only to a code parts running from an external Flash. If you split the code in a clever way so that rarely used functions are in the external Flash and often used functions are in the internal Flash, the results relating to the overall solution will be much better.

    Here are tips if you would like to repeat these measurements:

    • branch used for the experiment can be found at https://github.com/awojasinski-nordicsemi/sdk-nrf/tree/NRFX-1428-xip-performance-ncs

    • compilation: west build -b nrf5340dk_nrf5340_cpuapp
    • flashing firmware: nrfjprog --coprocessor CP_APPLICATION --sectorerase --qspisectorerase --program build/zephyr/zephyr.hex

    • Compile to external memory:
      • in CMakeLists.txt change compile definition XIP_MEMORY=1
      • in configuration/nrf5340dk_nrf5340_cpuapp/prj.conf change CONFIG_HAVE_CUSTOM_LINKER_SCRIPT to y
    • Compile to internal memory
      • in CMakeLists.txt change compile definition XIP_MEMORY=0
      • in configuration/nrf5340dk_nrf5340_cpuapp/prj.conf change CONFIG_HAVE_CUSTOM_LINKER_SCRIPT to n
    • Change CPU clock to 128MHz
      • in CMakeLists.txt change compile definition CPU_128MHZ=1 (0 => 64MHz, 1=> 128MHz)
    • Change QSPI speed
      • in CMakeLists.txt change compile definition XIP_DIV
        • XIP_DIV=0 => 94MHz
        • XIP_DIV=1 => 48MHz
        • XIP_DIV=2 => 24MHz
    • Disable/Enable Cache
      • in configuration/nrf5340dk_nrf5340_cpuapp/prj.conf change CONFIG_NRF_ENABLE_CACHE to n/y
  • Thanks for this information and the sample project. I download the project and built it. I am having problems flashing it.  I am using the nrf SDK version 1.9.0 and Visual Studio Code with Windows 10.  Here is my flash command and the response:

    nrfjprog --coprocessor CP_APPLICATION --sectorerase --qspisectorerase --verify --program build/zephyr/zephyr.hex --log

    Parsing image file.
    Verifying programming.
    ERROR: [  nRF53] - Data does not match in QSPI memory address range [0x00000000-0x000051f4]
    ERROR: [  nRF53] - QSPI memory verification failed
    ERROR: [  nRF53] - Failed while verifying file build/zephyr/zephyr.hex.
    ERROR: Write verify failed.

    I also tried to make my own little application that places some functions in external flash space. Here is a portion of the map file that shows "test_code" and "test2_code" in external flash space, as well as the flash command and response:

    xip_text        0x10000000       0x34
                    0x10000000                . = ALIGN (0x4)
    xip_text       0x10000000       0x34 app/libapp.a(test_code.c.obj)
                    0x10000000                test_code
                    0x1000001a                test2_code

    But on flashing the device, it shows an error that the program downloader doesn’t know how to write to external QSPI flash.

    nrfjprog --coprocessor CP_APPLICATION --sectorerase --qspisectorerase --verify --program internal_flash/zephyr/zephyr.hex --log

    Parsing image file.
    ERROR: [ Worker] - Address 0x00100000 does not map to a known memory.
    ERROR: The file specified is not a valid hex file, has data outside valid areas
    ERROR: or does not have data in valid areas.

Related