cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMx MAJOR BUG in UsbX configuration....

matt-crc
Associate III

I'm using ThreadX on a STM32H743 MCU.  I'm trying to setup a USB Host_only on the USB_HS device, and a USB Device_only device on USB_FS.  The peripheral configuration is ok

mattcrc_0-1741644603541.pngmattcrc_1-1741644669213.png

In the AzRtos settings, it defines 2 seperate byte_pools for each device (one for the host and one for the device).  So far so good.

mattcrc_2-1741644863409.png

In the USBX configuration, everything seems to be setup properly as well.

mattcrc_3-1741645010754.png

mattcrc_4-1741645061836.png

mattcrc_5-1741645128220.png

 

mattcrc_6-1741645175424.png

mattcrc_7-1741645259747.png

mattcrc_8-1741645310730.png

mattcrc_9-1741645363899.png

Everything seems to be configured properly.... so now lets get CubeMX to generate the code....

In the app_azure_rtos.c file, CubeMX generates the 2 separate instances of USBx, with 2 memory pools.  (this is good)

 

 

 

 

	/**************************************************************************/
	/* UsbX Host Pool                                                         */
	/**************************************************************************/
#if USE_USBX_HOST == 1
	syslog(SYSLOG_INFO, "USB Host memory pool Addr [%08x]  size=[%d]", (UINT)ux_host_byte_pool_buffer, (UINT)UX_HOST_APP_MEM_POOL_SIZE);
	memset(ux_host_byte_pool_buffer, 0, UX_HOST_APP_MEM_POOL_SIZE);
	if (tx_byte_pool_create(&ux_host_app_byte_pool, "UsbX Host memory pool",
			ux_host_byte_pool_buffer,
			UX_HOST_APP_MEM_POOL_SIZE) != TX_SUCCESS) {
		syslog(SYSLOGN_ERROR, "Ux_Byte Pool Error... ");
	} else {
		syslog(SYSLOGN_INFO, "Ux Byte Pool Created... ");

		memory_ptr = (VOID*) &ux_host_app_byte_pool;
		status = MX_USBX_Host_Init(memory_ptr);
		if (status != UX_SUCCESS) {
			syslog(SYSLOG_ERROR, "UsbX-Host Init Error");
			while (1) {	};
		}
		syslog(SYSLOG_INFO, "UsbX Host services started");
	}
#endif

	/**************************************************************************/
	/* UsbX Device Pool                                                       */
	/**************************************************************************/
#if USE_USBX_DEVICE == 1
	if (tx_byte_pool_create(&ux_device_app_byte_pool, "UsbX Device memory pool",
			ux_device_byte_pool_buffer,
			UX_DEVICE_APP_MEM_POOL_SIZE) != TX_SUCCESS) {
		syslog(SYSLOGN_ERROR, "Ux_Byte Pool Error... ");
	} else {
		syslog(SYSLOGN_INFO, "Ux Byte Pool Created... ");

		memory_ptr = (VOID*) &ux_device_app_byte_pool;
		status = MX_USBX_Device_Init(memory_ptr);
		if (status != UX_SUCCESS) {
			syslog(SYSLOG_ERROR, "UsbX-Device Init Error");
			while (1) { };
		}
		syslog(SYSLOG_INFO, "UsbX Device services started");
	}
#endif

 

 

 

from there it calls MX_USBX_Host_Init() and MX_USBX_Device_Init() which in theory initializes all the pointers, memory, stacks, threads, etc.  This all sounds good, and compiles without issue.  When debugging you see all the tasks, Mutex, Queues, etc, but the system randomly get hardware faults, memory errors, etc.

mattcrc_11-1741646014071.png

The problem is that CubeMX did not generate the #defines properly for the AZRTOS code.  IMPORTANT note; negative logic is being used to initialize the pointers and stack.  For example in file: _ux_system_initializatize.c, you can see negative logic being used (defines) to initialize the main USBX structure.  (and it appears to be done this way through out the USBX code).

 

 

 

#ifndef UX_DEVICE_SIDE_ONLY

    /* Set the _ux_system_host structure.  */
    _ux_system_host =  (UX_SYSTEM_HOST *) (((UCHAR *) regular_memory_pool_start) + memory_pool_offset);

    /* Add to the memory offset the size of the allocated block.  */
    memory_pool_offset += (ULONG)sizeof(UX_SYSTEM_HOST);

#endif

#ifndef UX_HOST_SIDE_ONLY

    /* Set the _ux_system_slave structure.  */
    _ux_system_slave =  (UX_SYSTEM_SLAVE *) (((UCHAR *) regular_memory_pool_start) + memory_pool_offset);

    /* Add to the memory offset the size of the allocated block.  */
    memory_pool_offset += (ULONG)sizeof(UX_SYSTEM_SLAVE);

#endif


#ifdef UX_OTG_SUPPORT

    /* Set the _ux_system_otg structure.  */
    _ux_system_otg =  (UX_SYSTEM_OTG *) (((UCHAR *) regular_memory_pool_start) + memory_pool_offset);

    /* Add to the memory offset the size of the allocated block.  */
    memory_pool_offset += (ULONG)sizeof(UX_SYSTEM_OTG);
#endif

 

 

 

_ux_system_host and _ux_system_device are the primary structures in USBX code.  Neither of them get initialized properly and at run time are both set to address 0x00000 (which points to ITCMRAM).

So how can this code with negative logic ever run?  @FBL 

This is a bug on the CUBEMX side - by not defining the proper system defines, and on the Embedded Code side because of all the negative logic (#defines) when trying to initialize the code.

 

1 REPLY 1
matt-crc
Associate III

To ST employee,

You will probably ask for the .ioc file, so i attached it here.