My task is to create a webserver on the nRF9160DK. For this i'm using the civetweb module provided by zephyr and the ethernet-shield from PHYTEC. I got an issue i want to discuss here, so i explain my thoughts here step by step, since this is my first post in this community and i'm quite new to zephyr.
In the beginning i tried to setup the civetweb webserver on the recommended target for the http_server example from vanilla zephyr, the Atmel SAM E70 Xplained. Beside for some unrelated issues i posted here, i got the webserver up and running and even successful implemented some necessary tests for my project, for example DHCP-support.
Next step was switching to the end-target, the nRF9160. I installed the nrf-connect SDK v1.5.0 and the zephyr SDK v2.4.99 according to the getting started guide. Since this board does not have any hardware-networking, i decided to integrate the PHYTEC link board eth since it is supported by the zephyr OS. For this i had to change the .overlay file of the link_board to make it suitable for the nRF9160DK.
link_board_eth.overlay @ zephyr/boards/shields/link_board_eth
&spi3 {
status = "okay";
cs-gpios = <&gpio0 10 GPIO_ACTIVE_LOW>; // D10
sck-pin = <13>;
mosi-pin = <11>;
miso-pin = <12>;
enc424j600@0 {
compatible = "microchip,enc424j600";
spi-max-frequency = <14000000>;
int-gpios = <&gpio0 9 GPIO_ACTIVE_LOW>; // D9
status = "okay";
label = "ETH_0";
reg = <0>;
};
};
Since the webserver requires more RAM than there is available in the secure-partition, i builded the project for the non-secure version of the nRF9160DK. With the following command, i was able to compile the project.
west build -b nrf9160dk_nrf9160ns %PATH_TO_PROJECT% -DSHIELD=link_board_eth
Now i'll show the output of the building process.
-- west build: generating a build system
Including boilerplate (Zephyr base): C:/local/nordic_zephyr/zephyr/cmake/app/boilerplate.cmake
-- Application: C:/local/%PATH_TO_PROJECT%
-- Zephyr version: 2.4.99 (C:/local/nordic_zephyr/zephyr)
-- Found Python3: C:/Python39/python.exe (found suitable exact version "3.9.2") found components: Interpreter
-- Found west (found suitable version "0.10.1", minimum required is "0.7.1")
-- Board: nrf9160dk_nrf9160ns, Revision: 0.7.0, Shield(s): link_board_eth
-- Cache files will be written to: C:/local/nordic_zephyr/zephyr/.cache
-- Found dtc: C:/ProgramData/chocolatey/bin/dtc.exe (found suitable version "1.5.0", minimum required is "1.4.6")
-- Found toolchain: gnuarmemb (C:/gnuarmemb)
-- Found BOARD.dts: C:/local/nordic_zephyr/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160ns.dts
-- Found devicetree overlay: C:/local/nordic_zephyr/zephyr/boards/shields/link_board_eth/link_board_eth.overlay
-- Found devicetree overlay: C:/local/nordic_zephyr/zephyr/boards/shields/link_board_eth/link_board_eth.overlay
nrf9160dk_nrf9160ns.dts.pre.tmp:366.32-370.5: Warning (simple_bus_reg): /soc/cryptocell-sw: missing or empty reg/ranges property
nrf9160dk_nrf9160ns.dts.pre.tmp:59.42-71.3: Warning (unique_unit_address_if_enabled): /soc/peripheral@40000000/flash-controller@39000: duplicate unit-address (also used in node /soc/peripheral@40000000/kmu@39000)
nrf9160dk_nrf9160ns.dts.pre.tmp:311.19-317.3: Warning (unique_unit_address_if_enabled): /soc/peripheral@40000000/clock@5000: duplicate unit-address (also used in node /soc/peripheral@40000000/power@5000)
-- Generated zephyr.dts: C:/local/nordic_zephyr/build/zephyr/zephyr.dts
-- Generated devicetree_unfixed.h: C:/local/nordic_zephyr/build/zephyr/include/generated/devicetree_unfixed.h
-- Generated device_extern.h: C:/local/nordic_zephyr/build/zephyr/include/generated/device_extern.h
Parsing C:/local/nordic_zephyr/zephyr/Kconfig
Loaded configuration 'C:/local/nordic_zephyr/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160ns_defconfig'
Merged configuration 'C:/local/nordic_zephyr/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160ns_0_7_0.conf'
Merged configuration 'C:/local/zephyrtest_2_5_0/webserverPlayground/webserver/prj.conf'
Configuration saved to 'C:/local/nordic_zephyr/build/zephyr/.config'
Kconfig header saved to 'C:/local/nordic_zephyr/build/zephyr/include/generated/autoconf.h'
-- The C compiler identification is GNU 8.3.1
-- The CXX compiler identification is GNU 8.3.1
-- The ASM compiler identification is GNU
-- Found assembler: C:/gnuarmemb/bin/arm-none-eabi-gcc.exe
Changed board to secure nrf9160dk_nrf9160 (NOT NS)
=== child image spm - begin ===
Including boilerplate (Zephyr base): C:/local/nordic_zephyr/zephyr/cmake/app/boilerplate.cmake
-- Application: C:/local/nordic_zephyr/nrf/samples/spm
-- Zephyr version: 2.4.99 (C:/local/nordic_zephyr/zephyr)
-- Found Python3: C:/Python39/python.exe (found suitable exact version "3.9.2") found components: Interpreter
-- Found west (found suitable version "0.10.1", minimum required is "0.7.1")
-- Board: nrf9160dk_nrf9160, Revision: 0.7.0
-- Cache files will be written to: C:/local/nordic_zephyr/zephyr/.cache
-- Found dtc: C:/ProgramData/chocolatey/bin/dtc.exe (found suitable version "1.5.0", minimum required is "1.4.6")
-- Found toolchain: gnuarmemb (C:/gnuarmemb)
-- Found BOARD.dts: C:/local/nordic_zephyr/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160.dts
-- Found devicetree overlay: C:/local/nordic_zephyr/nrf/samples/spm/nrf9160dk_nrf9160.overlay
nrf9160dk_nrf9160.dts.pre.tmp:59.42-71.3: Warning (unique_unit_address_if_enabled): /soc/peripheral@50000000/flash-controller@39000: duplicate unit-address (also used in node /soc/peripheral@50000000/kmu@39000)
nrf9160dk_nrf9160.dts.pre.tmp:311.19-317.3: Warning (unique_unit_address_if_enabled): /soc/peripheral@50000000/clock@5000: duplicate unit-address (also used in node /soc/peripheral@50000000/power@5000)
-- Generated zephyr.dts: C:/local/nordic_zephyr/build/spm/zephyr/zephyr.dts
-- Generated devicetree_unfixed.h: C:/local/nordic_zephyr/build/spm/zephyr/include/generated/devicetree_unfixed.h
-- Generated device_extern.h: C:/local/nordic_zephyr/build/spm/zephyr/include/generated/device_extern.h
Parsing C:/local/nordic_zephyr/zephyr/Kconfig
Loaded configuration 'C:/local/nordic_zephyr/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160_defconfig'
Merged configuration 'C:/local/nordic_zephyr/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160_0_7_0.conf'
Merged configuration 'C:/local/nordic_zephyr/nrf/samples/spm/prj.conf'
Merged configuration 'C:/local/nordic_zephyr/nrf/samples/spm/boards/nrf9160dk_nrf9160.conf'
Merged configuration 'C:/local/nordic_zephyr/nrf/subsys/partition_manager/partition_manager_enabled.conf'
Merged configuration 'C:/local/nordic_zephyr/build/spm/zephyr/misc/generated/extra_kconfig_options.conf'
Configuration saved to 'C:/local/nordic_zephyr/build/spm/zephyr/.config'
Kconfig header saved to 'C:/local/nordic_zephyr/build/spm/zephyr/include/generated/autoconf.h'
-- The C compiler identification is GNU 8.3.1
-- The CXX compiler identification is GNU 8.3.1
-- The ASM compiler identification is GNU
-- Found assembler: C:/gnuarmemb/bin/arm-none-eabi-gcc.exe
CMake Deprecation Warning at C:/local/nordic_zephyr/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
-- Generating done
-- Build files have been written to: C:/local/nordic_zephyr/build/spm
=== child image spm - end ===
CMake Deprecation Warning at C:/local/nordic_zephyr/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.
-- Target architecture - arm
CMake Warning (dev) at C:/cmake-3.19.6-win64-x64/share/cmake-3.19/Modules/GNUInstallDirs.cmake:223 (message):
Unable to determine default CMAKE_INSTALL_LIBDIR directory because no
target architecture is known. Please enable at least one language before
including GNUInstallDirs.
Call Stack (most recent call first):
C:/local/nordic_zephyr/modules/lib/civetweb/CMakeLists.txt:53 (include)
This warning is for project developers. Use -Wno-dev to suppress it.
-- Enabling tests in the build - ON
-- Thread Stack Size - 102400
-- Enabling server executable - ON
-- Serve no static files - OFF
-- Disable CGI support - OFF
-- Disable caching support - OFF
-- C++ wrappers - OFF
-- IP Version 6 - OFF
-- Websockets support - OFF
-- Server statistics support - OFF
-- Memory Debugging - OFF
-- ASAN in debug mode - ON
-- Force x32 / x64 architecture - OFF
-- Lua CGI support - OFF
-- Executable installation - ON
-- Build if there are warnings - ON
-- Duktape CGI support - OFF
-- SSL support - ON
-- Compile for OpenSSL 1.1 API - OFF
-- Dynamically load SSL libraries - ON
-- Configuring C Compiler
-- Performing Test HAVE_C_FLAG_STD_C11
-- Performing Test HAVE_C_FLAG_STD_C11 - Failed
-- Performing Test HAVE_C_FLAG_STD_C99
-- Performing Test HAVE_C_FLAG_STD_C99 - Failed
-- Performing Test HAVE_C_FLAG_STD_C89
-- Performing Test HAVE_C_FLAG_STD_C89 - Failed
-- Performing Test HAVE_C_FLAG_FSANITIZE_UNDEFINED
-- Performing Test HAVE_C_FLAG_FSANITIZE_UNDEFINED - Failed
-- Performing Test HAVE_C_FLAG_FSANITIZE_ADDRESS
-- Performing Test HAVE_C_FLAG_FSANITIZE_ADDRESS - Failed
-- Performing Test HAVE_C_FLAG_COVERAGE
-- Performing Test HAVE_C_FLAG_COVERAGE - Failed
-- Configuring done
-- Generating done
-- Build files have been written to: C:/local/nordic_zephyr/build
-- west build: building application
[10/215] Performing build step for 'spm_subimage'
[196/201] Linking C executable zephyr\zephyr_prebuilt.elf
Memory region Used Size Region Size %age Used
FLASH: 32 KB 48 KB 66.67%
SRAM: 8648 B 64 KB 13.20%
IDT_LIST: 72 B 2 KB 3.52%
[201/201] Linking C executable zephyr\zephyr.elf
[209/215] Linking C executable zephyr\zephyr_prebuilt.elf
Memory region Used Size Region Size %age Used
FLASH: 153232 B 976 KB 15.33%
SRAM: 89816 B 192 KB 45.68%
IDT_LIST: 104 B 2 KB 5.08%
[215/215] Generating zephyr/merged.hex
After the successful build, i flashed the board and got the following console output.
*** Booting Zephyr OS build v2.4.99-ncs1 *** Flash regions Domain Permissions 00 00 0x00000 0x08000 Secure rwxl 01 31 0x08000 0x100000 Non-Secure rwxl Non-secure callable region 0 placed in flash region 0 with size 32. SRAM region Domain Permissions 00 07 0x00000 0x10000 Secure rwxl 08 31 0x10000 0x40000 Non-Secure rwxl Peripheral Domain Status 00 NRF_P0 Non-Secure OK 01 NRF_CLOCK Non-Secure OK 02 NRF_RTC0 Non-Secure OK 03 NRF_RTC1 Non-Secure OK 04 NRF_NVMC Non-Secure OK 05 NRF_UARTE1 Non-Secure OK 06 NRF_UARTE2 Secure SKIP 07 NRF_TWIM2 Non-Secure OK 08 NRF_SPIM3 Non-Secure OK 09 NRF_TIMER0 Non-Secure OK 10 NRF_TIMER1 Non-Secure OK 11 NRF_TIMER2 Non-Secure OK 12 NRF_SAADC Non-Secure OK 13 NRF_PWM0 Non-Secure OK 14 NRF_PWM1 Non-Secure OK 15 NRF_PWM2 Non-Secure OK 16 NRF_PWM3 Non-Secure OK 17 NRF_WDT Non-Secure OK 18 NRF_IPC Non-Secure OK 19 NRF_VMC Non-Secure OK 20 NRF_FPU Non-Secure OK 21 NRF_EGU1 Non-Secure OK 22 NRF_EGU2 Non-Secure OK 23 NRF_DPPIC Non-Secure OK 24 NRF_REGULATORS Non-Secure OK 25 NRF_GPIOTE1 Non-Secure OK SPM: NS image at 0xc000 SPM: NS MSP at 0x2001fea8 SPM: NS reset vector at 0x10c59 SPM: prepare to jump to Non-Secure image. *** Booting Zephyr OS build v2.4.99-ncs1 *** [00:00:00.003,692] <inf> ethdrv: Link down [00:00:00.003,784] <inf> ethdrv: ENC424J600 Initialized [00:00:00.007,934] <inf> net_config: Initializing network [00:00:00.007,965] <inf> net_config: Waiting interface 1 (0x200148b8) to be up... [00:00:01.673,034] <inf> ethdrv: Link up [00:00:01.673,278] <inf> ethdrv: 100Mbps [00:00:01.673,309] <inf> ethdrv: full duplex [00:00:01.673,492] <inf> ethdrv: Not suspended [00:00:01.673,522] <inf> net_config: Interface 1 (0x200148b8) coming up [00:00:01.673,553] <inf> net_config: Running dhcpv4 client... [00:00:01.720,458] <dbg> lib_extensions.sscanf: [IMPLEMENTATION MISSING : sscanf] [00:00:06.901,611] <inf> net_dhcpv4: Received: 192.168.0.171 [00:00:06.901,733] <inf> net_config: IPv4 address: 192.168.0.171 [00:00:06.901,733] <inf> net_config: Lease time: 3600 seconds [00:00:06.901,763] <inf> net_config: Subnet: 255.255.255.0 [00:00:06.901,794] <inf> net_config: Router: 192.168.0.1
Except for the information about the flash, RAM and peripherals, the previous used Atmel-Board showed a similar output. Quite exiting i tried to access the webserver over webbrowser with the IP address, but then zephyr crashes with the following message.
[00:07:41.357,604] <err> os: ***** USAGE FAULT ***** [00:07:41.357,635] <err> os: Stack overflow (context area not valid) [00:07:41.357,635] <err> os: r0/a1: 0x20010554 r1/a2: 0x00026c74 r2/a3: 0x2001c908 [00:07:41.357,635] <err> os: r3/a4: 0x00000000 r12/ip: 0x200105c4 r14/lr: 0x00020a29 [00:07:41.357,666] <err> os: xpsr: 0x61000000 [00:07:41.357,666] <err> os: Faulting instruction address (r15/pc): 0x000209d6 [00:07:41.357,666] <err> os: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0 [00:07:41.357,666] <err> os: Current thread: 0x20014ab8 (unknown)
For completeness i'll share my prj.conf which didn't change for the successfull tests with the Atmel-Board.
# General config CONFIG_CIVETWEB=y CONFIG_JSON_LIBRARY=y # pthreads CONFIG_POSIX_API=y CONFIG_PTHREAD_IPC=y CONFIG_POSIX_MQUEUE=y # networking CONFIG_NETWORKING=y CONFIG_NET_IPV4=y CONFIG_NET_TCP=y CONFIG_NET_TCP_BACKLOG_SIZE=5 CONFIG_NET_SOCKETS=y CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=16384 CONFIG_NET_TX_STACK_SIZE=2048 CONFIG_NET_RX_STACK_SIZE=2048 CONFIG_ISR_STACK_SIZE=4096 CONFIG_MAIN_STACK_SIZE=4096 CONFIG_IDLE_STACK_SIZE=2048 CONFIG_HEAP_MEM_POOL_SIZE=8192 CONFIG_NET_CONFIG_SETTINGS=y CONFIG_NET_DHCPV4=y CONFIG_NET_MAX_CONN=5 # logging CONFIG_NET_LOG=y CONFIG_LOG_STRDUP_BUF_COUNT=16
Can anyone help me with this issue? Does anyone has experience with the ethernet-shield from PHYTEC in combination with the nRF9160DK? Any suggestions appreciated