CONFIG_MCUMGR_TRANSPORT_UART and Thread_create

Hi, 

I'm trying to use same UART channel on both project-specific purpose and MCUmgr DFU. However, when I enable the option  CONFIG_MCUMGR_TRANSPORT_UART, the code reset's at specific thread initialization. This thread handles the project-specific uart handling. Here are the some keypoints about the issue:

- Without CONFIG_MCUMGR_TRANSPORT_UART, all threads being created successfully

- There is another thread creation right before the Uart Thread, which is being created with no problem. 

- When the problem occurs, there is no visible error logs, system just reboots. 

Here are the logs: 

*** Booting nRF Connect SDK v3.1.0-6c6e5b32496e ***
*** Using Zephyr OS v4.1.99-1612683d4010 ***
[00:00:00.002,008] <inf> app: RMIRA MAIN DEVICE with NRF54L - MAIN APP STARTED
[00:00:00.002,195] <inf> app: peripheral_init return: 0, crypto_init return: 0
Thread analyze:
 Peripheral          : STACK: unused 1816 usage 232 / 2048 (11 %); CPU: 0 %
                     : Total CPU cycles used: 24
 thread_analyzer     : STACK: unused 560 usage 464 / 1024 (45 %); CPU: 1 %
                     : Total CPU cycles used: 235
 mcumgr smp          : STACK: unused 1752 usage 296 / 2048 (14 %); CPU: 0 %
                     : Total CPU cycles used: 22
 BT LW WQ            : STACK: unused 1808 usage 296 / 2104 (14 %); CPU: 0 %
                     : Total CPU cycles used: 20
 BT GATT DM WQ       : STACK: unused 1008 usage 296 / 1304 (22 %); CPU: 0 %
                     : Total CPU cycles used: 20
 sysworkq            : STACK: unused 1752 usage 296 / 2048 (14 %); CPU: 0 %
                     : Total CPU cycles used: 15
 MPSL Work           : STACK: unused 728 usage 296 / 1024 (28 %); CPU: 0 %
                     : Total CPU cycles used: 17
 logging             : STACK: unused 7592 usage 600 / 8192 (7 %); CPU: 86 %
                     : Total CPU cycles used: 20023
 idle                : STACK: unused 272 usage 48 / 320 (15 %); CPU: 0 %
                     : Total CPU cycles used: 0
 main                : STACK: unused 7856 usage 336 / 8192 (4 %); CPU: 6 %
                     : Total CPU cycles used: 1558
 ISR0                : STACK: unused 1624 usage 424 / 2048 (20 %)
*** Booting nRF Connect SDK v3.1.0-6c6e5b32496e ***
*** Using Zephyr OS v4.1.99-1612683d4010 ***
[00:00:00.002,008] <inf> app: RMIRA MAIN DEVICE with NRF54L - MAIN APP STARTED
[00:00:00.002,195] <inf> app: peripheral_init return: 0, crypto_init return: 0
Thread analyze:
 Peripheral          : STACK: unused 1816 usage 232 / 2048 (11 %); CPU: 0 %
                     : Total CPU cycles used: 25
 thread_analyzer     : STACK: unused 560 usage 464 / 1024 (45 %); CPU: 1 %
                     : Total CPU cycles used: 235
 mcumgr smp          : STACK: unused 1752 usage 296 / 2048 (14 %); CPU: 0 %
                     : Total CPU cycles used: 22
 BT LW WQ            : STACK: unused 1808 usage 296 / 2104 (14 %); CPU: 0 %
                     : Total CPU cycles used: 20
 BT GATT DM WQ       : STACK: unused 1008 usage 296 / 1304 (22 %); CPU: 0 %
                     : Total CPU cycles used: 19
 sysworkq            : STACK: unused 1752 usage 296 / 2048 (14 %); CPU: 0 %
                     : Total CPU cycles used: 15
 MPSL Work           : STACK: unused 728 usage 296 / 1024 (28 %); CPU: 0 %
                     : Total CPU cycles used: 17
 logging             : STACK: unused 7592 usage 600 / 8192 (7 %); CPU: 86 %
                     : Total CPU cycles used: 20021
 idle                : STACK: unused 272 usage 48 / 320 (15 %); CPU: 0 %
                     : Total CPU cycles used: 0
 main                : STACK: unused 7856 usage 336 / 8192 (4 %); CPU: 6 %
                     : Total CPU cycles used: 1560
 ISR0                : STACK: unused 1624 usage 424 / 2048 (20 %)
*** Booting nRF Connect SDK v3.1.0-6c6e5b32496e ***
*** Using Zephyr OS v4.1.99-1612683d4010 ***
[00:00:00.002,008] <inf> app: RMIRA MAIN DEVICE with NRF54L - MAIN APP STARTED
[00:00:00.002,196] <inf> app: peripheral_init return: 0, crypto_init return: 0
Thread analyze:
 Peripheral          : STACK: unused 1816 usage 232 / 2048 (11 %); CPU: 0 %
                     : Total CPU cycles used: 25
 thread_analyzer     : STACK: unused 560 usage 464 / 1024 (45 %); CPU: 1 %
                     : Total CPU cycles used: 235
 mcumgr smp          : STACK: unused 1752 usage 296 / 2048 (14 %); CPU: 0 %
                     : Total CPU cycles used: 22
 BT LW WQ            : STACK: unused 1808 usage 296 / 2104 (14 %); CPU: 0 %
                     : Total CPU cycles used: 20
 BT GATT DM WQ       : STACK: unused 1008 usage 296 / 1304 (22 %); CPU: 0 %
                     : Total CPU cycles used: 20
 sysworkq            : STACK: unused 1752 usage 296 / 2048 (14 %); CPU: 0 %
                     : Total CPU cycles used: 16
 MPSL Work           : STACK: unused 728 usage 296 / 1024 (28 %); CPU: 0 %
                     : Total CPU cycles used: 17
 logging             : STACK: unused 7592 usage 600 / 8192 (7 %); CPU: 86 %
                     : Total CPU cycles used: 20020
 idle                : STACK: unused 272 usage 48 / 320 (15 %); CPU: 0 %
                     : Total CPU cycles used: 0
 main                : STACK: unused 7856 usage 336 / 8192 (4 %); CPU: 6 %
                     : Total CPU cycles used: 1559
 ISR0                : STACK: unused 1624 usage 424 / 2048 (20 %)

And the thread init function which fails: 
void uart_thread_create(void *p1, void *p2, void *p3)
{

    k_tid_t tid =  k_thread_create(&uart_thread_data,
                                    Uart_Thread_Stack,
                                    UART_THREAD_STACK_SIZE,
                                    uart_thread,
                                    NULL,
                                    NULL,
                                    NULL,
                                    UART_THREAD_PRIORITY,
                                    0, 
                                    K_NO_WAIT);
    LOG_INF("Uart Thread created");
    k_thread_name_set(tid, "uart");

    uart_msgq.command = UART_INIT;
    k_msgq_put(&uart_thread_msgq, &uart_msgq, K_NO_WAIT);
}
Parents
  • I've noticed that thread creation is not the cause of the problem. After the thread creation, uart00 is initialized and callback function is defined which is the exact point of crash. 

    static int uart0_init(void)
    {
        if (!device_is_ready(uart_dev)) 
        {
            LOG_ERR("UART0 device not ready\n");
            return APP_ERROR;
        }
    
    	int err = uart_callback_set(uart_dev, uart_cbx, NULL);
        if (err)
        {
            LOG_ERR("uart_callback_set fail\n");
            return APP_ERROR;
        }
        LOG_INF("uart0_init successful. err: %d", err);
    
        return 0;
    }

    So how does MCUmgr handles UART data in the background ?

  • In the file zephyr/subsys/mgmt/mcumgr/transport/src/smp_uart.c -> smp_uart_init ->uart_mcumgr_register seems to register the irq for the same uart you are trying to set a callback for. You cannot do that, either use different uart instance or disable CONFIG_MCUMGR_TRANSPORT_UART

Reply Children
  • Ok, I've tried to disable the irq register in the smp_uart_init() function to see the result, which failed again. Then I've set the MCUmgr uart to another uart instance (UART30) to make it different from the project-specific uart (UART20), which resulted in continuous restart. So, I can not use IRQ for two different uart at the same time ? 

  • Emre Bayraktar said:
    Then I've set the MCUmgr uart to another uart instance (UART30)

    How did you do that? in the overlay file? you need to make sure that zephyr,uart-mcumgr = &uart30 to make that change. Make sure UART20 stays as your app UART and isn’t also selected as zephyr,uart-mcumgr or console/shell. 

    Also restarts normally happens with asserts, errors and some debug warning. Do you get any useful log before the reset? You can enable RTT for console logs.

Related