This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

To identify, adjust sleep period of sample app threads?

Hello Devzone Community,

My name is Ted, and I am continuing my effort to configure a Zephyr based, Nordic aws_iot sample app based firmware to run and support nRF9160 lowest specified power consumption. I am in the process of putting all application threads to sleep, so that Zephyr's idle thread can put the application processor into a low power sleep mode. Nordic Power Profiler waveforms of measured current draw, however, indicate that I've failed in this. Some part of the overall firmware binary appears to be yet running. Lowest average current I achieve is ~190 microamps.

My Devzone account doesn't permit me to upload photos, but here is a link to two captures from Nordic's power profile which I took earlier today.  My apology that I must include an external link here and not the images directly:

wiki.neelanurseries.com/.../20220311

The first one shows a general pattern of current regularly spiking from a few microamps to around three milliamps.  The zoomed capture shows the ten millisecond spikes, a more distinct fast spike and a more blunted longer duration one.

These are taken during a 45 second period when all my application threads are sleeping -- for 45 seconds -- and LTE modem is turned off, and GPIOs to hardware enable points of our board are also turned off, effectively powering down the hardware outside the nRF9160.

From these waveforms I observe that some ARM processor activity appears to be consuming current every ten milliseconds. But though I have put my app threads into a nearly minute long sleep period, and have searched for the sleep periods set on aws_iot sample app threads, I cannot see any firmware configured device or service that is configured to run every ten milliseconds.

This work is based on Nordic's aws_iot sample app, as it appears in ncs v1.6.1. The sample app creates three or four Zephyr threads. Zephyr itself creates a  thread for `int main()` and an idle thread. Work of my own adds a few more threads at run time. These latest threads I can readily put to sleep for minutes or even hours, with a call to k_sleep() in a given thread's effective main function.

I have enabled Zephyr's thread_analyzer feature, and can observe simple reporting at run time of the threads of this firmware. Here is a typical Zephyr output I can see via a serial connection, and using a simple CLI to invoke a handful of commands:

Excerpt 1: Zephyr thread summary report

```1) 'thread_accelerometer' stack size 2048 bytes, stack used 960 bytes, 46%
2) 'thread_dev_work' stack size 3072 bytes, stack used 1504 bytes, 48%
3) 'thread_simple_cli' stack size 4096 bytes, stack used 1768 bytes, 43%
4) 'thread_led' stack size 512 bytes, stack used 136 bytes, 26%
5) 'download_client' stack size 4096 bytes, stack used 104 bytes, 2%
6) 'at_cmd_socket_thread' stack size 1472 bytes, stack used 688 bytes, 46%
7) 'time_thread' stack size 1024 bytes, stack used 728 bytes, 71%
8) 'connection_poll_thread' stack size 3072 bytes, stack used 296 bytes, 9%
9) '0x20015ab0' stack size 1024 bytes, stack used 168 bytes, 16%
10) 'sysworkq' stack size 2048 bytes, stack used 168 bytes, 8%
11) 'idle 00' stack size 320 bytes, stack used 56 bytes, 17%```


Here I modify the report to annotate each thread's origin, which affects how easily or not I can adjust a thread's sleep time:

Excerpt 2:

```1) 'thread_accelerometer' . . . home authored application
2) 'thread_dev_work' . . . home authored application
3) 'thread_simple_cli' . . . home authored application
4) 'thread_led' . . . home authored application
5) 'download_client' . . . aws_iot sample app
6) 'at_cmd_socket_thread' . . . aws_iot sample app
7) 'time_thread' . . . aws_iot sample app
8) 'connection_poll_thread' . . . aws_iot sample app
9) '0x20015ab0' . . . ?, not known
10) 'sysworkq' . . . Zephyr 2.6.0
11) 'idle 00' . . . Zephyr 2.6.0```


So far I have been able to track down in Zephyr's dwt.h library header file that the time thread has a default sleep period of 3600 seconds. Tracing thread 'at_cmd_socket_thread' which is implemented in ncs/nrf/subsys/net/lib/aws_iot/src/aws_iot.c I cannot tell what this thread's effective sleep period is.

Question (1): Can a Devzone team member or community member help me identify where this thread's sleep time is realized?

I have yet to find the implementation details for thread 'download_client', 'connection_poll_thread' and '0x20015ab0'. The last of these threads I have concern for. It is not named, and so I cannot be sure whether it is a Zephyr construct or a Nordic sample app construct. This unnamed thread has shown in the thread analyzer report since I enabled Zephyr's analyzer.


Question (2): is static code analysis the only way to learn "who" in the Zephyr and other source codes is creating the unnamed thread?

Until I can identify the unnamed thread, I won't know whether I can cleanly properly adjust its sleep period. If it is a kernel thread, my app space firmware won't automatically have privileges to make any changes to a kernel thread. I believe there are some extra steps to be able to do so, if that is even possible.

I recognize also that I cannot simply change sleep times of the aws_iot sample app threads, and expect celular level and MQTT client-broker connections to continue to function. I'll need to study and find a way to cleanly close connections before putting such threads to sleep.

Thanks ahead of time to all who can shed some light and help on these deep sleep and nRF9160 power saving questions!

- Ted

  • Hi Didrik,

    Thank you for the modified "hello_world" project.  For some reason I not able to compile this Nordic + Zephyr based application.  I am still using ncs SDK 1.6.1.  My various compiler tools are recent enough to pass the early tool version checks.  But I have never before seen the cyclic behavior I'm now getting as the build process parses all Kconfig dependencies. About every sixty six lines of build output the compiling appears to repeat itself.  I have never seen this kind of erroneous behavior in a `west` based build:

     

    ted@vibratsiya:~/projects/ncs/hello-world-1462$ west build -b nrf9160dk_nrf9160
    -- west build: generating a build system
    Including boilerplate (Zephyr base): /home/ted/projects/ncs/zephyr/cmake/app/boilerplate.cmake
    CMake Deprecation Warning at /home/ted/projects/ncs/zephyr/cmake/app/boilerplate.cmake:37 (cmake_policy):
      The OLD behavior for policy CMP0079 will be removed from a future version
      of CMake.
    
      The cmake-policies(7) manual explains that the OLD behaviors of all
      policies are deprecated and that a policy should be set to OLD only under
      specific short-term circumstances.  Projects should be ported to the NEW
      behavior and not rely on setting a policy to OLD.
    Call Stack (most recent call first):
      /home/ted/projects/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      /home/ted/projects/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:35 (include_boilerplate)
      CMakeLists.txt:5 (find_package)
    
    
    -- Application: /home/ted/projects/ncs/hello-world-1462
    -- Zephyr version: 2.6.0-rc1 (/home/ted/projects/ncs/zephyr), build: v2.6.0-rc1-ncs1
    -- Found Python3: /usr/bin/python3.8 (found suitable exact version "3.8.10") found components: Interpreter 
    -- Found west (found suitable version "0.12.0", minimum required is "0.7.1")
    -- Board: nrf9160dk_nrf9160, Revision: 0.7.0
    -- Cache files will be written to: /home/ted/.cache/zephyr
    -- Found dtc: /usr/bin/dtc (found suitable version "1.5.0", minimum required is "1.4.6")
    -- Found toolchain: gnuarmemb (/opt/gcc-arm-none-eabi-10.3-2021.10)
    -- Found BOARD.dts: /home/ted/projects/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160.dts
    -- Generated zephyr.dts: /home/ted/projects/ncs/hello-world-1462/build/zephyr/zephyr.dts
    -- Generated devicetree_unfixed.h: /home/ted/projects/ncs/hello-world-1462/build/zephyr/include/generated/devicetree_unfixed.h
    -- Generated device_extern.h: /home/ted/projects/ncs/hello-world-1462/build/zephyr/include/generated/device_extern.h
    Parsing /home/ted/projects/ncs/zephyr/Kconfig
    Loaded configuration '/home/ted/projects/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160_defconfig'
    Merged configuration '/home/ted/projects/ncs/hello-world-1462/prj.conf'
    Configuration saved to '/home/ted/projects/ncs/hello-world-1462/build/zephyr/.config'
    Kconfig header saved to '/home/ted/projects/ncs/hello-world-1462/build/zephyr/include/generated/autoconf.h'
    
    warning: UART_CONSOLE (defined at drivers/console/Kconfig:47) was assigned the value 'y' but got the
    value 'n'. Check these unsatisfied dependencies: SERIAL (=n), SERIAL_HAS_DRIVER (=n). See
    http://docs.zephyrproject.org/latest/reference/kconfig/CONFIG_UART_CONSOLE.html and/or look up
    UART_CONSOLE in the menuconfig/guiconfig interface. The Application Development Primer, Setting
    Configuration Values, and Kconfig - Tips and Best Practices sections of the manual might be helpful
    too.
    
    -- The C compiler identification is GNU 10.3.1
    -- The CXX compiler identification is GNU 10.3.1
    -- The ASM compiler identification is GNU
    -- Found assembler: /opt/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gcc
    CMake Deprecation Warning at /home/ted/projects/ncs/modules/lib/civetweb/CMakeLists.txt:2 (cmake_minimum_required):
      Compatibility with CMake < 2.8.12 will be removed from a future version of
      CMake.
    
      Update the VERSION argument <min> value or use a ...<max> suffix to tell
      CMake that the project does not need compatibility with older versions.
    
    
    -- Configuring done
    CMake Warning (dev) at /home/ted/projects/ncs/zephyr/cmake/linker/ld/target.cmake:33 (add_custom_command):
      Policy CMP0116 is not set: Ninja generators transform DEPFILEs from
      add_custom_command().  Run "cmake --help-policy CMP0116" for policy
      details.  Use the cmake_policy command to set the policy and suppress this
      warning.
    Call Stack (most recent call first):
      /home/ted/projects/ncs/zephyr/CMakeLists.txt:1198 (configure_linker_script)
    This warning is for project developers.  Use -Wno-dev to suppress it.
    
    CMake Warning (dev) at /home/ted/projects/ncs/zephyr/cmake/linker/ld/target.cmake:33 (add_custom_command):
      Policy CMP0116 is not set: Ninja generators transform DEPFILEs from
      add_custom_command().  Run "cmake --help-policy CMP0116" for policy
      details.  Use the cmake_policy command to set the policy and suppress this
      warning.
    Call Stack (most recent call first):
      /home/ted/projects/ncs/zephyr/CMakeLists.txt:1253 (configure_linker_script)
    This warning is for project developers.  Use -Wno-dev to suppress it.
    
    -- Generating done
    -- Build files have been written to: /home/ted/projects/ncs/hello-world-1462/build
    -- west build: building application
    [0/1] Re-running CMake...
    Including boilerplate (Zephyr base (cached)): /home/ted/projects/ncs/zephyr/cmake/app/boilerplate.cmake
    CMake Deprecation Warning at /home/ted/projects/ncs/zephyr/cmake/app/boilerplate.cmake:37 (cmake_policy):
      The OLD behavior for policy CMP0079 will be removed from a future version
      of CMake.
    
      The cmake-policies(7) manual explains that the OLD behaviors of all
      policies are deprecated and that a policy should be set to OLD only under
      specific short-term circumstances.  Projects should be ported to the NEW
      behavior and not rely on setting a policy to OLD.
    Call Stack (most recent call first):
      /home/ted/projects/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      /home/ted/projects/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:40 (include_boilerplate)
      CMakeLists.txt:5 (find_package)
    
    
    -- Application: /home/ted/projects/ncs/hello-world-1462
    -- Zephyr version: 2.6.0-rc1 (/home/ted/projects/ncs/zephyr), build: v2.6.0-rc1-ncs1
    -- Found west (found suitable version "0.12.0", minimum required is "0.7.1")
    -- Board: nrf9160dk_nrf9160, Revision: 0.7.0
    -- Cache files will be written to: /home/ted/.cache/zephyr
    -- Found dtc: /usr/bin/dtc (found suitable version "1.5.0", minimum required is "1.4.6")
    -- Found toolchain: gnuarmemb (/opt/gcc-arm-none-eabi-10.3-2021.10)
    -- Found BOARD.dts: /home/ted/projects/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160.dts
    -- Generated zephyr.dts: /home/ted/projects/ncs/hello-world-1462/build/zephyr/zephyr.dts
    -- Generated devicetree_unfixed.h: /home/ted/projects/ncs/hello-world-1462/build/zephyr/include/generated/devicetree_unfixed.h
    -- Generated device_extern.h: /home/ted/projects/ncs/hello-world-1462/build/zephyr/include/generated/device_extern.h
    Parsing /home/ted/projects/ncs/zephyr/Kconfig
    Loaded configuration '/home/ted/projects/ncs/hello-world-1462/build/zephyr/.config'
    No change to configuration in '/home/ted/projects/ncs/hello-world-1462/build/zephyr/.config'
    No change to Kconfig header in '/home/ted/projects/ncs/hello-world-1462/build/zephyr/include/generated/autoconf.h'
    CMake Deprecation Warning at /home/ted/projects/zephyr-based-2/modules/lib/civetweb/CMakeLists.txt:2 (cmake_minimum_required):
      Compatibility with CMake < 2.8.12 will be removed from a future version of
      CMake.
    
      Update the VERSION argument <min> value or use a ...<max> suffix to tell
      CMake that the project does not need compatibility with older versions.
    
    
    -- Configuring done
    CMake Warning (dev) at /home/ted/projects/ncs/zephyr/cmake/linker/ld/target.cmake:33 (add_custom_command):
      Policy CMP0116 is not set: Ninja generators transform DEPFILEs from
      add_custom_command().  Run "cmake --help-policy CMP0116" for policy
      details.  Use the cmake_policy command to set the policy and suppress this
      warning.
    Call Stack (most recent call first):
      /home/ted/projects/ncs/zephyr/CMakeLists.txt:1198 (configure_linker_script)
    This warning is for project developers.  Use -Wno-dev to suppress it.
    
    CMake Warning (dev) at /home/ted/projects/ncs/zephyr/cmake/linker/ld/target.cmake:33 (add_custom_command):
      Policy CMP0116 is not set: Ninja generators transform DEPFILEs from
      add_custom_command().  Run "cmake --help-policy CMP0116" for policy
      details.  Use the cmake_policy command to set the policy and suppress this
      warning.
    Call Stack (most recent call first):
      /home/ted/projects/ncs/zephyr/CMakeLists.txt:1253 (configure_linker_script)
    This warning is for project developers.  Use -Wno-dev to suppress it.
    
    -- Generating done
    -- Build files have been written to: /home/ted/projects/ncs/hello-world-1462/build
    [0/1] Re-running CMake...
    Including boilerplate (Zephyr base (cached)): /home/ted/projects/ncs/zephyr/cmake/app/boilerplate.cmake
    CMake Deprecation Warning at /home/ted/projects/ncs/zephyr/cmake/app/boilerplate.cmake:37 (cmake_policy):
      The OLD behavior for policy CMP0079 will be removed from a future version
      of CMake.
    
      The cmake-policies(7) manual explains that the OLD behaviors of all
      policies are deprecated and that a policy should be set to OLD only under
      specific short-term circumstances.  Projects should be ported to the NEW
      behavior and not rely on setting a policy to OLD.
    Call Stack (most recent call first):
      /home/ted/projects/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      /home/ted/projects/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:40 (include_boilerplate)
      CMakeLists.txt:5 (find_package)
    
    
    -- Application: /home/ted/projects/ncs/hello-world-1462
    -- Zephyr version: 2.6.0-rc1 (/home/ted/projects/ncs/zephyr), build: v2.6.0-rc1-ncs1
    -- Found west (found suitable version "0.12.0", minimum required is "0.7.1")
    -- Board: nrf9160dk_nrf9160, Revision: 0.7.0
    -- Cache files will be written to: /home/ted/.cache/zephyr
    -- Found dtc: /usr/bin/dtc (found suitable version "1.5.0", minimum required is "1.4.6")
    -- Found toolchain: gnuarmemb (/opt/gcc-arm-none-eabi-10.3-2021.10)
    -- Found BOARD.dts: /home/ted/projects/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160.dts
    -- Generated zephyr.dts: /home/ted/projects/ncs/hello-world-1462/build/zephyr/zephyr.dts
    -- Generated devicetree_unfixed.h: /home/ted/projects/ncs/hello-world-1462/build/zephyr/include/generated/devicetree_unfixed.h
    -- Generated device_extern.h: /home/ted/projects/ncs/hello-world-1462/build/zephyr/include/generated/device_extern.h
    Parsing /home/ted/projects/ncs/zephyr/Kconfig
    Loaded configuration '/home/ted/projects/ncs/hello-world-1462/build/zephyr/.config'
    No change to configuration in '/home/ted/projects/ncs/hello-world-1462/build/zephyr/.config'
    No change to Kconfig header in '/home/ted/projects/ncs/hello-world-1462/build/zephyr/include/generated/autoconf.h'
    CMake Deprecation Warning at /home/ted/projects/zephyr-based-2/modules/lib/civetweb/CMakeLists.txt:2 (cmake_minimum_required):
      Compatibility with CMake < 2.8.12 will be removed from a future version of
      CMake.
    
      Update the VERSION argument <min> value or use a ...<max> suffix to tell
      CMake that the project does not need compatibility with older versions.
    
    
    -- Configuring done
    CMake Warning (dev) at /home/ted/projects/ncs/zephyr/cmake/linker/ld/target.cmake:33 (add_custom_command):
      Policy CMP0116 is not set: Ninja generators transform DEPFILEs from
      add_custom_command().  Run "cmake --help-policy CMP0116" for policy
      details.  Use the cmake_policy command to set the policy and suppress this
      warning.
    Call Stack (most recent call first):
      /home/ted/projects/ncs/zephyr/CMakeLists.txt:1198 (configure_linker_script)
    This warning is for project developers.  Use -Wno-dev to suppress it.
    
    CMake Warning (dev) at /home/ted/projects/ncs/zephyr/cmake/linker/ld/target.cmake:33 (add_custom_command):
      Policy CMP0116 is not set: Ninja generators transform DEPFILEs from
      add_custom_command().  Run "cmake --help-policy CMP0116" for policy
      details.  Use the cmake_policy command to set the policy and suppress this
      warning.
    Call Stack (most recent call first):
      /home/ted/projects/ncs/zephyr/CMakeLists.txt:1253 (configure_linker_script)
    This warning is for project developers.  Use -Wno-dev to suppress it.
    
    -- Generating done
    -- Build files have been written to: /home/ted/projects/ncs/hello-world-1462/build
    [0/1] Re-running CMake...
    Including boilerplate (Zephyr base (cached)): /home/ted/projects/ncs/zephyr/cmake/app/boilerplate.cmake
    CMake Deprecation Warning at /home/ted/projects/ncs/zephyr/cmake/app/boilerplate.cmake:37 (cmake_policy):
      The OLD behavior for policy CMP0079 will be removed from a future version
      of CMake.
    
      The cmake-policies(7) manual explains that the OLD behaviors of all
      policies are deprecated and that a policy should be set to OLD only under
      specific short-term circumstances.  Projects should be ported to the NEW
      behavior and not rely on setting a policy to OLD.
    Call Stack (most recent call first):
      /home/ted/projects/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      /home/ted/projects/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:40 (include_boilerplate)
      CMakeLists.txt:5 (find_package)
    
    
    -- Application: /home/ted/projects/ncs/hello-world-1462
    -- Zephyr version: 2.6.0-rc1 (/home/ted/projects/ncs/zephyr), build: v2.6.0-rc1-ncs1
    -- Found west (found suitable version "0.12.0", minimum required is "0.7.1")
    -- Board: nrf9160dk_nrf9160, Revision: 0.7.0
    -- Cache files will be written to: /home/ted/.cache/zephyr
    -- Found dtc: /usr/bin/dtc (found suitable version "1.5.0", minimum required is "1.4.6")
    -- Found toolchain: gnuarmemb (/opt/gcc-arm-none-eabi-10.3-2021.10)
    -- Found BOARD.dts: /home/ted/projects/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160.dts
    -- Generated zephyr.dts: /home/ted/projects/ncs/hello-world-1462/build/zephyr/zephyr.dts
    -- Generated devicetree_unfixed.h: /home/ted/projects/ncs/hello-world-1462/build/zephyr/include/generated/devicetree_unfixed.h
    -- Generated device_extern.h: /home/ted/projects/ncs/hello-world-1462/build/zephyr/include/generated/device_extern.h
    Parsing /home/ted/projects/ncs/zephyr/Kconfig
    Loaded configuration '/home/ted/projects/ncs/hello-world-1462/build/zephyr/.config'
    No change to configuration in '/home/ted/projects/ncs/hello-world-1462/build/zephyr/.config'
    No change to Kconfig header in '/home/ted/projects/ncs/hello-world-1462/build/zephyr/include/generated/autoconf.h'
    CMake Deprecation Warning at /home/ted/projects/zephyr-based-2/modules/lib/civetweb/CMakeLists.txt:2 (cmake_minimum_required):
      Compatibility with CMake < 2.8.12 will be removed from a future version of
      CMake.
    
      Update the VERSION argument <min> value or use a ...<max> suffix to tell
      CMake that the project does not need compatibility with older versions.
    
    
    -- Configuring done
    CMake Warning (dev) at /home/ted/projects/ncs/zephyr/cmake/linker/ld/target.cmake:33 (add_custom_command):
      Policy CMP0116 is not set: Ninja generators transform DEPFILEs from
      add_custom_command().  Run "cmake --help-policy CMP0116" for policy
      details.  Use the cmake_policy command to set the policy and suppress this
      warning.
    Call Stack (most recent call first):
      /home/ted/projects/ncs/zephyr/CMakeLists.txt:1198 (configure_linker_script)
    This warning is for project developers.  Use -Wno-dev to suppress it.
    
    CMake Warning (dev) at /home/ted/projects/ncs/zephyr/cmake/linker/ld/target.cmake:33 (add_custom_command):
      Policy CMP0116 is not set: Ninja generators transform DEPFILEs from
      add_custom_command().  Run "cmake --help-policy CMP0116" for policy
      details.  Use the cmake_policy command to set the policy and suppress this
      warning.
    Call Stack (most recent call first):
      /home/ted/projects/ncs/zephyr/CMakeLists.txt:1253 (configure_linker_script)
    This warning is for project developers.  Use -Wno-dev to suppress it.
    
    -- Generating done
    -- Build files have been written to: /home/ted/projects/ncs/hello-world-1462/build
    [0/1] Re-running CMake...
    Including boilerplate (Zephyr base (cached)): /home/ted/projects/ncs/zephyr/cmake/app/boilerplate.cmake
    CMake Deprecation Warning at /home/ted/projects/ncs/zephyr/cmake/app/boilerplate.cmake:37 (cmake_policy):
      The OLD behavior for policy CMP0079 will be removed from a future version
      of CMake.
    
      The cmake-policies(7) manual explains that the OLD behaviors of all
      policies are deprecated and that a policy should be set to OLD only under
      specific short-term circumstances.  Projects should be ported to the NEW
      behavior and not rely on setting a policy to OLD.
    Call Stack (most recent call first):
      /home/ted/projects/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      /home/ted/projects/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:40 (include_boilerplate)
      CMakeLists.txt:5 (find_package)
    
    
    -- Application: /home/ted/projects/ncs/hello-world-1462
    -- Zephyr version: 2.6.0-rc1 (/home/ted/projects/ncs/zephyr), build: v2.6.0-rc1-ncs1
    -- Found west (found suitable version "0.12.0", minimum required is "0.7.1")
    -- Board: nrf9160dk_nrf9160, Revision: 0.7.0
    -- Cache files will be written to: /home/ted/.cache/zephyr
    -- Found dtc: /usr/bin/dtc (found suitable version "1.5.0", minimum required is "1.4.6")
    -- Found toolchain: gnuarmemb (/opt/gcc-arm-none-eabi-10.3-2021.10)
    -- Found BOARD.dts: /home/ted/projects/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160.dts
    ^Cninja: error: rebuilding 'build.ninja': interrupted by user
    

    One thing I notice is that `cmake` never seems to progress beyond the zero'th of one steps:

    Dropping partition 'nrf_modem_lib_trace' since its size is 0.
    -- Configuring done
    CMake Warning (dev) at /home/ted/projects/zephyr-based/zephyr/cmake/linker/ld/target.cmake:33 (add_custom_command):
      Policy CMP0116 is not set: Ninja generators transform DEPFILEs from
      add_custom_command().  Run "cmake --help-policy CMP0116" for policy
      details.  Use the cmake_policy command to set the policy and suppress this
      warning.
    Call Stack (most recent call first):
      /home/ted/projects/zephyr-based/zephyr/CMakeLists.txt:1198 (configure_linker_script)
    This warning is for project developers.  Use -Wno-dev to suppress it.
    
    CMake Warning (dev) at /home/ted/projects/zephyr-based/zephyr/cmake/linker/ld/target.cmake:33 (add_custom_command):
      Policy CMP0116 is not set: Ninja generators transform DEPFILEs from
      add_custom_command().  Run "cmake --help-policy CMP0116" for policy
      details.  Use the cmake_policy command to set the policy and suppress this
      warning.
    Call Stack (most recent call first):
      /home/ted/projects/zephyr-based/zephyr/CMakeLists.txt:1253 (configure_linker_script)
    This warning is for project developers.  Use -Wno-dev to suppress it.
    
    -- Generating done
    -- Build files have been written to: /home/ted/projects/zephyr-based/hello-world-1462-de-didrik/build
    -- west build: building application
    [0/1] Re-running CMake...
    

    There are these triplet statements:

    - Configuring done

     . . .

    - Generating done

    [0/1] Re-running cmake...

    I am very interested to run your modified hello_world app on our nRF9160DK development board.  More than curious to see whether we measure a similar 3uA with this application.  But can you see any clue in above build process output which explains why `cmake` keeps repeating the first build steps?

    The first hello_world sample app you sent on 2022-03-11 builds and runs.  I will review prj.conf and related diffs between the two hello_world versions you prepared and shared with me.  Perhaps I can adapt the first one with the SPM child image and other diffs.  There should be only one or a few differences between the two code samples.

    Again thank you for all your help on this extended, multi-part question and issue!

    - Ted

  • tedhavelka said:
    I am very interested to run your modified hello_world app on our nRF9160DK development board.  More than curious to see whether we measure a similar 3uA with this application.  But can you see any clue in above build process output which explains why `cmake` keeps repeating the first build steps?

    That is very weird. However, looking at the project again, I see that I made it for NCS v1.9.1, not 1.6.1 which was my intention.

    Here is another version which hopefully works better: hello_world_low_power.zip

    Note that you must build it for nrf9160dk_nrf9160ns, as it enables the modem_lib.

    But in general, the changes are only disabling SERIAL, in both the SPM and the application, and enabling the modem_lib to stop the modem from consuming power unnecessary.

    tedhavelka said:
    Again thank you for all your help on this extended, multi-part question and issue!

    No problem. I am happy to be of help.

  • Hello Didrik,

    Reporting now findings with the latest low power hello_world code you send.  The project zipped in file hello_world_low_power.zip results for me in the same erroneous, cyclic 'endless loop' cmake build behavior which I described first time a couple of days ago.  I have unzipped and attempted to build this project four times, in two different ways, on two different Ubuntu 20.04 based work stations.

    My first try was to unzip hello_world_low_power in an extent ncs v1.6.1 workspace.  I've often called this my 'west workspace'.  The yaml file which directs `west` how to populate this workspace is:

    manifest:
      remotes:
        - name: nrfconnect
          url-base: https://github.com/nrfconnect
      projects:
        - name: nrf
          repo-path: sdk-nrf
          remote: nrfconnect
          revision: v1.6.1
          import: true 
      self:
        # This repository should be cloned to 
        path: aws-iot-stand-alone
    

    The projects you zipped and have shared with me do not have any manifest file, so I assumed they would build against ncs v1.6.1.  I find no reference in these modified hello_world projects to any particular ncs version.  You mention however that 1462.hello_world.zip unintentionally was or is built against ncs version 1.9.1.  I think that's today's latest stable ncs.  v1.9.1 is definitely a newer release than the nrf-connect SDK code I am presently using.

    The second way I attempt my builds is to create a fresh ncs folder, add my west.yml file there, and run `west init -l hello_world_low_power` in the ncs folder, and then cd into the hello_world_low_power project folder and `west update` there.  There's no obvious reason I can see this would make a difference, but I wanted to be sure I wasn't gumming up any works by re-using my existing ncs workspace.  ( I have successfully used the same ncs workspace for multiple projects, taking care to know that each one depends on the same ncs and third party git repos. )

    The two work hosts on which I'm developing have mostly identical toolchain elements.  I am likely missing some key elements of toolchain description but here are the primary tools I use and think about in my nRF9160 Zephyr application based work:

    Excerpt 1 - host 2 toolchain, Nordic Semi + Zephyr + arm-none-eabi-gcc:

    ted@dev-host-2:~/projects/zephyr-based$ west --version
    West version: v0.12.0
    
    ted@dev-host-2:~/projects/zephyr-based$ cmake --version
    cmake version 3.23.0
    
    CMake suite maintained and supported by Kitware (kitware.com/cmake).
    ted@dev-host-2:~/projects/zephyr-based$ dtc --version
    Version: DTC 1.5.0
    
    ted@dev-host-2:/opt/gcc-arm-none-eabi-10.3-2021.10/bin$ ./arm-none-eabi-gcc --version
    arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10.3-2021.10) 10.3.1 20210824 (release)
    Copyright (C) 2020 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    Excerpt 2 - host 1 toolchain, Nordic Semi ncs 1.6.1 + Zephyr + crosstool-NG compiler:

    Ubuntu 20.04 LTS - Dell tower FG
    
    ted@localhost:~/projects/zephyr-based/z4-sandbox-kionix-work$ west --version
    West version: v0.11.0
    
    ted@localhost:~/projects/zephyr-based/z4-sandbox-kionix-work$ cmake --version
    cmake version 3.21.1
    
    CMake suite maintained and supported by Kitware (kitware.com/cmake).
    
    ted@localhost:~/projects/zephyr-based/z4-sandbox-kionix-work$ dtc --version
    Version: DTC 1.5.0
    
    ted@localhost:/opt/zephyr-sdk-0.13.0/arm-zephyr-eabi/bin$ ./arm-zephyr-eabi-gcc --version
    arm-zephyr-eabi-gcc (crosstool-NG 1.24.0.378_e011758) 10.3.0
    Copyright (C) 2020 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    The first hello_world.zip project, which lacked the setting of symbol `CONFIG_NRF_MODEM_LIB=y` prj.conf, and also did not include a child_image subdirectory builds and runs on both hosts.  I can build this sample app simply unzipping it within my existing ncs west workspace.  The two later low power hello_world apps fail to build, but without producing any cmake or other error messages. To recap the build time failure is that cmake or a subordinate tool in the build process keeps cycling back to the start of project processing.

    Do you have any suggestion where further I can look in cmake's output to determine what's misguiding the build process?  This 'cmake endless loop' error so far is specific to the two latest modified projects you share in this Devzone thread.  The error travels with the projects from one host to a second, with a similar but not identical build environment.  This leads me to believe there is some edge case error somewhere in the project.  I will however keep in mind that I may have set up my tools with an edge case fault on each of my favored workstations.

    What I can and will do at this point is return to the working hello_word app, and manually add the prj.conf NRF_MODEM_LIB symbol, try building, and then manually add the child_image folder and Kconfig modifier file for Secure Partition Manager project there.  Those are the two key changes I see you make in the second hello_world and later.

    Kindly inform me and our audience if there are additional toolchain details I should include, to decipher from where this endless loop build arises.

    Thanks again Didrik, and stay safe . . .

    - Ted

  • Hi again Didrik,

    As I attempt to amend the first hello_world project you posted in this thread, I find that adding to prj.conf the symbol setting `CONFIG_NRF_MODEM_LIB=y` causes for me the build error:

    Excerpt - cmake build time snippet:

    $ west build -b nrf9160dk_nrf9160ns
    [0/14] Performing build step for 'spm_subimage'
    ninja: no work to do. 
    [2/12] Building C object modules/nrf/lib/nrf_modem_lib/CMakeFiles/..__nrf__lib__nrf_modem_lib.dir/nrf91_sockets.c.obj
    FAILED: modules/nrf/lib/nrf_modem_lib/CMakeFiles/..__nrf__lib__nrf_modem_lib.dir/nrf91_sockets.c.obj 
    ccache /opt/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gcc -DBUILD_VERSION=v2.6.0-rc1-ncs1 -DEXT_API_MAGIC=0x281ee6de,0xb845acea,23298 -DFIRMWARE_INFO_MAGIC=0x281ee6de,0x8fcebb4c,23298 -DKERNEL -DNRF9160_XXAA -DNRF_TRUSTZONE_NONSECURE -DUSE_PARTITION_MANAGER=1 -D_FORTIFY_SOURCE=2 -D__PROGRAM_START -D__ZEPHYR__=1 -I/home/ted/projects/zephyr-based/zephyr/include -I/home/ted/projects/zephyr-based/hello-world-0311/build/zephyr/include/generated -I/home/ted/projects/zephyr-based/zephyr/soc/arm/nordic_nrf/nrf91 -I/home/ted/projects/zephyr-based/nrf/include -I/home/ted/projects/zephyr-based/modules/hal/cmsis/CMSIS/Core/Include -I/home/ted/projects/zephyr-based/modules/hal/nordic/nrfx -I/home/ted/projects/zephyr-based/modules/hal/nordic/nrfx/drivers/include -I/home/ted/projects/zephyr-based/modules/hal/nordic/nrfx/mdk -I/home/ted/projects/zephyr-based/zephyr/modules/hal_nordic/nrfx/. -I/home/ted/projects/zephyr-based/modules/debug/segger/SEGGER -I/home/ted/projects/zephyr-based/modules/debug/segger/Config -I/home/ted/projects/zephyr-based/zephyr/modules/segger/. -I/home/ted/projects/zephyr-based/nrfxlib/nrf_modem/include -isystem /home/ted/projects/zephyr-based/zephyr/lib/libc/minimal/include -isystem /opt/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/include -isystem /opt/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/include-fixed -Os -imacros /home/ted/projects/zephyr-based/hello-world-0311/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -fdiagnostics-color=always -mcpu=cortex-m33 -mthumb -mabi=aapcs -imacros /home/ted/projects/zephyr-based/zephyr/include/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-address-of-packed-member -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-strict-overflow -fno-reorder-functions -fno-defer-pop -fmacro-prefix-map=/home/ted/projects/zephyr-based/hello-world-0311=CMAKE_SOURCE_DIR -fmacro-prefix-map=/home/ted/projects/zephyr-based/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/home/ted/projects/zephyr-based=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc -MD -MT modules/nrf/lib/nrf_modem_lib/CMakeFiles/..__nrf__lib__nrf_modem_lib.dir/nrf91_sockets.c.obj -MF modules/nrf/lib/nrf_modem_lib/CMakeFiles/..__nrf__lib__nrf_modem_lib.dir/nrf91_sockets.c.obj.d -o modules/nrf/lib/nrf_modem_lib/CMakeFiles/..__nrf__lib__nrf_modem_lib.dir/nrf91_sockets.c.obj -c /home/ted/projects/zephyr-based/nrf/lib/nrf_modem_lib/nrf91_sockets.c
    /home/ted/projects/zephyr-based/nrf/lib/nrf_modem_lib/nrf91_sockets.c:21:10: fatal error: sockets_internal.h: No such file or directory
       21 | #include <sockets_internal.h>
          |          ^~~~~~~~~~~~~~~~~~~~
    compilation terminated.
    ninja: build stopped: subcommand failed.

    When I change working directory from hello_world up to ../zephyr and search for this header file, I find it located in `subsys/net/lib/sockets`.  So from my ncs top level dir the path and file are `ncs/zephyr/subsys/net/lib/sockets/sockets_internal.h`.

    I have attempted to add this path to hello_world's build with a stanza in CMakeLists.txt, a line of the form:

    include_directories($ENV{ZEPHYR_BASE}/subsys/net/lib/sockets)

    As well I have tried some related paths with fewer path elements.  None of these has solved the missing header file error, nor had any visible impact on the -I options reported during build, and visible as part of line 4 in the build snippet above.

    Question 1 - have you a west.yaml file for your latest hello_world_low_power project, which you can share?

    Question 2 - are there one or more other Kconfig symbols, e.g. CONFIG_NETWORKING which I may need to enable?

    My effort here is to build the hello_world sample app, with nRF Modem lib enabled but not explicitly called by the sample, so that I can confirm our nRF9160DK kit can draw as little as 3 microamps.  I'm presently copying my own west.yml file.  This manifest file works for ncs v1.6.1 sample apps and a couple ncs based projects of my own.  I am however unsure if my west.yml sets up the same libraries as you have when you build and run your hello_world app versions.

    Attempting to build and prove your project draws 3uA, so I may adopt its key configurations to my team's work and achieve the same result there.  Will continue researches here to overcome these build time errors.

    - Ted

  • Hi again Didrik,

    Working with the first hello_world sample app you sent, I am now able to build and flash that example with `CONFIG_NRF_MODEM_LIB=y` added to this app's prj.conf file.  There were a few build time errors to resolve.  These were all resolvable with a few additions to prj.conf:

    Code excerpt - amended prj.conf file to build first version low power hello_world app:

    CONFIG_USE_SEGGER_RTT=y
    
    CONFIG_LOG=y
    CONFIG_LOG_BACKEND_RTT=y
    CONFIG_LOG_BACKEND_UART=n
    
    CONFIG_RTT_CONSOLE=y
    CONFIG_UART_CONSOLE=n
    
    CONFIG_SERIAL=n
    
    # 2022-03-30 WED - Ted adding config from latest, third hello_world zip de Didrik:
    CONFIG_NRF_MODEM_LIB=y
    
    # Network - need following networking facilities for cmake to find 'sockets_internal.h':
    CONFIG_NETWORKING=y
    CONFIG_NET_SOCKETS=y
    
    # Modem library - may or may not need modem lib sys init, but present in aws_iot sample app:
    ##CONFIG_NRF_MODEM_LIB=y
    CONFIG_NRF_MODEM_LIB_SYS_INIT=n
    
    # 2022-03-30 need following kernel features to make k_malloc() defined to 'ncs/nrf/lib/nrf_modem_lib/nrf91_sockets.c':
    CONFIG_KERNEL_MEM_POOL=y
    CONFIG_HEAP_MEM_POOL_SIZE=2048
    

    I am reviewing proper Power Profiler Kit connections now, preparing to measure current draw.  Also I note here that I have not yet added the child_image/spm.conf to this earliest shared hello_world app.

    Also noting that no amendments were needed in CMakeLists.txt.  Expressing the three or so Kconfig symbols in prj.conf is sufficient to inform cmake where to locate certain header files and kernel level functions.

    Will update you on current use findings when I have them - Ted

Related