cancel
Showing results for 
Search instead for 
Did you mean: 

Threadx thread gets suspended from EMC interference

marcus1129
Associate

Im using USBx as my USB driver for the STM32U599VJT6Q.

This driver has 2 functions: "usbx_cdc_acm_read_thread_entry" and "usbx_cdc_acm_write_thread_entry" each of which runs in their own thread.

The problem im having is the thread running "usbx_cdc_acm_write_thread_entry" gets semaphore suspended whenever interference occurs on the USB transmission line.

The problem appears to be related to the function "ux_device_class_cdc_acm_write" as i have not been able to recreate the issue after removing it from the function.

I haven't found any functions that can circumvent a semaphore suspension, so instead i have attempted to delete the thread and recreate it periodically, this works before interference occurs, however after the interference occurs it does manage to create a new thread but it still does not run.

Transmit function:

 

 

 

VOID usbx_cdc_acm_write_thread_entry(ULONG thread_input)
{
	/* Private Variables */
	ULONG tx_actual_length;
    UX_SLAVE_DEVICE *device;
    const char ctrStr[10] = "Alive!\n";
    device = &_ux_system_slave->ux_system_slave_device;

    uint32_t ctr = 0;

	char* testData;
	while(1)
	{
//		if ((device->ux_slave_device_state == UX_DEVICE_CONFIGURED) && (cdc_acm != UX_NULL))
//		{
			//if (tx_queue_receive(&USB_data, &testData, TX_WAIT_FOREVER) == TX_SUCCESS)
//			if (tx_queue_receive(&USB_data, &testData, TX_NO_WAIT) == TX_SUCCESS)
//			{
//				ux_device_class_cdc_acm_write(cdc_acm, testData, strlen(testData), &tx_actual_length);
//			}
//			else
//			{
				if (ctr++ > 10)
				{
					ctr = 0;
					ux_device_class_cdc_acm_write(cdc_acm, ctrStr, strlen(ctrStr), &tx_actual_length);
				}
				tx_thread_sleep(1);
//			}
//		}
		tx_thread_sleep(1);
		//free(testData);
	}
}

 

 

 

 

My attempt at solving the problem:

 

 

 

static VOID app_ux_device_thread_entry(ULONG thread_input)
{
	int counter = 0;
        
        /*
        ...
        */

	  while (1)
	  {
		tx_thread_sleep(100); // <---- Added to allow other processes to run
		if(counter > 15){
			counter = 0;
			UINT status1 = tx_thread_terminate(&ux_cdc_write_thread);
			UINT status2 = tx_thread_delete(&ux_cdc_write_thread);
			tx_thread_sleep(100);
			UINT status3 = tx_thread_create(&ux_cdc_write_thread, "cdc_acm_write_usbx_app_thread_entry", usbx_cdc_acm_write_thread_entry, 1, pointer, 1025, 13, 13, TX_NO_TIME_SLICE, TX_AUTO_START); // Priority was 20
//			UINT status4 = tx_thread_resume(&ux_cdc_write_thread);
//			int temp = 3;
		}
		else{
			counter++;
		}
	  }

  /* USER CODE END app_ux_device_thread_entry */
}

 

 

 

 

0 REPLIES 0