cancel
Showing results for 
Search instead for 
Did you mean: 

NUCLEO-F767ZI as USB host and NUCLEO-F103RB via ST-Link (VCP) and UART as USB Client

BC_1990
Associate

Hi,

I'm trying to set up a USB host using a Nucleo144-F767ZI, which should exchange data with a Nucleo64-F103RB through USB. Since the Nucleo64 doesn't have a USB interface for the F103, I want to utilize the VCP (Virtual Com Port) of the ST-Link on the board. For a simple functionality test, I've configured both boards as follows:

Nucleo144-F767ZI:

  • RCC: HSE BYPASS Clock Source
  • USB_OTG_FS: Mode Host_Only
  • Middleware USB_Host
    • Communication Host Class (Virtual Port COM)
    • Platform Settings Driver_VBUS_FS: GPIO Output PG6

In "usb_host.c," I've implemented the following variables and functions:

 

uint8_t rx_buffer[100];
uint8_t tx_buffer[] = "0123456789";
/* USER CODE BEGIN 0 */
void userFunction(void){
	static uint32_t i = 0;

	if (Appli_state == APPLICATION_READY) {
		if ((HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin) == GPIO_PIN_SET) && i > 0xffff) {
			USBH_CDC_Transmit(&hUsbHostFS, tx_buffer, 10);
			i = 0;
		}

		i++;
	}
}
/* USER CODE END 0 */
/* USER CODE BEGIN 1 */
void USBH_CDC_TransmitCallback(USBH_HandleTypeDef *phost){
	USBH_CDC_Receive(phost, rx_buffer, 10);

	HAL_GPIO_TogglePin(LED0_GPIO_Port, LED0_Pin);
}

void USBH_CDC_ReceiveCallback(USBH_HandleTypeDef *phost){
	HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
}
/* USER CODE END 1 */

 

The function "userFunction" is called cyclically in the while loop of the main function.

Nucleo64-F103RB:

  • USART2 on PA2 and PA3
    • NVIC USART2 enable

I have implemented the following source code in main.c:

 

uint8_t data_tx[10];
uint8_t data_rx[10];

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) {

}

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
//	if (!memcmp(data_rx, data_expected, sizeof(data_expected))) {
//		HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
//		HAL_UART_Transmit_IT(&huart2, (uint8_t *) data_tx, strlen(data_tx));
//	}

	HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
	memcpy(data_tx, data_rx, sizeof(data_tx));
	HAL_UART_Transmit_IT(&huart2, data_tx, sizeof(data_tx));

	HAL_UART_Receive_IT(&huart2, data_rx, sizeof(data_rx));
	memset (data_rx, '\0', sizeof(data_rx));
}

 

After initializing the peripherals in the main function, I call the function:

 

HAL_UART_Receive_IT(&huart2, data_rx, sizeof(data_rx));

 

I then connect the two devices using an appropriate USB cable. When I inspect the variable "HCD_HandleTypeDef hhcd_USB_OTG_FS" in the debug mode, its .gState is set to "HOST_ABORT_STATE" after a short period. Using the debugging function, I have determined that this state transition coincides with the UsrLog message "No registered class for this device."

I have tested the functionality of the Nucleo64-F103RB with a computer, and the communication works flawlessly using a serial monitor.

I hope someone can help me with my issue. Please let me know if any additional information is needed.

Best regards,
BC_1990

 

1 REPLY 1
jiangfan
ST Employee

maybe you may try to check USBH_RegisterClass() is OK or not.