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

Reply Children
Related