cancel
Showing results for 
Search instead for 
Did you mean: 

USB CDC device conflict with other peripheral

ABricout
Associate III

Hello,

I am working on the STM32H7A3ZGT6 with the following parameters

  • CubeIDE 1.13.0
  • CubeMX 6.9.0

I am trying to add a USB device CDC for debugging. My objective is to print debug data on the virtual port com. I am sucessufull at sending data directly after the USB CDC init but when I use another module, the USB isn't working anymore and the TX function if returning a Busy error

 

I configured the USB with the following parameters: (Clock to USB = 48MHz)

ABricout_0-1689093133117.png

ABricout_1-1689093141352.png

The USB is initialized fine and I can open the Port Com on my computer.

If I put data to the usb directly after the USB init it is working, but once I use another peripheral (UART, SPI…) the USB no longer outputs any data and the function CDC_Transmit_HS returns a busy error

 

  MX_OCTOSPI2_Init();
  MX_USB_DEVICE_Init();  // INIT USB OK
  /* USER CODE BEGIN 2 */
  HAL_Delay(5000);
  uint8_t test_cdc_usb[] = "Coucou";
  print_debug_usb(test_cdc_usb, sizeof(test_cdc_usb)); // PUT USB DATA OK
  print_debug_usb(test_cdc_usb, sizeof(test_cdc_usb)); // PUT USB DATA OK
  /*Memory*/
  memory_SPI_Init(); // USES OCTOSPI2
  memoryMes_init();  // USES OCTOSPI2
  print_debug_usb(test_cdc_usb, sizeof(test_cdc_usb));  // PUT USB DATA ERROR BUSY

 

The Function used to flush data to the USB CDC is the following:

 

uint8_t usb_cdc_debug_buffer[2048];
void print_debug_usb(uint8_t * data, uint16_t size)
{
	memcpy(usb_cdc_debug_buffer, data, size);
	usb_cdc_debug_buffer[size] = '\n';
	while(CDC_Transmit_HS(usb_cdc_debug_buffer, (size+1)) == USBD_BUSY);
	HAL_Delay(300);
}

 

I didn't change the code genereated by CubeMX for the USB device and am using the CDC_Transmit_HS found in the usbd_cdc_if.h file.

Do you have any idea where this could come from?

thank you

Augustin

 

5 REPLIES 5
AScha.3
Chief III

How did you set the interrupts priority?

Usb working fine with high priority, just system and systick should be higher, all other lower.

 

If you feel a post has answered your question, please click "Accept as Solution".
ABricout
Associate III

Hello,

The priority settings does not change the problem. I put the usb as highest after the system and I still have the same behavior

gbm
Lead III

DCC_Transmit_FS() must be called from an interrupt service routine of the same priority as USB interrupt If you call it from main, it will sooner or later hang.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
ABricout
Associate III

Ok, so I created a timer with the same interrupt priority and I call the function CDC_TRANSMIT_HS in the handler of this timer.

The result is still the same, when I use another peripheral I get a busy error from the CDC_TRANSMIT_HS

#include "usbd_cdc_if.h"
#include "tim.h"

uint8_t usb_cdc_debug_buffer[2048];
uint16_t usb_cdc_data_size;
void USB_handler(void)
{
	HAL_TIM_Base_Stop_IT(&htim17); // Time timer
	CDC_Transmit_HS((uint8_t*)usb_cdc_debug_buffer, usb_cdc_data_size);
}

void print_debug_usb(char * data, uint16_t size)
{
	memcpy(usb_cdc_debug_buffer, data, size);
	usb_cdc_debug_buffer[size] = '\r';
	usb_cdc_debug_buffer[size+1] = '\n';
	usb_cdc_data_size = size+2;
	HAL_TIM_Base_Start_IT(&htim17); // Time timer

	HAL_Delay(300);
}

 

ABricout
Associate III

I also tried to put an echo in the USB received function (sure to have the same IT priority) to send the data received back. I got the same result BUSY:

static int8_t CDC_Receive_HS(uint8_t* Buf, uint32_t *Len)
{
  /* USER CODE BEGIN 11 */
  USBD_CDC_SetRxBuffer(&hUsbDeviceHS, &Buf[0]);
  USBD_CDC_ReceivePacket(&hUsbDeviceHS);
  uint16_t len = *Len;
  CDC_Transmit_HS (Buf, len);
  return (USBD_OK);
  /* USER CODE END 11 */
}