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

Zephyr kernel crash on -O0 bug report

2021 05 18 west update new source

mkdir -p ncs

west init -m github.com/.../sdk-nrf --mr master ./ncs
cd ~/ncs
west update
west zephyr-export

//// ~/ncs/nrf/west.yml

name: zephyr
repo-path: sdk-zephyr
revision: 4d068de3f50f6a2de2be0c0b98670e33d28ff493

1. revision: 4d068de3f50f6a2de2be0c0b98670e33d28ff493   before to void main() CRASH, when set_compiler_property(PROPERTY optimization_debug -O0)

2. revision: a9423cbce69a5df78140a2cf3ba11aa56d395cfc   west update,   go to void main() good work, when set_compiler_property(PROPERTY optimization_debug -O0)


# follows are my setting
/////~/ncs/zephyr/cmake/compiler/gcc/compiler_flags.cmake

set_compiler_property(PROPERTY no_optimization -O0)
if(CMAKE_C_COMPILER_VERSION VERSION_LESS "4.8.0")
set_compiler_property(PROPERTY optimization_debug -O0)
else()
#set_compiler_property(PROPERTY optimization_debug -Og)
set_compiler_property(PROPERTY optimization_debug -O0)
endif()
set_compiler_property(PROPERTY optimization_speed -O2)
#set_compiler_property(PROPERTY optimization_size -Os)
set_compiler_property(PROPERTY optimization_size -Og)

////SES create hello_world in  non-secure mode
build_nrf9160dk_nrf9160ns

////prj.conf

CONFIG_DEBUG=y

# enable cpp
CONFIG_CPLUSPLUS=y
CONFIG_STD_CPP11=y
CONFIG_LIB_CPLUSPLUS=y

# enable libs
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
CONFIG_FPU=y

# page fault dump
CONFIG_FAULT_DUMP=1

# disable console out
###CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n
CONFIG_USE_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y
CONFIG_SEGGER_RTT_BUFFER_SIZE_DOWN=2048
CONFIG_SEGGER_RTT_BUFFER_SIZE_UP=2048

# enable device
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_I2C=y

# reboot utility
CONFIG_REBOOT=y

# Fatal error reboot
CONFIG_WATCHDOG=y

# Json utility, if u need
###CONFIG_JSON_LIBRARY=y

# flash write
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y

# enable mcuboot/boot/zephyr project
CONFIG_BOOTLOADER_MCUBOOT=y

//////////////nrf9160dk_nrf9160ns.overlay

/ {
chosen {
zephyr,console = &uart0;
zephyr,shell-uart = &uart0;
zephyr,uart-mcumgr = &uart0;
zephyr,bt-mon-uart = &uart0;
};
};

&uart0 {
current-speed = <115200>;
status = "okay";
rx-pin = <0>;
tx-pin = <1>;
/delete-property/ cts-pin;
/delete-property/ rts-pin;
};

&uart1 {
current-speed = <115200>;
status = "okay";
rx-pin = <0x15>;
tx-pin = <0x16>;
/delete-property/ cts-pin;
/delete-property/ rts-pin;
};

&uart2 {
current-speed = <115200>;
status = "okay";
rx-pin = <0x1b>;
tx-pin = <0x1c>;
/delete-property/ cts-pin;
/delete-property/ rts-pin;
};

&i2c2 {
compatible = "nordic,nrf-twim";
status = "disabled";
};

&i2c3 {
compatible = "nordic,nrf-twim";
status = "okay";
sda-pin = < 0x1e >;
scl-pin = < 0x1f >;
clock-frequency = <I2C_BITRATE_STANDARD>;

eeprom0: eeprom@54 {
compatible = "atmel,at24";
reg = <0x54>;
label = "EEPROM_0";
size = <1024>;
pagesize = <16>;
address-width = <8>;
timeout = <3>;
};

eeprom1: eeprom@56 {
compatible = "atmel,at24";
reg = <0x56>;
label = "EEPROM_1";
size = <1024>;
pagesize = <16>;
address-width = <8>;
timeout = <3>;
};
};

&spi3 {
compatible = "nordic,nrf-spim";
status = "disabled";
sck-pin = <0xFFFFFFFF>;
mosi-pin = <0xFFFFFFFF>;
miso-pin = <0xFFFFFFFF>;
};

  • in fault.c i get crash address
    arm-none-eabi-gdb trace last call function of LR-> 0x00033c87
    arm-none-eabi-gdb trace last crash address of PC-> 0x0002a93e


    0x00033c87
    Line 674 of "zephyr/include/generated/syscalls/kernel.h"
       starts at address 0x33c7c <k_mutex_lock+12> and ends at 0x33c88 <k_mutex_lock+24>.

    0x0002a93e
    Line 120 of "/root/ncs/zephyr/kernel/mutex.c" starts at address 0x2a93c <z_impl_k_mutex_lock>
       and ends at 0x2a950 <z_impl_k_mutex_lock+20>.


    follows is ok version

  • What version of ncs (nrf) are you using? Check it out by running git log from ncs/v1.5.0/nrf. 

     By these you are referring to the zephyr revision I guess?

    1. revision: 4d068de3f50f6a2de2be0c0b98670e33d28ff493   before to void main() CRASH, when set_compiler_property(PROPERTY optimization_debug -O0)

    2. revision: a9423cbce69a5df78140a2cf3ba11aa56d395cfc   west update,   go to void main() good work, when set_compiler_property(PROPERTY optimization_debug -O0)

    When using NCS you shouldn't care about the zephyr revision, instead you should check out the nrf revision/tag followed by a west update, then it will automatically get the zephyr revision compatible with that version of NCS. Please do that, and if you still see an issue, please tell me and I will look into it.

    Best regards,

    Simon

  • the version I paste in the first section already!
    2021/05/18
    west update new source
    mkdir -p ncs

    west init -m github.com/.../sdk-nrf --mr master ./ncs
    cd ~/ncs
    west update
    west zephyr-export

    name: zephyr
    repo-path: sdk-zephyr
    revision: 4d068de3f50f6a2de2be0c0b98670e33d28ff493

  • It is not recommended to modify the default files directly.

    If you would like to set optimization use these configs:

    You could also use CONFIG_COMPILER_OPT, which allows you to pass compiler optimization directly to the compiler.

    Is there a reason you want to modify the default file /ncs/zephyr/cmake/compiler/gcc/compiler_flags.cmake? If the above Kconfigs are not suficcient I will look into the original issue.

  • thanks the response
    the -O0 in kernel not in mcuboot
    it can see every variable value~~~
    Before and include revision: a9423cbce69a5df78140a2cf3ba11aa56d395cfc
    it's all good -O0 why not to use
    If Kernel and App not run pass in -O0 and -O3, can not call it stable!
    I will not use that version!

    thanks

Related