This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

strange behaviour of nrf5340 dk and zephyr sdk.

Hi I have recently started to use nrf5340dk for a 'pet' project. I have developed some code for both app and net. 

Then I started to note have some trouble on the serial output from the net code. 

So I have started to expand my studies on both the zephyr os and the development kit. I have noted that my serial communication from net core are now blocked. But this can be a problem from both linux or cable or my mistake. 

So I have returned to the the samples. I have written a simple script to make tests: https://github.com/gvieri/myzephyrstuff/blob/main/compile-and-load-zephyr.sh

When I run it I get a problem on the net core. West is able to flash the hex file, but nrfjprog return me an error.

-----------------------------------------------------------------------

~/compile-and-load-zephyr.sh samples/bluetooth/scan_adv/
This utility will try to compile for nrf5340 net core. If you need another target please modify the value of BOARD accordingly.
If you need to make a test remember to disable one of loading method. You must choose between nrfjprog --program OR west flash
-- west build: generating a build system
Including boilerplate (Zephyr base): /home/user1/zephyrproject/zephyr/cmake/app/boilerplate.cmake
-- Application: /home/user1/zephyrproject/zephyr/samples/bluetooth/scan_adv
-- Zephyr version: 2.5.99 (/home/user1/zephyrproject/zephyr)
-- Found Python3: /home/user1/anaconda3/bin/python3.6 (found suitable exact version "3.6.10") found components: Interpreter
-- Found west (found suitable version "0.10.1", minimum required is "0.7.1")
-- BUILD_VERSION=zephyr-v2.5.0-3633-geaa2dba1a232
-- Board: nrf5340dk_nrf5340_cpunet
-- Cache files will be written to: /home/user1/.cache/zephyr
-- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK
-- Using toolchain: zephyr 0.12.4 (/home/user1/zephyr-sdks/zephyr-sdk-x86-0.12.4)
-- Found dtc: /home/user1/zephyr-sdks/zephyr-sdk-x86-0.12.4/sysroots/x86_64-pokysdk-linux/usr/bin/dtc (found suitable version "1.5.0", minimum required is "1.4.6")
-- Found BOARD.dts: /home/user1/zephyrproject/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpunet.dts
-- Generated zephyr.dts: /home/user1/build/zephyr/zephyr.dts
-- Generated devicetree_unfixed.h: /home/user1/build/zephyr/include/generated/devicetree_unfixed.h
-- Generated device_extern.h: /home/user1/build/zephyr/include/generated/device_extern.h
Parsing /home/user1/zephyrproject/zephyr/Kconfig
Loaded configuration '/home/user1/zephyrproject/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpunet_defconfig'
Merged configuration '/home/user1/zephyrproject/zephyr/samples/bluetooth/scan_adv/prj.conf'
Configuration saved to '/home/user1/build/zephyr/.config'
Kconfig header saved to '/home/user1/build/zephyr/include/generated/autoconf.h'
-- The C compiler identification is GNU 10.2.0
-- The CXX compiler identification is GNU 10.2.0
-- The ASM compiler identification is GNU
-- Found assembler: /home/user1/zephyr-sdks/zephyr-sdk-x86-0.12.4/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user1/build
-- west build: building application
[188/195] Linking C executable zephyr/zephyr_prebuilt.elf

[195/195] Linking C executable zephyr/zephyr.elf
Memory region Used Size Region Size %age Used
FLASH: 75868 B 256 KB 28.94%
SRAM: 17757 B 64 KB 27.10%
SRAM1: 0 GB 64 KB 0.00%
IDT_LIST: 0 GB 2 KB 0.00%
---------------------------------------------
-- west flash: rebuilding
ninja: no work to do.
-- west flash: using runner nrfjprog
Using board 960130128
-- runners.nrfjprog: Flashing file: /home/user1/build/zephyr/zephyr.hex
Parsing image file.
Erasing page at address 0x1000000.
Erasing page at address 0x1000800.
Erasing page at address 0x1001000.
Erasing page at address 0x1001800.
Erasing page at address 0x1002000.
Erasing page at address 0x1002800.
Erasing page at address 0x1003000.
Erasing page at address 0x1003800.
Erasing page at address 0x1004000.
Erasing page at address 0x1004800.
Erasing page at address 0x1005000.
Erasing page at address 0x1005800.
Erasing page at address 0x1006000.
Erasing page at address 0x1006800.
Erasing page at address 0x1007000.
Erasing page at address 0x1007800.
Erasing page at address 0x1008000.
Erasing page at address 0x1008800.
Erasing page at address 0x1009000.
Erasing page at address 0x1009800.
Erasing page at address 0x100A000.
Erasing page at address 0x100A800.
Erasing page at address 0x100B000.
Erasing page at address 0x100B800.
Erasing page at address 0x100C000.
Erasing page at address 0x100C800.
Erasing page at address 0x100D000.
Erasing page at address 0x100D800.
Erasing page at address 0x100E000.
Erasing page at address 0x100E800.
Erasing page at address 0x100F000.
Erasing page at address 0x100F800.
Erasing page at address 0x1010000.
Erasing page at address 0x1010800.
Erasing page at address 0x1011000.
Erasing page at address 0x1011800.
Erasing page at address 0x1012000.
Erasing page at address 0x1012800.
Applying system reset.
Checking that the area to write is not protected.
Programming device.
Applying pin reset.
-- runners.nrfjprog: Board with serial number 960130128 flashed successfully.
---------------------------------------------
nrfjprog --recover
Recovering device. This operation might take 30s.
Writing image to disable ap protect.
Erasing user code and UICR flash areas.
nrfjprog --program /home/user1/build/zephyr/zephyr.hex
Parsing image file.
ERROR: The file specified is not a valid hex file, has data outside valid areas
ERROR: or does not have data in valid areas.
---------------------------------------------
nrfjprog version: 10.12.2
JLinkARM.dll version: 6.88a
---------------------------------------------
nrfjprog -i:
960130128
nrfjprog --deviceversion:
NRF5340_xxAA_ENGD
---------------------------------------------
Linux 5.4.0-74-generic x86_64 GNU/Linux

----------------------------------------------------------------------------------

I have added the nrfjprog --recover to be sure that the board memory is not locked. 

I am unable to explain to myself why the west flash seems loading the example and the nrfjprog complains about a not valid file. However soon I will receive another nrf5340 board so I'll be able to exclude hardware problem from the list.  

P.S. if you modify the script to compile for cpuapp the problem will disappear... (some time it will complain about: " ERROR: The area to write is not erased.")  

  • Hi,

    nrfjprog will default to the application core unless you explicitly target the network core with the argument:

    --coprocessor CP_NETWORK

    You also need to add a sectorerase when you program the core, and I recommend that you follow-up the command with a pinreset:

    nrfjprog --program $BUILD/zephyr/zephyr.hex --sectorerase --coprocessor CP_NETWORK
    nrfjprog --pinreset

    "west flash" handles all of this.

    When you recover a core, its flash is erased and a small program is written to it to keep the debug port open. However, when you recover the network core the flash of both cores is erased, but only the network core gets the program written to it. This means that the cores will be locked after a pin reset or power cycle, unless you recover the application core afterwards:

    nrfjprog --recover --coprocessor CP_NETWORK
    nrfjprog --recover

    Hope this helps you resolve your issues, and let me know if you run into any other problems.

Related