How are ascii strings encoded on the lpc1343

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How are ascii strings encoded on the lpc1343

1,375 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by traspando on Fri Sep 21 23:20:48 MST 2012
Tonight I was debugging some usb issues and in an attempt to verify some device descriptor strings were correct before uploading it to my board, I ran the linux utility "strings" on the .bin file.

I was quite surprised to find the strings were not present! They were there (I uploaded the bin to my uC and everything worked fine), just in a non-ascii encoding...

Could anyone shed some more light on this?
0 Kudos
6 Replies

1,358 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Sun Sep 23 23:40:18 MST 2012
Looks like you are compiling wide chars. Have you set a strange option on the compiler?

Post your build log, showing the compiler invocation for the file with this 'problem'
0 Kudos

1,358 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by traspando on Sun Sep 23 17:57:30 MST 2012
It's not just the USB descriptors, it's any char string (i.e. the example in my previous post)
0 Kudos

1,358 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Sun Sep 23 00:17:36 MST 2012
In USB descriptors characters are represented in 16-bit Unicode. When you define them, you usually use some 16-bit type, not plain char.
0 Kudos

1,358 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by cfb on Sat Sep 22 17:37:54 MST 2012
Unicode not ASCII?
0 Kudos

1,358 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by traspando on Sat Sep 22 14:22:22 MST 2012
I opened up one of these binaries in a hex editor and found that characters are stored as 16 bytes (vs the 8bits I expected). This will let you see them:
strings -e l <binary>

Why is it storing them this way?

I.e. :

char test[] = "Tacos!"

gets stored as T 0x00 a 0x00 c 0x00 o 0x00 s 0x00 ! 0x00
0 Kudos

1,358 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Sat Sep 22 01:06:20 MST 2012
They are encoded in ascii. More likely is that you are mis understanding what strings does.
From the strings man page:
A  string is any sequence of 4 (the default) or more printing characters ending with a newline or a  null.
0 Kudos