hello_world will not compile

I'm trying to compile hello_world from the template files on the nRF9160-DK.

My computer is running Ubuntu 22.04.02. I have updated everything via nRF Connect for Desktop v4.1.2.

I am using VSCode and used the "Build" button in the Actions box.

Here is the code:

/*
* Copyright (c) 2012-2014 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/kernel.h>

void main(void)
{

printk("Hello World! %s\n", CONFIG_BOARD);

}

Here is the message in the TERMINAL window of VSCode

Building hello_world_July_18_23
/bin/sh -c west build --build-dir /nordicsemi/myapps/hello_world_July_18_23/build /nordicsemi/myapps/hello_world_July_18_23

[0/24] Performing build step for 'tfm'
ninja: no work to do.
[2/16] Building C object CMakeFiles/app.dir/src/main.c.obj
[3/16] Linking C static library app/libapp.a
[4/16] Building C object zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_nrfx_uarte.c.obj
FAILED: zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_nrfx_uarte.c.obj
ccache /nordicsemi/toolchains/v2.3.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -DKERNEL -DMBEDTLS_CONFIG_FILE=\"nrf-config.h\" -DMBEDTLS_USER_CONFIG_FILE=\"nrf-config-user.h\" -DNRF9160_XXAA -DNRF_SKIP_FICR_NS_COPY_TO_RAM -DNRF_TRUSTZONE_NONSECURE -DUSE_PARTITION_MANAGER=1 -D_ANSI_SOURCE -D_FORTIFY_SOURCE=1 -D__LINUX_ERRNO_EXTENSIONS__ -D__PROGRAM_START -D__ZEPHYR_SUPERVISOR__ -D__ZEPHYR__=1 -I/nordicsemi/v2.3.0/zephyr/include -Izephyr/include/generated -I/nordicsemi/v2.3.0/zephyr/soc/arm/nordic_nrf/nrf91 -I/nordicsemi/v2.3.0/zephyr/lib/libc/newlib/include -I/nordicsemi/v2.3.0/zephyr/soc/arm/nordic_nrf/common/. -I/nordicsemi/v2.3.0/nrf/include -I/nordicsemi/v2.3.0/nrf/include/tfm -I/nordicsemi/v2.3.0/nrf/tests/include -Itfm/generated/interface/include -I/nordicsemi/v2.3.0/modules/hal/cmsis/CMSIS/Core/Include -I/nordicsemi/v2.3.0/modules/hal/nordic/nrfx -I/nordicsemi/v2.3.0/modules/hal/nordic/nrfx/drivers/include -I/nordicsemi/v2.3.0/modules/hal/nordic/nrfx/mdk -I/nordicsemi/v2.3.0/zephyr/modules/hal_nordic/nrfx/. -I/nordicsemi/v2.3.0/nrfxlib/nrf_modem/include -Itfm/install/interface/include -Imodules/nrfxlib/nrfxlib/nrf_security/src/include/generated -I/nordicsemi/v2.3.0/nrfxlib/nrf_security/include -I/nordicsemi/v2.3.0/nrfxlib/nrf_security/include/mbedtls -I/nordicsemi/v2.3.0/modules/crypto/mbedtls/include -I/nordicsemi/v2.3.0/modules/crypto/mbedtls/include/mbedtls -I/nordicsemi/v2.3.0/modules/crypto/mbedtls/include/psa -I/nordicsemi/v2.3.0/modules/crypto/mbedtls/library -I/nordicsemi/v2.3.0/nrfxlib/crypto/nrf_oberon/include/mbedtls -I/nordicsemi/v2.3.0/nrfxlib/crypto/nrf_oberon/include -fno-strict-aliasing -Os -imacros /nordicsemi/myapps/hello_world_July_18_23/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m33 -mthumb -mabi=aapcs -mfp16-format=ieee --sysroot=/nordicsemi/toolchains/v2.3.0/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros /nordicsemi/v2.3.0/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=/nordicsemi/myapps/hello_world_July_18_23=CMAKE_SOURCE_DIR -fmacro-prefix-map=/nordicsemi/v2.3.0/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/nordicsemi/v2.3.0=WEST_TOPDIR -ffunction-sections -fdata-sections -specs=nano.specs -std=c99 -MD -MT zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_nrfx_uarte.c.obj -MF zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_nrfx_uarte.c.obj.d -o zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_nrfx_uarte.c.obj -c /nordicsemi/v2.3.0/zephyr/drivers/serial/uart_nrfx_uarte.c
In file included from /nordicsemi/v2.3.0/zephyr/drivers/serial/uart_nrfx_uarte.c:13:
/nordicsemi/v2.3.0/modules/hal/nordic/nrfx/hal/nrf_uarte.h: In function 'nrf_uarte_event_check':
/nordicsemi/v2.3.0/modules/hal/nordic/nrfx/hal/nrf_uarte.h:489:1: error: unknown type name 'namespace'
489 | namespace n
| ^~~~~~~~~
/nordicsemi/v2.3.0/modules/hal/nordic/nrfx/hal/nrf_uarte.h:491:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
491 | {
| ^
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /nordicsemi/toolchains/v2.3.0/usr/local/bin/cmake --build /nordicsemi/myapps/hello_world_July_18_23/build

* The terminal process failed to launch (exit code: 1).
* Terminal will be reused by tasks, press any key to close it.

Parents
  • Hello,

    /nordicsemi/v2.3.0/modules/hal/nordic/nrfx/hal/nrf_uarte.h:489:1: error: unknown type name 'namespace'

    We don't use 'namespace' in the nrf_uarte.h header, so it seems like the header file may have been modified. This is what is supposed to be at line 489: https://github.com/zephyrproject-rtos/hal_nordic/blob/4ee20fd6ca25cd4bf78918f4fffee016a4ef47b9/nrfx/hal/nrf_uarte.h#L489 

    To see what's changed, you can open a terminal and change directory to /v2.3.0/modules/hal/nordic and use git:

    $ git status
    $ git diff

    Best regards,

    Vidar

  • Thank you Vidar,

    Nothing was changed in the .h files on my system. I am the only person working on the system so I would know that no one else did it either. I wonder if the source files from Nordic Semi were corrupted somehow. I will rebuild my environment from scratch and try again and let you know the results. 

    Best regards og tusen takk,

    Brian 

  • Hi Brian,

    Bare hyggelig / you're welcome. Yes, I don't see any other explanation than the header file must have been modified or corrupted somehow. If you want to save some time, it should be quicker to do a 'git reset --hard' inside the /v2.3.0/modules/hal/nordic/ directory to restore the files rather than re-installing the SDK (if that's what you meant by rebuilding your environment). 

  • Hello Vidar,

    I restored the system via rebuilding. I can compile hello-world but still cannot link, but now for a different reason that I also do not understand. Again, I am running under Ubuntu.

    Here is the source code, I added the for loop so that there would be something more in the serial terminal window.

    *
    * Copyright (c) 2012-2014 Wind River Systems, Inc.
    *
    * SPDX-License-Identifier: Apache-2.0
    */

    #include <zephyr/kernel.h>

    int main(void)
    {
       int i;
       for(i=0; i<100; i++){
         printk("Hello World_01! %s\n", CONFIG_BOARD);
       }
       return 0;
    }

    Here is the Build output in the terminal window:

    Building hello_world_01
    /bin/sh -c west build --build-dir /nordicsemi/myapps/hello_world_01/build /nordicsemi/myapps/hello_world_01

    [1/11] Building C object CMakeFiles/app.dir/src/main.c.obj
    [2/11] Linking C static library app/libapp.a
    [3/11] Linking C executable zephyr/zephyr_pre0.elf

    [4/11] Generating dev_handles.c
    [5/11] Building C object zephyr/CMakeFiles/zephyr_pre1.dir/dev_handles.c.obj
    [6/11] Linking C executable zephyr/zephyr_pre1.elf

    [7/11] Generating linker.cmd
    [8/11] Generating isr_tables.c, isrList.bin
    [9/11] Building C object zephyr/CMakeFiles/zephyr_final.dir/dev_handles.c.obj
    [10/11] Building C object zephyr/CMakeFiles/zephyr_final.dir/isr_tables.c.obj
    [11/11] Linking C executable zephyr/zephyr.elf
    Memory region Used Size Region Size %age Used
    FLASH: 22920 B 1 MB 2.19%
    RAM: 7552 B 256 KB 2.88%
    IDT_LIST: 0 GB 2 KB 0.00%
    * Terminal will be reused by tasks, press any key to close it.

    And here is the output from Flash:

    Executing task: nRF Connect: Flash: hello_world_01/build (active)

    Flashing build to 960025583
    /bin/sh -c west flash -d /nordicsemi/myapps/hello_world_01/build --skip-rebuild --dev-id 960025583

    -- west flash: using runner nrfjprog
    -- runners.nrfjprog: Flashing file: /nordicsemi/myapps/hello_world_01/build/zephyr/zephyr.hex
    [error] [ Client] - Encountered error -5: Command read_device_info executed for 1 milliseconds with result -5
    [error] [ Worker] - Encountered unexpected debug port ID 6, expected 2
    [error] [ Client] - Encountered error -5: Command read_memory_descriptors executed for 127 milliseconds with result -5
    Failed to read device memories.
    [error] [ nRF52] - Device memory generation failed.
    [error] [ Worker] - Detected CPU core "235012351" does match expected CPU core "234881279"
    ERROR: The --family option given with the command (or the default from
    ERROR: nrfjprog.ini) does not match the device connected.
    NOTE: For additional output, try running again with logging enabled (--log).
    NOTE: Any generated log error messages will be displayed.
    FATAL ERROR: command exited with status 18: nrfjprog --program /nordicsemi/myapps/hello_world_01/build/zephyr/zephyr.hex --sectoranduicrerase --verify -f NRF52 --snr 960025583

    * The terminal process terminated with exit code: 18.
    * Terminal will be reused by tasks, press any key to close it.

    Here is some additional important information:

    I get the same flash error message when I try to flash hello_world under Windows 11 and I get the same flash error message when I try to flash after change the board from the nRF9160-DK to a Thingy:91 linked via a Segger JLink. 

  • Hello,

    I am glad to hear that you were able to resolve the build error. The nrfjprog error indicates that you are trying to program a nRF52 project to a nRF9160 target. Did you build the hello world sample for 'nrf9160dk_nrf52840' instead of nrf9160dk_nrf9160' maybe? 

    Please make sure the switch on your 9160 DK is set to the correct position.

  • Thank you Vidar,

    The switch position was correct but I had not been careful when I built the .config file and the nRF52... was selected rather than the nRF9160. In the US we call that a "rookie mistake" or simply not paying adequate attention to the software parameters.

    OK, I am up and running. Thank you again.

    Brian

Reply Children
No Data
Related