ROM Bootloader cause reset if usbStringPtr is set

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

ROM Bootloader cause reset if usbStringPtr is set

Jump to solution
1,326 Views
nobodyKnows
Contributor III

Hello,

I try to configure the ROM Bootloader, but if I set the usbStringsPointer than enter the ROM Bootloader will lead to a Software Reset of the MCU.

Can anyone help me with the config structure? There must be an issue.

#define USB_STRING_DESCRIPTOR 0x03

const uint8_t USB_STR_0[4] = {0x02,0x03,0x09,0x04}; /* RM 14.4.5.2 */

__attribute__((section(".usb_str"))) usb_strings_t usb_str = {
	//Länge, +utf16 string
	.vendor = { 18,USB_STRING_DESCRIPTOR,'T',0,'Y',0,'R',0,'A',0,'C',0,'O',0,'N',0,'T',0 },
	.product_description = { 12,USB_STRING_DESCRIPTOR,'V',0,'D',0,'8',0,'5',0,'0',0},
	.serial_nr = { 18,USB_STRING_DESCRIPTOR,'1',0,'2',0,'3',0,'4',0,'5',0,'6',0,'7',0,'8',0 },

	.str_size = {sizeof(USB_STR_0),18,12,18},
};



const uint8_t * const g_string_descriptors[4] =
{
        USB_STR_0,
        usb_str.vendor,
		usb_str.product_description,
		usb_str.serial_nr,
};


const Languages_desc_t g_languages =
{
        .STR0_ptr = USB_STR_0,
        .Size = sizeof(USB_STR_0),
        .Num = (uint16_t) 0x0409,
        .StringDescriptors = g_string_descriptors,
        .Sizes = usb_str.str_size,
};


__attribute__((section(".cfg_section"))) volatile const bootloader_config_t bcfg = {
		.tag = 0x6766636B, //!< Magic Number
        .crcStartAddress = 0xFFFFFFFF, //!< Disable CRC check
        .crcByteCount = 0xFFFFFFFF, //!< Disable CRC check
        .crcExpectedValue = 0xFFFFFFFF, //!< Disable CRC check
		.enabledPeripherals = ENABLE_PERIPHERAL_USB_HID,
        .i2cSlaveAddress = 0x10, //!< Use default I2C address(0x10)
        .peripheralDetectionTimeoutMs = 10000, //!< Use user-defined timeout(ms)
        .usbVid = 0x22B5, //!< Use default Vendor ID(0x15A2)
        .usbPid = 0x0850, //!< Use default Product ID(0x0073)
		.usbStringsPointer = (uint32_t)&g_languages,
        .clockFlags = 0xFE, //!< 0 bit cleared: Enable High speed mode. NOTE: Enabling high speed mode makes UART connection worse, requires pull-up on UART RX line!
		.clockDivider = 0xff, //!< Use clock divider(0)
		.mmcauPtr = 0x410,
		.FOPTConfig = {0x45FFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFF3DFE},
};

 Thanks a lot in advance and best regards

0 Kudos
1 Solution
1,145 Views
nobodyKnows
Contributor III

Hello everbody,

due to the poor documentation I decide to readout the ROM bootloader and do a bit of reverse engineering. Now I found out what is wrong with it.

1) g_languages must be filled with padding bytes that all variables are on a 32bit boundary.

2) the datatype of g_string_desc_size is uint8_t.

3) USB_STR_0 is 0x04,0x03,0x09,0x04

The USB_STR_3 with serial number does not work. I don't know why. However for my application it is not necessary to work.

 

Best regards,

Maximilian

View solution in original post

0 Kudos
8 Replies
1,146 Views
nobodyKnows
Contributor III

Hello everbody,

due to the poor documentation I decide to readout the ROM bootloader and do a bit of reverse engineering. Now I found out what is wrong with it.

1) g_languages must be filled with padding bytes that all variables are on a 32bit boundary.

2) the datatype of g_string_desc_size is uint8_t.

3) USB_STR_0 is 0x04,0x03,0x09,0x04

The USB_STR_3 with serial number does not work. I don't know why. However for my application it is not necessary to work.

 

Best regards,

Maximilian

0 Kudos
1,132 Views
bobpaddock
Senior Contributor III

Having or not having a USB serial number causes different USB behavior. With no serial number when your devices is plugged into each port on Windows it will be seen as new device that needs installed for each port.

With a serial number, even if the serial number is just "1", your devices will work on all ports with only the initial install.

Also be aware that Windows caches USB Descriptors. Which means that the device need to be uninstalled, or the descriptor's BCD version number needs to be upped by one, for any descriptor change. .bcdDevice which follows the VID/PID in the descriptor.  I find it easier to update bcdDevice.



0 Kudos
1,275 Views
bobpaddock
Senior Contributor III
".StringDescriptors = g_string_descriptors,"

Is a pointer to the address of g_string_descriptors expected here, per the (const uint_8 **) cast in the reference manual rather than the actual address of g_string_desciptors?

Also the magic number 0x0409 that they fail to explain is the USB designation for the English language.

0 Kudos
1,238 Views
nobodyKnows
Contributor III

Hello,

thanks for your reply. I tried it with a pointer to a pointer which points to g_languages. It change the reset behavior but the strings and language id specifier dont work.

Kernel Log:

[ 5755.340863] usb 1-1.4: new full-speed USB device number 57 using ehci-pci
[ 5755.452991] usb 1-1.4: language id specifier not provided by device, defaulting to English
[ 5755.454724] usb 1-1.4: New USB device found, idVendor=22b5, idProduct=0850, bcdDevice= 0.02
[ 5755.454727] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 5755.455642] hid-generic 0003:22B5:0850.0006: hiddev1,hidraw3: USB HID v1.00 Device [HID 22b5:0850] on usb-0000:00:1a.0-1.4/input0

 

Sourcecode:

#define USB_STRING_DESCRIPTOR 0x03

const uint8_t USB_STR_0[4] = {0x02,0x03,0x09,0x04}; /* RM 14.4.5.2 */

__attribute__((section(".usb_str"))) usb_strings_t usb_str = {
	//Länge, +utf16 string
	.vendor = { 18,USB_STRING_DESCRIPTOR,'T',0,'Y',0,'R',0,'A',0,'C',0,'O',0,'N',0,'T',0 },
	.product_description = { 12,USB_STRING_DESCRIPTOR,'V',0,'D',0,'8',0,'5',0,'0',0},
	.serial_nr = { 18,USB_STRING_DESCRIPTOR,'1',0,'2',0,'3',0,'4',0,'5',0,'6',0,'7',0,'8',0 },

	.str_size = {sizeof(USB_STR_0),18,12,18},
};


__attribute__ ((section(".after_vectors.reset")))
const uint8_t * const g_string_descriptors[4] =
{
        USB_STR_0,
        usb_str.vendor,
		usb_str.product_description,
		usb_str.serial_nr,
};

__attribute__ ((section(".after_vectors.reset")))
const uint8_t * const g_strPtr = (uint8_t *)&g_string_descriptors;

__attribute__ ((section(".after_vectors.reset")))
const Languages_desc_t g_languages =
{
	.STR0_ptr = USB_STR_0,
	.Size = sizeof(USB_STR_0),
	.Num = (uint16_t) 0x0409,
	.StringDescriptors = &g_strPtr,
	.Sizes = usb_str.str_size,
};

__attribute__ ((section(".after_vectors.reset")))
const uint8_t * const g_langPtr = (uint8_t *)&g_languages;


__attribute__((section(".cfg_section"))) volatile const bootloader_config_t bcfg = {
		.tag = 0x6766636B, //!< Magic Number
        .crcStartAddress = 0xFFFFFFFF, //!< Disable CRC check
        .crcByteCount = 0xFFFFFFFF, //!< Disable CRC check
        .crcExpectedValue = 0xFFFFFFFF, //!< Disable CRC check
		.enabledPeripherals = ENABLE_PERIPHERAL_USB_HID,
        .i2cSlaveAddress = 0x10, //!< Use default I2C address(0x10)
        .peripheralDetectionTimeoutMs = 10000, //!< Use user-defined timeout(ms)
        .usbVid = 0x22B5, //!< Use default Vendor ID(0x15A2)
        .usbPid = 0x0850, //!< Use default Product ID(0x0073)
		.usbStringsPointer = &g_langPtr,
        .clockFlags = 0xFE, //!< 0 bit cleared: Enable High speed mode. NOTE: Enabling high speed mode makes UART connection worse, requires pull-up on UART RX line!
		.clockDivider = 0xff, //!< Use clock divider(0)
		.mmcauPtr = 0x410,
		.FOPTConfig = {0x45FFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFF3DFE},
};

 

0 Kudos
1,229 Views
bobpaddock
Senior Contributor III

That now has both g_string_discriptors and g_language as pointer to pointers.
g_lanauge was okay as it was.  Only g_string_discriptors is the issue within the g_languge structure.

g_string_desciptors is an array of pointers pointing to an an array of structures of uint8_t's.

Anything change if it is done the way the data sheet shows, with the actual cast?:

g_languages = { USB_STR_0,
sizeof(USB_STR_0),
(uint_16)0x0409,
(const uint_8 **)g_string_descriptors,
...

0 Kudos
1,219 Views
nobodyKnows
Contributor III

It change nothing. The binary output of the compilier is the same.

0 Kudos
1,301 Views
Pavel_Hernandez
NXP TechSupport
NXP TechSupport

Hello,

What kind of target are you using?

Best regards,
Pavel

0 Kudos
1,288 Views
nobodyKnows
Contributor III

Hello Pavel,

the target mcu is a K32L2A31A.

Best regards,

Maximilian

0 Kudos