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

UART, custom and AT commands

Hi,

I have been trying to get UART working properly on my custom board but also on nRF9160 DK. I'm using only UART_0.

With CONFIG_USE_AT_HOST and without any uart code inside my own code, AT commands are working but if I wrote something else like "hi" to terminal, the device is giving a HARD FAULT.

hi
[0[00:01:23.622,528] [1B][1;31m<err> os: ***** HARD FAULT *****[1B][0m
[00:01:23.628,143] [1B][1;31m<err> os:   Fault escalation (see below)[1B][0m
[00:01:23.634,399] [1B][1;31m<err> os: ***** USAGE FAULT *****[1B][0m
[00:01:23.640,045] [1B][1;31m<err> os:   Stack overflow (context area not valid)[1B][0m
[00:01:23.647,216] [1B][1;31m<err> os: r0/a1:  0x2002c600  r1/a2:  0x00000001  r2/a3:  0x20027506[1B][0m
[00:01:23.655,883] [1B][1;31m<err> os: r3/a4:  0x2002c600 r12/ip:  0x000253a9 r14/lr:  0x000252f3[1B][0m
[00:01:23.664,550] [1B][1;31m<err> os:  xpsr:  0x00028e00[1B][0m
[00:01:23.669,769] [1B][1;31m<err> os: s[ 0]:  0x00000000  s[ 1]:  0x00000000  s[ 2]:  0x00000000  s[ 3]:  0x00000000[1B][0m
[00:01:23.680,175] [1B][1;31m<err> os: s[ 4]:  0x00000000  s[ 5]:  0x00000000  s[ 6]:  0x00000000  s[ 7]:  0x00000000[1B][0m
[00:01:23.690,612] [1B][1;31m<err> os: s[ 8]:  0x00000000  s[ 9]:  0x00000000  s[10]:  0x00000000  s[11]:  0x00000000[1B][0m
[00:01:23.701,019] [1B][1;31m<err> os: s[12]:  0x00000000  s[13]:  0x00000000  s[14]:  0x00000000  s[15]:  0x00000000[1B][0m
[00:01:23.711,456] [1B][1;31m<err> os: fpscr:  0x000109b1[1B][0m
[00:01:23.716,674] [1B][1;31m<err> os: Faulting instruction address (r15/pc): 0x2002c600[1B][0m
[00:01:23.724,548] [1B][1;31m<err> os: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0[1B][0m
[00:01:23.732,421] [1B][1;31m<err> os: Current thread: 0x200229b0 (unknown)[1B][0m
Running main.c error handlerError of type ERROR_SYSTEM_FAULT: 2

With uart code from https://github.com/Rallare/fw-nrfconnect-nrf/blob/nrf9160_samples/samples/nrf9160/uart/ inside my own code, I'm able to write whatever I want to terminal and it echoes that back from uart_cb(). But AT commands are NOT working, the code is understanding them as just similar text like "hi" and is echoing them back and not doing anything with the modem.

So, do you have any idea how should I make them work together? My goal is to give my own commands but also AT commands to the device with only one UART peripheral.

Regards,
Tero

Parents
  • I am not able to recreate your error, could you share your code?

    Best regards,

    Simon

  • I cleaned my code a little bit so there is not anything useless.

    Here is the prints of execution when uart_init() has been done in main.c:

    Flash region		Domain		Permissions
    00 0x00000 0x08000 	Secure		rwxl
    01 0x08000 0x10000 	Non-Secure	rwxl
    02 0x10000 0x18000 	Non-Secure	rwxl
    03 0x18000 0x20000 	Non-Secure	rwxl
    04 0x20000 0x28000 	Non-Secure	rwxl
    05 0x28000 0x30000 	Non-Secure	rwxl
    06 0x30000 0x38000 	Non-Secure	rwxl
    07 0x38000 0x40000 	Non-Secure	rwxl
    08 0x40000 0x48000 	Non-Secure	rwxl
    09 0x48000 0x50000 	Non-Secure	rwxl
    10 0x50000 0x58000 	Non-Secure	rwxl
    11 0x58000 0x60000 	Non-Secure	rwxl
    12 0x60000 0x68000 	Non-Secure	rwxl
    13 0x68000 0x70000 	Non-Secure	rwxl
    14 0x70000 0x78000 	Non-Secure	rwxl
    15 0x78000 0x80000 	Non-Secure	rwxl
    16 0x80000 0x88000 	Non-Secure	rwxl
    17 0x88000 0x90000 	Non-Secure	rwxl
    18 0x90000 0x98000 	Non-Secure	rwxl
    19 0x98000 0xa0000 	Non-Secure	rwxl
    20 0xa0000 0xa8000 	Non-Secure	rwxl
    21 0xa8000 0xb0000 	Non-Secure	rwxl
    22 0xb0000 0xb8000 	Non-Secure	rwxl
    23 0xb8000 0xc0000 	Non-Secure	rwxl
    24 0xc0000 0xc8000 	Non-Secure	rwxl
    25 0xc8000 0xd0000 	Non-Secure	rwxl
    26 0xd0000 0xd8000 	Non-Secure	rwxl
    27 0xd8000 0xe0000 	Non-Secure	rwxl
    28 0xe0000 0xe8000 	Non-Secure	rwxl
    29 0xe8000 0xf0000 	Non-Secure	rwxl
    30 0xf0000 0xf8000 	Non-Secure	rwxl
    31 0xf8000 0x100000 	Non-Secure	rwxl
    Non-secure callable region 0 placed in flash region 0 with size 32.
    
    
    SRAM region		Domain		Permissions
    00 0x00000 0x02000	Secure		rwxl
    01 0x02000 0x04000	Secure		rwxl
    02 0x04000 0x06000	Secure		rwxl
    03 0x06000 0x08000	Secure		rwxl
    04 0x08000 0x0a000	Secure		rwxl
    05 0x0a000 0x0c000	Secure		rwxl
    06 0x0c000 0x0e000	Secure		rwxl
    07 0x0e000 0x10000	Secure		rwxl
    08 0x10000 0x12000	Non-Secure	rwxl
    09 0x12000 0x14000	Non-Secure	rwxl
    10 0x14000 0x16000	Non-Secure	rwxl
    11 0x16000 0x18000	Non-Secure	rwxl
    12 0x18000 0x1a000	Non-Secure	rwxl
    13 0x1a000 0x1c000	Non-Secure	rwxl
    14 0x1c000 0x1e000	Non-Secure	rwxl
    15 0x1e000 0x20000	Non-Secure	rwxl
    16 0x20000 0x22000	Non-Secure	rwxl
    17 0x22000 0x24000	Non-Secure	rwxl
    18 0x24000 0x26000	Non-Secure	rwxl
    19 0x26000 0x28000	Non-Secure	rwxl
    20 0x28000 0x2a000	Non-Secure	rwxl
    21 0x2a000 0x2c000	Non-Secure	rwxl
    22 0x2c000 0x2e000	Non-Secure	rwxl
    23 0x2e000 0x30000	Non-Secure	rwxl
    24 0x30000 0x32000	Non-Secure	rwxl
    25 0x32000 0x34000	Non-Secure	rwxl
    26 0x34000 0x36000	Non-Secure	rwxl
    27 0x36000 0x38000	Non-Secure	rwxl
    28 0x38000 0x3a000	Non-Secure	rwxl
    29 0x3a000 0x3c000	Non-Secure	rwxl
    30 0x3c000 0x3e000	Non-Secure	rwxl
    31 0x3e000 0x40000	Non-Secure	rwxl
    
    Peripheral		Domain		Status
    00 NRF_P0               Non-Secure	OK
    01 NRF_CLOCK            Non-Secure	OK
    02 NRF_RTC1             Non-Secure	OK
    03 NRF_NVMC             Non-Secure	OK
    04 NRF_UARTE1           Non-Secure	OK
    05 NRF_UARTE2           Secure		SKIP
    06 NRF_TWIM2            Non-Secure	OK
    07 NRF_SPIM3            Non-Secure	OK
    08 NRF_TIMER0           Non-Secure	OK
    09 NRF_TIMER1           Non-Secure	OK
    10 NRF_TIMER2           Non-Secure	OK
    11 NRF_SAADC            Non-Secure	OK
    12 NRF_PWM0             Non-Secure	OK
    13 NRF_PWM1             Non-Secure	OK
    14 NRF_PWM2             Non-Secure	OK
    15 NRF_PWM3             Non-Secure	OK
    16 NRF_WDT              Secure		SKIP
    17 NRF_IPC              Non-Secure	OK
    18 NRF_VMC              Non-Secure	OK
    19 NRF_FPU              Non-Secure	OK
    20 NRF_EGU1             Non-Secure	OK
    21 NRF_EGU2             Non-Secure	OK
    22 NRF_DPPIC            Non-Secure	OK
    23 NRF_GPIOTE1          Non-Secure	OK
    24 NRF_REGULATORS       Non-Secure	OK
    
    SPM: NS image at 0xc000
    SPM: NS MSP at 0x200290a0
    SPM: NS reset vector at 0xf975
    SPM: prepare to jump to Non-Secure image.
    *** Booting Zephyr OS version 2.1.0  ***
    [00:00:00.191,253] [1B][0m<dbg> board_nonsecure.open_at_socket: AT socket opened[1B][0m
    [00:00:00.198,455] [1B][0m<dbg> board_nonsecure.deactivate_modemtrace: AT CMD: AT%XMODEMTRACE=0[1B][0m
    [00:00:00.214,019] [1B][0m<dbg> board_nonsecure.deactivate_modemtrace: AT RESP: OK
    [1B][0m
    [00:00:00.221,588] [1B][0m<dbg> board_nonsecure.check_modem_firmware: AT CMD: AT+CGMR[1B][0m
    [00:00:00.235,717] [1B][0m<dbg> board_nonsecure.check_modem_firmware: AT RESP: mfw_nrf9160_1.1.0
    OK
    [1B][0m
    [00:00:00.244,842] [1B][0m<dbg> board_nonsecure.check_modem_firmware: LATEST MODEM FW: mfw_nrf9160_1.1.0
    [1B][0m
    [00:00:00.254,241] [1B][0m<dbg> board_nonsecure.check_modem_firmware: CURRENT MODEM FW: mfw_nrf9160_1.1.0ù
    [1B][0m
    [00:00:00.263,793] [1B][0m<dbg> board_nonsecure.check_modem_firmware: You have the latest modem firmware.[1B][0m
    [00:00:00.273,162] [1B][0m<dbg> board_nonsecure.coex_configure: AT CMD: AT%XCOEX0=1,1,1574,1577[1B][0m
    [00:00:00.288,269] [1B][0m<dbg> board_nonsecure.coex_configure: AT RESP: OK
    [1B][0m
    [00:00:00.295,227] [1B][0m<dbg> board_nonsecure.coex_configure: COEX0 successfully configured[1B][0m
    UART application started! 
    Initializing LTE network.
    LTE network initialized.
    AT%XTEMP?       //sent from terminal
    AT%XTEMP?       //response to terminal
    
    AT%XTEMP?       //sent from terminal
    AT%XTEMP?       //response to terminal
    
    AT+CFUN?        //sent from terminal
    AT+CFUN?        //response to terminal
    
    hi              //sent from terminal
    hi              //response to terminal
    
    HEY             //sent from terminal
    HEY             //response to terminal

    Here is the prints of execution when uart_init() has been commented in main.c:

    Flash region		Domain		Permissions
    00 0x00000 0x08000 	Secure		rwxl
    01 0x08000 0x10000 	Non-Secure	rwxl
    02 0x10000 0x18000 	Non-Secure	rwxl
    03 0x18000 0x20000 	Non-Secure	rwxl
    04 0x20000 0x28000 	Non-Secure	rwxl
    05 0x28000 0x30000 	Non-Secure	rwxl
    06 0x30000 0x38000 	Non-Secure	rwxl
    07 0x38000 0x40000 	Non-Secure	rwxl
    08 0x40000 0x48000 	Non-Secure	rwxl
    09 0x48000 0x50000 	Non-Secure	rwxl
    10 0x50000 0x58000 	Non-Secure	rwxl
    11 0x58000 0x60000 	Non-Secure	rwxl
    12 0x60000 0x68000 	Non-Secure	rwxl
    13 0x68000 0x70000 	Non-Secure	rwxl
    14 0x70000 0x78000 	Non-Secure	rwxl
    15 0x78000 0x80000 	Non-Secure	rwxl
    16 0x80000 0x88000 	Non-Secure	rwxl
    17 0x88000 0x90000 	Non-Secure	rwxl
    18 0x90000 0x98000 	Non-Secure	rwxl
    19 0x98000 0xa0000 	Non-Secure	rwxl
    20 0xa0000 0xa8000 	Non-Secure	rwxl
    21 0xa8000 0xb0000 	Non-Secure	rwxl
    22 0xb0000 0xb8000 	Non-Secure	rwxl
    23 0xb8000 0xc0000 	Non-Secure	rwxl
    24 0xc0000 0xc8000 	Non-Secure	rwxl
    25 0xc8000 0xd0000 	Non-Secure	rwxl
    26 0xd0000 0xd8000 	Non-Secure	rwxl
    27 0xd8000 0xe0000 	Non-Secure	rwxl
    28 0xe0000 0xe8000 	Non-Secure	rwxl
    29 0xe8000 0xf0000 	Non-Secure	rwxl
    30 0xf0000 0xf8000 	Non-Secure	rwxl
    31 0xf8000 0x100000 	Non-Secure	rwxl
    Non-secure callable region 0 placed in flash region 0 with size 32.
    
    
    SRAM region		Domain		Permissions
    00 0x00000 0x02000	Secure		rwxl
    01 0x02000 0x04000	Secure		rwxl
    02 0x04000 0x06000	Secure		rwxl
    03 0x06000 0x08000	Secure		rwxl
    04 0x08000 0x0a000	Secure		rwxl
    05 0x0a000 0x0c000	Secure		rwxl
    06 0x0c000 0x0e000	Secure		rwxl
    07 0x0e000 0x10000	Secure		rwxl
    08 0x10000 0x12000	Non-Secure	rwxl
    09 0x12000 0x14000	Non-Secure	rwxl
    10 0x14000 0x16000	Non-Secure	rwxl
    11 0x16000 0x18000	Non-Secure	rwxl
    12 0x18000 0x1a000	Non-Secure	rwxl
    13 0x1a000 0x1c000	Non-Secure	rwxl
    14 0x1c000 0x1e000	Non-Secure	rwxl
    15 0x1e000 0x20000	Non-Secure	rwxl
    16 0x20000 0x22000	Non-Secure	rwxl
    17 0x22000 0x24000	Non-Secure	rwxl
    18 0x24000 0x26000	Non-Secure	rwxl
    19 0x26000 0x28000	Non-Secure	rwxl
    20 0x28000 0x2a000	Non-Secure	rwxl
    21 0x2a000 0x2c000	Non-Secure	rwxl
    22 0x2c000 0x2e000	Non-Secure	rwxl
    23 0x2e000 0x30000	Non-Secure	rwxl
    24 0x30000 0x32000	Non-Secure	rwxl
    25 0x32000 0x34000	Non-Secure	rwxl
    26 0x34000 0x36000	Non-Secure	rwxl
    27 0x36000 0x38000	Non-Secure	rwxl
    28 0x38000 0x3a000	Non-Secure	rwxl
    29 0x3a000 0x3c000	Non-Secure	rwxl
    30 0x3c000 0x3e000	Non-Secure	rwxl
    31 0x3e000 0x40000	Non-Secure	rwxl
    
    Peripheral		Domain		Status
    00 NRF_P0               Non-Secure	OK
    01 NRF_CLOCK            Non-Secure	OK
    02 NRF_RTC1             Non-Secure	OK
    03 NRF_NVMC             Non-Secure	OK
    04 NRF_UARTE1           Non-Secure	OK
    05 NRF_UARTE2           Secure		SKIP
    06 NRF_TWIM2            Non-Secure	OK
    07 NRF_SPIM3            Non-Secure	OK
    08 NRF_TIMER0           Non-Secure	OK
    09 NRF_TIMER1           Non-Secure	OK
    10 NRF_TIMER2           Non-Secure	OK
    11 NRF_SAADC            Non-Secure	OK
    12 NRF_PWM0             Non-Secure	OK
    13 NRF_PWM1             Non-Secure	OK
    14 NRF_PWM2             Non-Secure	OK
    15 NRF_PWM3             Non-Secure	OK
    16 NRF_WDT              Secure		SKIP
    17 NRF_IPC              Non-Secure	OK
    18 NRF_VMC              Non-Secure	OK
    19 NRF_FPU              Non-Secure	OK
    20 NRF_EGU1             Non-Secure	OK
    21 NRF_EGU2             Non-Secure	OK
    22 NRF_DPPIC            Non-Secure	OK
    23 NRF_GPIOTE1          Non-Secure	OK
    24 NRF_REGULATORS       Non-Secure	OK
    
    SPM: NS image at 0xc000
    SPM: NS MSP at 0x20028ca0
    SPM: NS reset vector at 0xf8f1
    SPM: prepare to jump to Non-Secure image.
    *** Booting Zephyr OS version 2.1.0  ***
    [00:00:00.191,253] [1B][0m<dbg> board_nonsecure.open_at_socket: AT socket opened[1B][0m
    [00:00:00.198,455] [1B][0m<dbg> board_nonsecure.deactivate_modemtrace: AT CMD: AT%XMODEMTRACE=0[1B][0m
    [00:00:00.214,050] [1B][0m<dbg> board_nonsecure.deactivate_modemtrace: AT RESP: OK
    [1B][0m
    [00:00:00.221,588] [1B][0m<dbg> board_nonsecure.check_modem_firmware: AT CMD: AT+CGMR[1B][0m
    [00:00:00.235,748] [1B][0m<dbg> board_nonsecure.check_modem_firmware: AT RESP: mfw_nrf9160_1.1.0
    OK
    [1B][0m
    [00:00:00.244,873] [1B][0m<dbg> board_nonsecure.check_modem_firmware: LATEST MODEM FW: mfw_nrf9160_1.1.0
    [1B][0m
    [00:00:00.254,241] [1B][0m<dbg> board_nonsecure.check_modem_firmware: CURRENT MODEM FW: mfw_nrf9160_1.1.0ø
    [1B][0m
    [00:00:00.263,793] [1B][0m<dbg> board_nonsecure.check_modem_firmware: You have the latest modem firmware.[1B][0m
    [00:00:00.273,162] [1B][0m<dbg> board_nonsecure.coex_configure: AT CMD: AT%XCOEX0=1,1,1574,1577[1B][0m
    [00:00:00.288,269] [1B][0m<dbg> board_nonsecure.coex_configure: AT RESP: OK
    [1B][0m
    [00:00:00.295,227] [1B][0m<dbg> board_nonsecure.coex_configure: COEX0 successfully configured[1B][0m
    UART application started! 
    Initializing LTE network.
    LTE network initialized.
    AT+CFUN?        //sent from terminal
    +CFUN: 0        //response to terminal
    OK              //response to terminal
    AT%XTEMP?       //sent from terminal
    %XTEMP: 23      //response to terminal
    OK              //response to terminal
    HEY             //sent from terminal
    [0[00:00:17.359,405] [1B][1;31m<err> os: ***** HARD FAULT *****[1B][0m
    [00:00:17.365,081] [1B][1;31m<err> os:   Fault escalation (see below)[1B][0m
    [00:00:17.371,337] [1B][1;31m<err> os: ***** USAGE FAULT *****[1B][0m
    [00:00:17.377,014] [1B][1;31m<err> os:   Stack overflow (context area not valid)[1B][0m
    [00:00:17.384,246] [1B][1;31m<err> os: r0/a1:  0x2002b5bc  r1/a2:  0x00000001  r2/a3:  0x20026564[1B][0m
    [00:00:17.392,944] [1B][1;31m<err> os: r3/a4:  0x2002b5bc r12/ip:  0x000213cf r14/lr:  0x00021319[1B][0m
    [00:00:17.401,672] [1B][1;31m<err> os:  xpsr:  0x00024400[1B][0m
    [00:00:17.406,921] [1B][1;31m<err> os: s[ 0]:  0x00000000  s[ 1]:  0x00000000  s[ 2]:  0x00000000  s[ 3]:  0x00000000[1B][0m
    [00:00:17.417,388] [1B][1;31m<err> os: s[ 4]:  0x00000000  s[ 5]:  0x00000000  s[ 6]:  0x00000000  s[ 7]:  0x00000000[1B][0m
    [00:00:17.427,886] [1B][1;31m<err> os: s[ 8]:  0x00000000  s[ 9]:  0x00000000  s[10]:  0x00000000  s[11]:  0x00000000[1B][0m
    [00:00:17.438,354] [1B][1;31m<err> os: s[12]:  0x00000000  s[13]:  0x00000000  s[14]:  0x00000000  s[15]:  0x00000000[1B][0m
    [00:00:17.448,852] [1B][1;31m<err> os: fpscr:  0x0000ebb1[1B][0m
    [00:00:17.454,071] [1B][1;31m<err> os: Faulting instruction address (r15/pc): 0x2002b5bc[1B][0m
    [00:00:17.462,005] [1B][1;31m<err> os: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0[1B][0m
    [00:00:17.469,909] [1B][1;31m<err> os: Current thread: 0x20021af0 (unknown)[1B][0m
    Running main.c error handlerError of type ERROR_SYSTEM_FAULT: 2

    Here is the code of the UART project:

    0576.uart.rar

    Regards,
    Tero

  • I am sorry for the delay, I have been quite busy lately. I will take a look at your code asap.

    Best regards,

    Simon

  • With CONFIG_USE_AT_HOST and without any uart code inside my own code, AT commands are working but if I wrote something else like "hi" to terminal, the device is giving a HARD FAULT.

    I am not sure what specifically causes the error, however, I know that CONFIG_USE_AT_HOST will include the library ncs\nrf\lib\at_host\at_host.c and that is built to work with AT commands. The received messages are handled by isr()-->uart_rx_handler(), before getting sent to the modem through cmd_send() (this happens in at_host.c) You have to modify the library if you want to send other kinds of messages to it.

    I'm able to write whatever I want to terminal and it echoes that back from uart_cb(). But AT commands are NOT working, the code is understanding them as just similar text like "hi" and is echoing them back and not doing anything with the modem.

    The reason this happens is because you are calling device_get_binding() two times for the same device name ("UART_0").

    If you look at the bottom of ncs\nrf\lib\at_host\at_host.c, you can see the SYS_INIT macro. This macro will run at_host_init()-->at_uart_init()-->device_get_binding() at bootup. Thus, if you include CONFIG_USE_AT_HOST in addition to calling uart_init()-->device_get_binding() in main(), the call from main will always execute last and will override the first call. That is the reason you only see the text getting echoed back (uart_cb() in main.c will execute and not isr() in at_host.c).

    I think one way of going about it is to copy and modify the at_host.c library according to your own needs. E.g. if the message starts with a specific character then you know whether it is a normal message or an AT command, and you can deal with it accordingly.

    Best regards,

    Simon

  • Hi Simon,

    I tried your Serial LTE Modem sample and modified it a little bit to compare custom commands first and then if it is an AT command then send it to a modem.

    I imported that sample into my code (which is based on Asset Tracker application) and removed CONFIG_USE_AT_HOST so now it's working.

    Now I have one problem with commanding LTE. I have modem_connect() and modem_offline() in main.c that uses the LTE Link Control. When I put those functions in main() they are working but if I try to call them from slm_at_host.c there comes an -ETIMEDOUT error.

    In slm_at_host.h I have used these lines:

    extern int modem_connect(void);
    extern int modem_offline(void);
    extern int gps_control(bool);

    But for example, GPS operation is starting and stopping properly via gps_control().

    Any idea why LTE is not working with commands from that other class?

    Regards,
    Tero

  • It seems like modem_connect() and modem_offline() are some custom functions. Could you upload your code? Then I can try to reproduce it on my side.

    Best regards,

    Simon

  • I cleaned the code a little bit so there should not be any useless stuff for this case for now.

    2626.test.rar

    Regards,
    Tero

Reply Children
Related