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

printk() on blinky example not working on UART0 for NS build

Hello all,

Having a smallish problem seeing printk() output on my board.  My board is an NRF9160 PCA10090 inspired board.  Long story short, I can't see printk() stuff showing up on UART0 when I build the NS version of the board.  The other non-NS version is fine.  I'm using 1.2.0.

The details.

Our board is very similar to the PCA10090.  LEDs on different GPIO, and UART0 on different pins.  I copied the ncs\v1.2.0\zephyr\samples\basic\blinky folder to my desktop and placed two files in there named nrf9160_pca10090.overlay and nrf9160_pca10090ns.overlay.  They are identical.  Here's the contents:

&uart0 {
  status = "ok";
  current-speed = <115200>;
  tx-pin = <19>;
  rx-pin = <18>;
};

&uart2 {
  status = "ok";
  current-speed = <9600>;
  tx-pin = <11>;
  rx-pin = <10>;
};

I've also modified the code to wiggle one of my LED pins, and give me a little printk() action as it does.  My main.c is modified like this:

	while (1) {
		/* Set pin to HIGH/LOW every 1 second */
		gpio_pin_write(dev, 5, cnt % 2);
		cnt++;
		k_sleep(SLEEP_TIME);
        printk("Count is: %d\n",cnt);
	}

Now if I do the following, it works:

File -> Open nRF Connect SDK Project (CMakeLists.txt is Desktop/blinky/CMakeLists.txt, Board Directory is ncs/v1.2.0/zephyr/boards/arm/nrf9160_pca10090, Board Name is nrf9160_pca10090, Build directory is the default Desktop/blinky/build_nerf9160_pca10090.  Check [X] Clean Build Directory).  Click Go.  Then click Debug->Go.  My LED blinks, and the count shows up on UART0 on pins 18/19.  All is well, so I'm pretty sure my .overlay files are ok.

But do the same thing, except for set Board Name to nrf9160_pca10090ns, and it doesn't work.  LED blinks, so I know I'm running, but no printk() on the uart.  

Anyone know why?

Thanks,

BoredBSEE

  • More info.  If I set a debut point inside printk.c / printk(), it gets called in the first version.  I can break on it, study parameters, all that.  In the NS version, it never gets called.

    Something is optimizing out the printk() calls in the NS build.  Anyone know what that might be?

    Oh, also my overlay files in the original post have some garbage in them.  Let me try to clean that up.

    &uart0 {
      status = "ok";
      current-speed = <115200>;
      tx-pin = <19>;
      rx-pin = <18>;
    };
    
    &uart2 {
      status = "ok";
      current-speed = <9600>;
      tx-pin = <11>;
      rx-pin = <10>;
    };
    
    

    That should look like this, if I did it right this time.  

    Thanks,

    BoredBSEE

  • Are you sure nothing else in your program is using the pin 19 or 18?

    I cannot think of anything else apart from the overlay file changes. Can you run some simple UART sample on your kit to see how it behaves?

  • I'm pretty sure nothing else is using those pins.  If I do the above recipe and select nerf9160_pca10090 as the board, I get output, so I know my hardware and my overlay files are ok.  It's just when I select nerf9160_pca10090ns, I don't get output.  And if you use the interactive debugger inside printk(), you can see it never gets called in the NS build.  It's as if something is optimizing out the calls to printk().  The problem seems to be a build problem.  I've seen other build systems (like Windows CE 6.0) that take all the debug calls out during a Retail build.  I'm guessing it's something along those lines, I just can't find it.

  • My collegue says that this is caused by the SPM.

    you should add the following in the CMakeLists.txt file, just below the cmake_minimum_required() line:

    if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/spm.conf")
      set(spm_CONF_FILE
        prj.conf
        ${CMAKE_CURRENT_LIST_DIR}/spm.conf
      )
    endif()
     
    if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mcuboot.conf")
      set(mcuboot_CONF_FILE
        prj.conf
        ${CMAKE_CURRENT_LIST_DIR}/mcuboot.conf
      )
    endif()
     
    if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${BOARD}.overlay")
      set(mcuboot_DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${BOARD}.overlay")
      set(spm_DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${BOARD}.overlay")
    endif(

    Can you please give it a try.

  • Thank you!  This fixed the problem perfectly.  I now have serial output on the NS build, worked like a charm.  Tell your colleague thank you as well.

    Small point - there is a missing end parenthesis on your code block.  I only mention it just in case someone else needs this.  Line 18 should be "endif ()".

    Again, many thanks.

    BoredBSEE

Related