I am working on the Firmware for an embedded USB project. The production programmer I would like to use automatically writes the Serial Number into the device flash memory at a specified memory address. The programmer stores the serial number as Hex digits in a specified number of bytes. For example, if I tell it to store the serial number 123456 at address 0x3C00 my memory looks like this:
0x3C00 - 00
0x3C01 - 01
0x3C02 - E2
0x3C03 - 40
//(123456 in Hex = 1E240)
The problem is, when my host application reads the serial number from the device it is looking for a unicode char array. So my serial number should be ...
{ '1','0',
'2','0',
'3','0',
'4','0',
'5','0',
'6','0'}
When the
So in my firmware, which I'm writing in C, is it possible to retrieve the hex serial number from flash, encode it into a unicode char array and store it in a variable in Ram?
Unicode Character “C” (U+0043)
It can represent all 1,114,112 Unicode characters. Most C code that deals with strings on a byte-by-byte basis still works, since UTF-8 is fully compatible with 7-bit ASCII.
As far as I know, the standard C's char data type is ASCII, 1 byte (8 bits). It should mean, that it can hold only ASCII characters.
Unicode is a standard encoding system that is used to represent characters from almost all languages. Every Unicode character is encoded using a unique integer code point between 0 and 0x10FFFF . A Unicode string is a sequence of zero or more code points.
It seems like you want:
wsprintf(wchar_buffer, L"%d", serial_number)
(assuming that your serial number fits in a 32-bit integer. In any case, wsprintf
will print your serial number as a wchar (unicode) string.
You should be able to use something like this:
wchar_t buf[10];
swprintf(buf, L"%d", your_int_value);
The details may be different depending on your exact implementation of the C runtime library. For example, your swprintf()
may expect the number of characters in buf
:
swprintf(buf, sizeof(buf)/sizeof(buf[0]), L"%d", your_int_value);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With