From 382638c8c61ddb73c32084887be41e173427023c Mon Sep 17 00:00:00 2001 From: "Alan C. Assis" Date: Mon, 25 Jan 2021 14:58:40 -0300 Subject: [PATCH] Add support in printf command to send 8-32 bits value --- nshlib/nsh_printf.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/nshlib/nsh_printf.c b/nshlib/nsh_printf.c index 60550b1af..af3b05582 100644 --- a/nshlib/nsh_printf.c +++ b/nshlib/nsh_printf.c @@ -63,6 +63,8 @@ int cmd_printf(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { FAR char *fmt; char ch; + uint32_t value; + int len; int i; /* parse each argument, detecting the right action to take @@ -84,7 +86,25 @@ int cmd_printf(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { case 'x': fmt++; - nsh_output(vtbl, "%c", strtol(fmt, NULL, 16)); + value = strtoul(fmt, NULL, 16); + len = strnlen(fmt, 10); + + if (len >= 7) + { + nsh_output(vtbl, "%c%c%c%c", value & 0xff, + (value & 0xff00) >> 8, + (value & 0xff0000) >> 16, + (value & 0xff000000) >> 24); + } + else if (len >= 3) + { + nsh_output(vtbl, "%c%c", value & 0xff, + (value & 0xff00) >> 8); + } + else if (len >= 1) + { + nsh_output(vtbl, "%c", value & 0xff); + } break; case 'n':