cancel
Showing results for 
Search instead for 
Did you mean: 

USBX issue in the STM32N657X0H3Q (Nucleo-N657x0-Q) board

Grace_04
Associate

 

 

We are working on a bare-metal application using USBX on an STM32N657X0H3Q device.
In CubeMX, we configured USB1_OTG_HS under Connectivity and enabled USBX in Middleware.

However, when we execute the following function:

 

 

static 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 */

/* 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 */
/* Configure FIFOs for HS USB */


HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_HS1, 0x200);

/* Set Tx FIFO 0 */
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS1, 0, 0x10);

/* Set Tx FIFO 2 */
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS1, 1, 0x10);

/* Set Tx FIFO 3 */
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS1, 2, 0x20);

/* USER CODE BEGIN USBX_Device_Init 2 */

ux_dcd_stm32_initialize((ULONG)USB1_OTG_HS, (ULONG)&hpcd_USB_OTG_HS1);

/* Start USB Peripheral */

HAL_PCD_Start(&hpcd_USB_OTG_HS1);

/* USER CODE END USBX_Device_Init 2 */


/* USER CODE END USB1_OTG_HS_Init 2 */

}

 

And after calling HAL_PCD_Start():

 

 

HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd)

{

__HAL_LOCK(hpcd);

__HAL_PCD_ENABLE(hpcd);

(void)USB_DevConnect(hpcd->Instance);

__HAL_UNLOCK(hpcd);

 

return HAL_OK;

}

 

Windows immediately shows the error:

“USB Device Not Recognized – The last USB device you connected to this computer malfunctioned.”

We are unable to detect the USB device on the host PC and we would like assistance in identifying what is missing or incorrectly configured in our USB1_OTG_HS and USBX setup.

 

and the in the main() function is

int main(void)

{

 

/* USER CODE BEGIN 1 */

 

/* USER CODE END 1 */

 

/* MCU Configuration--------------------------------------------------------*/

HAL_Init();

 

/* USER CODE BEGIN Init */

SystemClock_Config();

/* USER CODE END Init */

 

/* USER CODE BEGIN SysInit */

MX_USBX_Init();

/* USER CODE END SysInit */

 

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_USB1_OTG_HS_PCD_Init();

SystemIsolation_Config();

/* USER CODE BEGIN 2 */

 

/* Now USB CDC is ready – transmit test message */

ULONG sent;

uint8_t msg[] = "USB CDC Ready!\r\n";

 

USBD_CDC_ACM_Transmit(msg, sizeof(msg) - 1, &sent);

/* USER CODE END 2 */

 

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

/* USER CODE END WHILE */

 

/* USER CODE BEGIN 3 */

ux_device_stack_tasks_run();

ULONG received = 0;

 

if (USBD_CDC_ACM_Receive(buffer, sizeof(buffer), &received) == UX_SUCCESS &&

received > 0)

{

USBD_CDC_ACM_Transmit(buffer, received, &sent);

}

}

/* USER CODE END 3 */

}image.jpg

0 REPLIES 0