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

Reply
  • 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

Children
Related