This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

lpuart with log enabled

Hello,

I am quite new to NCS. I am trying to sending UART data from nRF52dk_52832 to PC.

The example is nrf\samples\peripheral\lpuart.

If I enable the example with CONFIG_LOG=y, the program crash with Stacking error (context area might be not valid)

I think stacking error should be the error related to memory so I have tried increasing memory size with CONFIG_MAIN_STACK_SIZE, CONFIG_HEAP_MEM_POOL_SIZE and CONFIG_LOG_BUFFER_SIZE but not working.

error message:

[00:05:47.382,385] <err> os: ***** MPU FAULT *****
[00:05:47.382,415] <err> os:   Stacking error (context area might be not valid)
[00:05:47.382,415] <err> os: r0/a1:  0x000004d4  r1/a2:  0x000004d8  r2/a3:  0x000004dc
os: r3/a4:  0x000004e0 r12/ip:  0x000004e4 r14/lr:  0x000004e8
[00:05:47.382,476] <err> os:  xpsr:  0x00os: Faulting instruction address (r15/pc): 0x000004ec
[00:05:47.382,507] <err> os: >>> ZEPHYR F[00:05:47.382,537] <err> os: Current thread: 0x200001c8 (unknown)
[00:05:47.637,115] <err>

prj.conf

CONFIG_NRF_SW_LPUART=y

# Sample is showing low power capabilities of low power uart module thus
# console/logging uart is disabled.
# Uncomment this section for debugging. Additionally, comment uart0 disabling
# in overlay.
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_HEAP_MEM_POOL_SIZE=1024
CONFIG_LOG_BUFFER_SIZE=1024

CONFIG_USE_SEGGER_RTT=y
CONFIG_LOG=y
CONFIG_NO_OPTIMIZATIONS=y
CONFIG_ASSERT=y

# Comment this section for debugging
CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n

# Uncomment to use lpuart using interrupt driven API
# CONFIG_NRF_SW_LPUART_INT_DRIVEN=y

And advice is appreciated.

Parents
  • I was able to get RTT Log (seems like that is what you're trying to do) to work with the nrf52 DK nRF52832 in the following manner:

    • Modify the lpuart accordingly:

    https://github.com/nrfconnect/sdk-nrf/compare/v1.7.0...simon-iversen:lpuart_rtt_log

    Best regards,

    Simon

  • Hi, I am sorry to bother you.

    Would you mind to have a look on my project?

    I think I have modified the project exactly like you have mentioned.

    lpuart.7z

    Thank you so much!

  • The solution is to set CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=8192


    Explanation:

    • First I added CONFIG_THREAD_NAME=y to your samples prj.conf
    • Then I ran your sample, and got the following output:

    [00:00:01.865,539] <inf> app: Received data 5 bytes
    [00:00:02.269,866] <err> os: ***** MPU FAULT *****
    [00:00:02.269,866] <err> os:   Stacking error (context area might be not valid)
    [00:00:02.269,897] <err> os: r0/a1:  0xe5b87cf6  r1/a2:  0x5889934f  r2/a3:  0xfdf17dfc
    [00:00:02.269,897] <err> os: r3/a4:  0x67cba936 r12/ip:  0x7fa9b996 r14/lr:  0x004d4b6e
    [00:00:02.269,927] <err> os:  xpsr:  0x61000000
    [00:00:02.269,927] <err> os: Faulting instruction address (r15/pc): 0x000046ac
    [00:00:02.269,958] <err> os: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0
    [00:00:02.269,989] <err> os: Current thread: 0x200001d0 (logging)
    [00:00:02.667,999] <err> fatal_error: Resetting system
    

    • You can see that a stack overflow happened, this is probably due to the config CONFIG_NO_OPTIMIZATIONS=y, which I didn't have in my sample. Which will turn off optimizations, and the code will occupy more memory.
    • Since I enabled CONFIG_THREAD_NAME, I could see that the logging thread caused the issue (Current thread: 0x200001d0 (logging))
    • Next, I increased the stack size of the logging thread by adding CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=8192 to the prj.conf file and the issue disappeared

    Best regards,

    Simon

  • Wow, that not only solve my problem but also showcase how to probably debug a program.

    Thank you for your excellent explanation, Simon.

Reply Children
No Data
Related