@@ -274,9 +274,27 @@ static void can_shell_print_extended_modes(const struct shell *sh, can_mode_t ca
274274 }
275275}
276276
277+ static const struct device * get_can_controller (char * id )
278+ {
279+ const struct device * dev = device_get_binding (id );
280+
281+ if (dev != NULL ) {
282+ return dev ;
283+ }
284+
285+ #ifdef CONFIG_DEVICE_DT_METADATA
286+ dev = device_get_by_dt_nodelabel (id );
287+ if (dev != NULL ) {
288+ return dev ;
289+ }
290+ #endif /* CONFIG_DEVICE_DT_METADATA */
291+
292+ return NULL ;
293+ }
294+
277295static int cmd_can_start (const struct shell * sh , size_t argc , char * * argv )
278296{
279- const struct device * dev = device_get_binding (argv [1 ]);
297+ const struct device * dev = get_can_controller (argv [1 ]);
280298 int err ;
281299
282300 if (!device_is_ready (dev )) {
@@ -297,7 +315,7 @@ static int cmd_can_start(const struct shell *sh, size_t argc, char **argv)
297315
298316static int cmd_can_stop (const struct shell * sh , size_t argc , char * * argv )
299317{
300- const struct device * dev = device_get_binding (argv [1 ]);
318+ const struct device * dev = get_can_controller (argv [1 ]);
301319 int err ;
302320
303321 if (!device_is_ready (dev )) {
@@ -318,7 +336,7 @@ static int cmd_can_stop(const struct shell *sh, size_t argc, char **argv)
318336
319337static int cmd_can_show (const struct shell * sh , size_t argc , char * * argv )
320338{
321- const struct device * dev = device_get_binding (argv [1 ]);
339+ const struct device * dev = get_can_controller (argv [1 ]);
322340 const struct device * phy ;
323341 const struct can_timing * timing_min ;
324342 const struct can_timing * timing_max ;
@@ -429,7 +447,7 @@ static int cmd_can_show(const struct shell *sh, size_t argc, char **argv)
429447
430448static int cmd_can_bitrate_set (const struct shell * sh , size_t argc , char * * argv )
431449{
432- const struct device * dev = device_get_binding (argv [1 ]);
450+ const struct device * dev = get_can_controller (argv [1 ]);
433451 struct can_timing timing = { 0 };
434452 uint16_t sample_pnt ;
435453 uint32_t bitrate ;
@@ -500,7 +518,7 @@ static int cmd_can_bitrate_set(const struct shell *sh, size_t argc, char **argv)
500518
501519static int cmd_can_dbitrate_set (const struct shell * sh , size_t argc , char * * argv )
502520{
503- const struct device * dev = device_get_binding (argv [1 ]);
521+ const struct device * dev = get_can_controller (argv [1 ]);
504522 struct can_timing timing = { 0 };
505523 uint16_t sample_pnt ;
506524 uint32_t bitrate ;
@@ -609,7 +627,7 @@ static int can_shell_parse_timing(const struct shell *sh, size_t argc, char **ar
609627
610628static int cmd_can_timing_set (const struct shell * sh , size_t argc , char * * argv )
611629{
612- const struct device * dev = device_get_binding (argv [1 ]);
630+ const struct device * dev = get_can_controller (argv [1 ]);
613631 struct can_timing timing = { 0 };
614632 int err ;
615633
@@ -638,7 +656,7 @@ static int cmd_can_timing_set(const struct shell *sh, size_t argc, char **argv)
638656
639657static int cmd_can_dtiming_set (const struct shell * sh , size_t argc , char * * argv )
640658{
641- const struct device * dev = device_get_binding (argv [1 ]);
659+ const struct device * dev = get_can_controller (argv [1 ]);
642660 struct can_timing timing = { 0 };
643661 int err ;
644662
@@ -667,7 +685,7 @@ static int cmd_can_dtiming_set(const struct shell *sh, size_t argc, char **argv)
667685
668686static int cmd_can_mode_set (const struct shell * sh , size_t argc , char * * argv )
669687{
670- const struct device * dev = device_get_binding (argv [1 ]);
688+ const struct device * dev = get_can_controller (argv [1 ]);
671689 can_mode_t mode = CAN_MODE_NORMAL ;
672690 can_mode_t raw ;
673691 char * endptr ;
@@ -715,7 +733,7 @@ static int cmd_can_mode_set(const struct shell *sh, size_t argc, char **argv)
715733
716734static int cmd_can_send (const struct shell * sh , size_t argc , char * * argv )
717735{
718- const struct device * dev = device_get_binding (argv [1 ]);
736+ const struct device * dev = get_can_controller (argv [1 ]);
719737 static unsigned int frame_counter ;
720738 unsigned int frame_no ;
721739 struct can_frame frame = { 0 };
@@ -836,7 +854,7 @@ static int cmd_can_send(const struct shell *sh, size_t argc, char **argv)
836854
837855static int cmd_can_filter_add (const struct shell * sh , size_t argc , char * * argv )
838856{
839- const struct device * dev = device_get_binding (argv [1 ]);
857+ const struct device * dev = get_can_controller (argv [1 ]);
840858 struct can_filter filter ;
841859 uint32_t id_mask ;
842860 int argidx = 2 ;
@@ -936,7 +954,7 @@ static int cmd_can_filter_add(const struct shell *sh, size_t argc, char **argv)
936954
937955static int cmd_can_filter_remove (const struct shell * sh , size_t argc , char * * argv )
938956{
939- const struct device * dev = device_get_binding (argv [1 ]);
957+ const struct device * dev = get_can_controller (argv [1 ]);
940958 int filter_id ;
941959 char * endptr ;
942960
@@ -960,7 +978,7 @@ static int cmd_can_filter_remove(const struct shell *sh, size_t argc, char **arg
960978
961979static int cmd_can_recover (const struct shell * sh , size_t argc , char * * argv )
962980{
963- const struct device * dev = device_get_binding (argv [1 ]);
981+ const struct device * dev = get_can_controller (argv [1 ]);
964982 k_timeout_t timeout = K_FOREVER ;
965983 int millisec ;
966984 char * endptr ;
0 commit comments