Custom command in MCUMGR

Hello,

My goal is to read out UICR address 0x10001080UL from command line / MCUMGR.

mcumgr --conntype serial --connstring COM8,baud=115200

How to acheive that?

I have tried and successfully compiled ran these mcumgr handler examples:

https://docs.zephyrproject.org/latest/services/device_mgmt/mcumgr_handlers.html

https://github.com/zephyrproject-rtos/zephyr/tree/main/tests/subsys/mgmt/mcumgr/handler_demo

But I don't see the new commands anywhere, not a new shell command, not a new run routine, please explain how to achieve this.

Parents
  • Hello,

    You can register the mcumgr shell handler by adding CONFIG_MCUMGR_GRP_SHELL=y to your project configuration file. In addition to this configuration setting, you need to include the following configurations from the overlay-shell.conf Kconfig fragment found in the SMP server sample:

    # Enable the shell MCUmgr transport.
    CONFIG_BASE64=y
    CONFIG_CRC=y
    CONFIG_SHELL=y
    CONFIG_SHELL_BACKEND_DUMMY=y
    CONFIG_MCUMGR_TRANSPORT_SHELL=y
    
    # mcumgr-cli application doesn't accepts log in the channel it uses
    CONFIG_SHELL_LOG_BACKEND=n
    

    You should then be able to register a shell command in your application. For example:

    static int cmd_uicr_read(const struct shell *shell, size_t argc, char **argv)
    {
    	ARG_UNUSED(argc);
    	ARG_UNUSED(argv);
    
    	shell_print(shell, "UICR@0x%x: 0x%x", 
    		(uint32_t) &NRF_UICR->CUSTOMER[0], NRF_UICR->CUSTOMER[0]);
    
    	return 0;
    }
    
    SHELL_CMD_REGISTER(uicr_read, NULL, "Print UICR register", cmd_uicr_read);

    Best regards,

    Vidar

  • Thanks a lot for the answer.

    The code integrates fine and flashes to my device.

    Is the uicr_read command supposed to be listed here under available commands? 

     mcumgr --conntype serial --connstring COM8 shell
    Execute shell commands remotely
    
    Usage:
      mcumgr shell [flags]
      mcumgr shell [command]
    
    Available Commands:
      exec        Execute a shell command remotely
    
    Flags:
      -h, --help   help for shell
    
    Global Flags:
      -c, --conn string         connection profile to use
          --connextra string    Additional key-value pair to append to the connstring
          --connstring string   Connection key-value pairs to use instead of using the profile's connstring
          --conntype string     Connection type to use instead of using the profile's type
      -i, --hci int             HCI index for the controller on Linux machine
      -l, --loglevel string     log level to use (default "info")
          --name string         name of target BLE device; overrides profile setting
          --ompres string       Use this CoAP resource instead of /omgr (default "/omgr")
      -t, --timeout float       timeout in seconds (partial seconds allowed) (default 10)
      -r, --tries int           total number of tries in case of timeout (default 1)
          --write-rsp           Send BLE acked write requests instead of unacked write commands

    I don't quite see how to execute the command.

  • Please try 

    mcumgr --conntype serial --connstring COM8,baud=115200 shell exec uicr_read
    . I'm not sure if you can list available commands over the mcumgr transport. You can try shell exec help to see if that works.

  • mcumgr --conntype serial --connstring COM8,baud=115200 shell exec uicr_read
    status=8

  • Please check if the CONFIG_MCUMGR_GRP_SHELL symbol got selected in your configuration file (build/zephyr/.config). The MGMT_ERR_ENOTSUP (8) error suggests that the shell handler did not get registered.

  • Though it's now working, the current consumption with the uart enabled is too high. I want to do mcumgr over USB. 

    In order to disable uart:

    &uart0 {
      status = "disabled";
    };
    It looks like
    CONFIG_MCUMGR_TRANSPORT_SHELL=y
    requires uart in the device tree:
    ncs/v2.6.1/zephyr/include/zephyr/device.h:89:41: error: '__device_dts_ord_70' undeclared
    Is it possible to keep this working over USB, but with uart disabled?
Reply
  • Though it's now working, the current consumption with the uart enabled is too high. I want to do mcumgr over USB. 

    In order to disable uart:

    &uart0 {
      status = "disabled";
    };
    It looks like
    CONFIG_MCUMGR_TRANSPORT_SHELL=y
    requires uart in the device tree:
    ncs/v2.6.1/zephyr/include/zephyr/device.h:89:41: error: '__device_dts_ord_70' undeclared
    Is it possible to keep this working over USB, but with uart disabled?
Children
  • After fiddling around with different combinations, this combination works:

    # Enable the serial mcumgr transport.
    CONFIG_MCUMGR_TRANSPORT_UART=y
    CONFIG_MCUMGR_GRP_SHELL=y
    # Enable the shell MCUmgr transport.
    CONFIG_BASE64=y
    CONFIG_SHELL=y
    CONFIG_SHELL_BACKEND_DUMMY=y
    #CONFIG_MCUMGR_TRANSPORT_SHELL=y
    CONFIG_SHELL_BACKEND_SERIAL=n

    / {
    	chosen {
    		zephyr,uart-mcumgr = &cdc_acm_uart0;
    	};
    };
    
    &zephyr_udc0 {
    	cdc_acm_uart0: cdc_acm_uart0 {
    		compatible = "zephyr,cdc-acm-uart";
    	};
    };
    
    &uart0 {
    	status = "disabled";
    };
    

Related