cancel
Showing results for 
Search instead for 
Did you mean: 

STM32N6570-DK USBX (USB-C, USB1) Error Code 43 on PC

TerZer
Associate III

Hello,

I'm trying to implement USB communication with a PC using USB1 (USB-C port) on an STM32N6570-DK with CubeMX. Most tutorials I've found on USBX are for older CubeMX versions and boards, so I'm a bit stuck.

When I connect the board to my PC, I only get Error Code 43 in Device Manager. Here's what I've done so far:

Enabled PA4 as shown in this diagram:

image.png

image.png

Enabled USB1 in CubeMX. Enabled interrupt and feft default settings otherwise:
image.png
 
Enabled USBX. System stack size: 10 * 1024, Memory pool size: 15 * 1024
image.png
Additional settings:
image.png
USB init code:
void MX_USB1_OTG_HS_PCD_Init(void)
{

  /* USER CODE BEGIN USB1_OTG_HS_Init 0 */

  /* USER CODE END USB1_OTG_HS_Init 0 */

  /* USER CODE BEGIN USB1_OTG_HS_Init 1 */
    memset(&hpcd_USB_OTG_HS1, 0x0, sizeof(PCD_HandleTypeDef));
  /* USER CODE END USB1_OTG_HS_Init 1 */
  hpcd_USB_OTG_HS1.Instance = USB1_OTG_HS;
  hpcd_USB_OTG_HS1.Init.dev_endpoints = 9;
  hpcd_USB_OTG_HS1.Init.speed = PCD_SPEED_HIGH;
  hpcd_USB_OTG_HS1.Init.phy_itface = USB_OTG_HS_EMBEDDED_PHY;
  hpcd_USB_OTG_HS1.Init.Sof_enable = DISABLE;
  hpcd_USB_OTG_HS1.Init.low_power_enable = DISABLE;
  hpcd_USB_OTG_HS1.Init.lpm_enable = DISABLE;
  hpcd_USB_OTG_HS1.Init.use_dedicated_ep1 = DISABLE;
  hpcd_USB_OTG_HS1.Init.vbus_sensing_enable = DISABLE;
  hpcd_USB_OTG_HS1.Init.dma_enable = DISABLE;
  if (HAL_PCD_Init(&hpcd_USB_OTG_HS1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN USB1_OTG_HS_Init 2 */

  /* USER CODE END USB1_OTG_HS_Init 2 */

}

 

Device Init and Stack Init where I added HAL_PCD_Start:
UINT MX_USBX_Device_Init(VOID *memory_ptr)
{
  UINT ret = UX_SUCCESS;
  UCHAR *pointer;
  TX_BYTE_POOL *byte_pool = (TX_BYTE_POOL*)memory_ptr;
  /* USER CODE BEGIN MX_USBX_Device_Init 0 */
  /* USER CODE END MX_USBX_Device_Init 0 */

  /* Initialize the Stack USB Device*/
  if (MX_USBX_Device_Stack_Init() != UX_SUCCESS)
  {
    /* USER CODE BEGIN MAIN_INITIALIZE_STACK_ERROR */
    return UX_ERROR;
    /* USER CODE END MAIN_INITIALIZE_STACK_ERROR */
  }

  /* USER CODE BEGIN MX_USBX_Device_Init 1 */
  /* USER CODE END MX_USBX_Device_Init 1 */

  /* Allocate the stack for device application main thread */
  if (tx_byte_allocate(byte_pool, (VOID **) &pointer, UX_DEVICE_APP_THREAD_STACK_SIZE,
                       TX_NO_WAIT) != TX_SUCCESS)
  {
    /* USER CODE BEGIN MAIN_THREAD_ALLOCATE_STACK_ERROR */
    return TX_POOL_ERROR;
    /* USER CODE END MAIN_THREAD_ALLOCATE_STACK_ERROR */
  }

  /* Create the device application main thread */
  if (tx_thread_create(&ux_device_app_thread, UX_DEVICE_APP_THREAD_NAME, app_ux_device_thread_entry,
                       0, pointer, UX_DEVICE_APP_THREAD_STACK_SIZE, UX_DEVICE_APP_THREAD_PRIO,
                       UX_DEVICE_APP_THREAD_PREEMPTION_THRESHOLD, UX_DEVICE_APP_THREAD_TIME_SLICE,
                       UX_DEVICE_APP_THREAD_START_OPTION) != TX_SUCCESS)
  {
    /* USER CODE BEGIN MAIN_THREAD_CREATE_ERROR */
    return TX_THREAD_ERROR;
    /* USER CODE END MAIN_THREAD_CREATE_ERROR */
  }

  /* USER CODE BEGIN MX_USBX_Device_Init 2 */
  /* USER CODE END MX_USBX_Device_Init 2 */

  return ret;
}

/**
  * @brief  Application USBX Device Initialization.
  *   None
  * @retval ret
  */
UINT MX_USBX_Device_Stack_Init(void)
{
  UINT ret = UX_SUCCESS;
  UCHAR *device_framework_high_speed;
  UCHAR *device_framework_full_speed;
  ULONG device_framework_hs_length;
  ULONG device_framework_fs_length;
  ULONG string_framework_length;
  ULONG language_id_framework_length;
  UCHAR *string_framework;
  UCHAR *language_id_framework;

  /* USER CODE BEGIN MX_USBX_Device_Stack_Init 0 */
  HAL_PWREx_EnableVddUSB();
  /* USER CODE END MX_USBX_Device_Stack_Init 0 */
  /* Get Device Framework High Speed and get the length */
  device_framework_high_speed = USBD_Get_Device_Framework_Speed(USBD_HIGH_SPEED,
                                                                &device_framework_hs_length);

  /* Get Device Framework Full Speed and get the length */
  device_framework_full_speed = USBD_Get_Device_Framework_Speed(USBD_FULL_SPEED,
                                                                &device_framework_fs_length);

  /* Get String Framework and get the length */
  string_framework = USBD_Get_String_Framework(&string_framework_length);

  /* Get Language Id Framework and get the length */
  language_id_framework = USBD_Get_Language_Id_Framework(&language_id_framework_length);

  /* Install the device portion of USBX */
  if (ux_device_stack_initialize(device_framework_high_speed,
                                 device_framework_hs_length,
                                 device_framework_full_speed,
                                 device_framework_fs_length,
                                 string_framework,
                                 string_framework_length,
                                 language_id_framework,
                                 language_id_framework_length,
                                 USBD_ChangeFunction) != UX_SUCCESS)
  {
    /* USER CODE BEGIN USBX_DEVICE_INITIALIZE_ERROR */
    return UX_ERROR;
    /* USER CODE END USBX_DEVICE_INITIALIZE_ERROR */
  }

  /* Initialize the cdc acm class parameters for the device */
  cdc_acm_parameter.ux_slave_class_cdc_acm_instance_activate   = USBD_CDC_ACM_Activate;
  cdc_acm_parameter.ux_slave_class_cdc_acm_instance_deactivate = USBD_CDC_ACM_Deactivate;
  cdc_acm_parameter.ux_slave_class_cdc_acm_parameter_change    = USBD_CDC_ACM_ParameterChange;

  /* USER CODE BEGIN CDC_ACM_PARAMETER */

  /* USER CODE END CDC_ACM_PARAMETER */

  /* Get cdc acm configuration number */
  cdc_acm_configuration_number = USBD_Get_Configuration_Number(CLASS_TYPE_CDC_ACM, 0);

  /* Find cdc acm interface number */
  cdc_acm_interface_number = USBD_Get_Interface_Number(CLASS_TYPE_CDC_ACM, 0);

  /* Initialize the device cdc acm class */
  if (ux_device_stack_class_register(_ux_system_slave_class_cdc_acm_name,
                                     ux_device_class_cdc_acm_entry,
                                     cdc_acm_configuration_number,
                                     cdc_acm_interface_number,
                                     &cdc_acm_parameter) != UX_SUCCESS)
  {
    /* USER CODE BEGIN USBX_DEVICE_CDC_ACM_REGISTER_ERROR */
    return UX_ERROR;
    /* USER CODE END USBX_DEVICE_CDC_ACM_REGISTER_ERROR */
  }

  /* Initialize and link controller HAL driver */
  ux_dcd_stm32_initialize((ULONG)USB1_OTG_HS, (ULONG)&hpcd_USB_OTG_HS1);
  /* USER CODE BEGIN MX_USBX_Device_Stack_Init_PostTreatment */
  /* Set Rx FIFO */
  HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_HS1, 0x200);
  /* Set Tx FIFO 0 */
  HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS1, 0, 0x40);
  /* Set Tx FIFO 1 */
  HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS1, 1, 0x100);
  /* USER CODE END MX_USBX_Device_Stack_Init_PostTreatment */

  /* USER CODE BEGIN MX_USBX_Device_Stack_Init 1 */
  HAL_PCD_Start(&hpcd_USB_OTG_HS1);
  /* USER CODE END MX_USBX_Device_Stack_Init 1 */

  return ret;
}

Device should show up in Windows Device Manager as:

image.png

Instead, I get this:

image.png

Changed clock configuration to 48 MHz.:

image.png

1 ACCEPTED SOLUTION

Accepted Solutions
FBL
ST Employee

Hi @TerZer 

Glad you succeeded to initialize your device. However, your FIFO allocation is not properly configured. Check these articles : knowledge article on configuring USB FIFO over USB OTG and Practical use cases to manage FIFO in USB OTG

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


View solution in original post

7 REPLIES 7
Pavel A.
Super User

The status in Device Manager says "Device descriptor request failed". 

VID 0000 and PID 0002 are not related to your device descriptors, this just means that the host cannot read the descriptors. A hardware USB sniffer would be helpful to understand why. 

 

zenderliving497
Associate II

Incomplete configuration.

TerZer
Associate III

@Pavel A. I understand that. By default generated descriptor configuration should be good.

@zenderliving497 What am I missing then? I thought it should be enough to read descriptor by pc.

Assuming the descriptors in the code are good, the problem is that the device fails to move the bits over the wires. This happens. Get a real USB bus analyzer and look what is going there. (not a software one such as wireshark). Warning: this kind of lab equipment is rare these days and can be expensive.

 

FBL
ST Employee

Hi @TerZer 

It seems the issue is coming from CubeMX code generation! Check the example provided here to check the initialization. If still having issues to enumerate as CDC, provide your source code to help you further.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


TerZer
Associate III

My solution was to change HAL_PCD_MspInit in stm32n6xx_hal_msp.c file to this:

/**
  * @brief PCD MSP Initialization
  * This function configures the hardware resources used in this example
  * @PAram hpcd: PCD handle pointer
  * @retval None
  */
void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
{
  RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  if(hpcd->Instance==USB1_OTG_HS)
  {
    /* USER CODE BEGIN USB1_OTG_HS_MspInit 0 */
		__HAL_RCC_PWR_CLK_ENABLE();

	    /** Set USB OTG HS PHY1 Reference Clock Source */
	    PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USBPHY1;
	    PeriphClkInitStruct.UsbPhy1ClockSelection = RCC_USBPHY1REFCLKSOURCE_HSE_DIRECT;

	    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
	    {
	      /* Initialization Error */
	      Error_Handler();
	    }
    /* USER CODE END USB1_OTG_HS_MspInit 0 */

  /** Initializes the peripherals clock
  */
    PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USBOTGHS1;
    PeriphClkInitStruct.UsbOtgHs1ClockSelection = RCC_USBPHY1REFCLKSOURCE_HSE_DIRECT;
    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
    {
      Error_Handler();
    }

    /* Enable VDDUSB */
    HAL_PWREx_EnableVddUSB();
    /* Peripheral clock enable */
    __HAL_RCC_USB1_OTG_HS_CLK_ENABLE();
    __HAL_RCC_USB1_OTG_HS_PHY_CLK_ENABLE();
    /* USB1_OTG_HS interrupt Init */
    HAL_NVIC_SetPriority(USB1_OTG_HS_IRQn, 2, 0);
    HAL_NVIC_EnableIRQ(USB1_OTG_HS_IRQn);
    /* USER CODE BEGIN USB1_OTG_HS_MspInit 1 */
    __HAL_RCC_GPIOA_CLK_ENABLE();

	LL_AHB5_GRP1_ForceReset(0x00800000);
	__HAL_RCC_USB1_OTG_HS_FORCE_RESET();
	__HAL_RCC_USB1_OTG_HS_PHY_FORCE_RESET();

	LL_RCC_HSE_SelectHSEDiv2AsDiv2Clock();
	LL_AHB5_GRP1_ReleaseReset(0x00800000);

	/* Peripheral clock enable */
	__HAL_RCC_USB1_OTG_HS_CLK_ENABLE();

	/* Required few clock cycles before accessing USB PHY Controller Registers */
	HAL_Delay(1);

	USB1_HS_PHYC->USBPHYC_CR &= ~(0x7 << 0x4);

	USB1_HS_PHYC->USBPHYC_CR |= (0x1 << 16) |
                                    (0x2 << 4)  |
                                    (0x1 << 2)  |
                                     0x1U;

	__HAL_RCC_USB1_OTG_HS_PHY_RELEASE_RESET();

	/* Required few clock cycles before Releasing Reset */
	HAL_Delay(1);

	__HAL_RCC_USB1_OTG_HS_RELEASE_RESET();

	/* Peripheral PHY clock enable */
	__HAL_RCC_USB1_OTG_HS_PHY_CLK_ENABLE();
    /* USER CODE END USB1_OTG_HS_MspInit 1 */

  }

}

 Also to enable bulk communication don't forget to add this bit in MX_USBX_Device_Stack_Init code:

  /* Set Rx FIFO - 512 words (2048 bytes) for all OUT endpoints */
  HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_HS1, 0x1400);
  /* Set Tx FIFO 0 - 512 words (256 bytes) for EP0 control */
  HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS1, 0, 0x1400);
  /* Set Tx FIFO 1 - 512 words (256 bytes) for CDC ACM interrupt endpoint (if used) */
  HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS1, 1, 0x1400);
  /* Set Tx FIFO 2 - 512 words (1024 bytes) for CDC ACM bulk IN endpoint */
  HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS1, 2, 0x1400);

 

FBL
ST Employee

Hi @TerZer 

Glad you succeeded to initialize your device. However, your FIFO allocation is not properly configured. Check these articles : knowledge article on configuring USB FIFO over USB OTG and Practical use cases to manage FIFO in USB OTG

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.