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

CONFIG_ASSERT Cause Code to Crash

As a test of nrf9160 DK board, I am trying to read a voltage signal and report it to the nRF cloud.  My original plan is to change a bit of the Asset Tracking sample code and the add the reading of one ADC channel.   

The ADC reading code is basically copied from the Simon tutorial sample here:

https://devzone.nordicsemi.com/nordic/nrf-connect-sdk-guides/b/getting-started/posts/nrf-connect-sdk-tutorial---part-2-ncs-v1-4-0

Both the Asset Tracking code and tutorial code works fine by itself.  But combing the two code causes the system to crash.  

After a long frustration trial, I finally find the "CONFIG_ASSET=y" in the prj.conf cause the tutorial code to output this error message in the LTE Link Monitor and crash:

ASSERTION FAIL [((arch_is_in_isr() == 0) || ((timeout).ticks == (((k_timeout_t) {})).ticks))] @ WEST_TOPDIR/zephyr/kernel/sem.c:140

Any clues of how to fix this problem?   

Thanks

Parents
  • I tried to set CONFIG_ASSERT=y in the prj.conf of the ADC sample, and encountered the same issue as you.

    It seems like I made a mistake in the ADC code, by calling adc_sample inside the timer callback. Could you try the following main.c:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #include <zephyr.h>
    #include <sys/printk.h>
    #include <drivers/pwm.h>
    #if defined(CONFIG_BOARD_NRF5340DK_NRF5340_CPUAPP) || defined(CONFIG_BOARD_NRF5340DK_NRF5340_CPUAPPNS) || defined(CONFIG_BOARD_NRF9160DK_NRF9160NS) || defined(CONFIG_BOARD_NRF9160DK_NRF9160)
    /*ADC definitions and includes*/
    #include <hal/nrf_saadc.h>
    #define ADC_DEVICE_NAME DT_LABEL(DT_INST(0, nordic_nrf_saadc))
    #define ADC_RESOLUTION 10
    #define ADC_GAIN ADC_GAIN_1_6
    #define ADC_REFERENCE ADC_REF_INTERNAL
    #define ADC_ACQUISITION_TIME ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 10)
    #define ADC_1ST_CHANNEL_ID 0
    #define ADC_1ST_CHANNEL_INPUT NRF_SAADC_INPUT_AIN0
    #define PWM_DEVICE_NAME DT_PROP(DT_NODELABEL(pwm0), label)
    #define PWM_CH0_PIN DT_PROP(DT_NODELABEL(pwm0), ch0_pin)
    #else
    #error "Choose supported board or add new board for the application"
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Maybe a better approach than using a semaphore is to offload the adc reading to a work queue. The Asset Tracker uses work queues a lot, so take a look at that to get an understanding how to implement it.

    I will do some more testing and update the tutorial soon.

    Best regards,

    Simon

  • Hi Simon,

    first of all great tutorial!! Tried the original way of the tutorial with my nrf5340-dk and newest sdk1.9.1 and the only thing I had to change for the PWM blink (without ADC) was the typedef from

    s16_t to int16_t  and everything worked. Befor I got support from Marte in 

    https://devzone.nordicsemi.com/f/nordic-q-a/86370/nrf-connect-sdk-tutorial---part-2-3-2-set-it-up---light_controller-not-working-vs-code

    The original ADC sample I mad changes same like before s16_t to int16_t  and 

    defined(CONFIG_BOARD_NRF5340DK_NRF5340_CPUAPP_NS) // the _ line was missing from the board definition.
    Afterwards I got the build error
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    > Executing task: nRF Connect: Generate config nrf5340dk_nrf5340_cpuapp for c:\my_projects\light_controller_copy <
    Building light_controller_copy
    west build --build-dir c:\my_projects\light_controller_copy\build c:\my_projects\light_controller_copy --pristine --board nrf5340dk_nrf5340_cpuapp -- -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=On -DNCS_TOOLCHAIN_VERSION:STRING="NONE" -DCONFIG_DEBUG_OPTIMIZATIONS=y -DCONFIG_DEBUG_THREAD_INFO=y
    -- west build: generating a build system
    Including boilerplate (Zephyr base): C:/nordicsemi/v1.9.1/zephyr/cmake/app/boilerplate.cmake
    -- Application: C:/my_projects/light_controller_copy
    -- Zephyr version: 2.7.99 (C:/nordicsemi/v1.9.1/zephyr), build: v2.7.99-ncs1-1
    -- Found Python3: C:/nordicsemi/v1.9.1/toolchain/opt/bin/python.exe (found suitable exact version "3.8.2") found components: Interpreter
    -- Found west (found suitable version "0.12.0", minimum required is "0.7.1")
    -- Board: nrf5340dk_nrf5340_cpuapp
    -- Cache files will be written to: C:/nordicsemi/v1.9.1/zephyr/.cache
    -- Found dtc: C:/nordicsemi/v1.9.1/toolchain/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
    -- Found toolchain: gnuarmemb (c:/nordicsemi/v1.9.1/toolchain/opt)
    -- Found BOARD.dts: C:/nordicsemi/v1.9.1/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp.dts
    -- Generated zephyr.dts: C:/my_projects/light_controller_copy/build/zephyr/zephyr.dts
    -- Generated devicetree_unfixed.h: C:/my_projects/light_controller_copy/build/zephyr/include/generated/devicetree_unfixed.h
    -- Generated device_extern.h: C:/my_projects/light_controller_copy/build/zephyr/include/generated/device_extern.h
    -- Including generated dts.cmake file: C:/my_projects/light_controller_copy/build/zephyr/dts.cmake
    Parsing C:/nordicsemi/v1.9.1/zephyr/Kconfig
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    So I went to the code from you above in this post, upload succesfully done but when I put some wire to ADC pin P0.04 A0 there is no change in Terminal output.
    I will continue with your mentioned "work queue " above, anyway would I like to light the LED by some potentiometer.
    Many thanks in advance and best regards,
    Christoph
  • Hi Christoph,

    Please create a new ticket with your issue. This ticket is almost a year old, and Simon is currently out of office.

    Best regards,

    Marte

  • Hi Marte,

    thank you and best regards!

    Christoph

Reply Children
No Data