cancel
Showing results for 
Search instead for 
Did you mean: 

D+ USB pull up resistor on STM32H743ZIT6 not activating.

wynandsp
Associate III

Dear Colleagues,

I have tried for more than a week to get the internal D+ pull up resistor to activate on my custom board.

I have checked the clocks and they seem to be all running. I created a new project with only USB OTG FS hid class enabled. STMCube v1.12.

When I probe the D+ pin I get the following.
_legacyfs_online_stmicro_images_0693W00000birPyQAI.pngIt took me a while to find the point where the process is started and that is in

/**
  * @brief  USB_DevConnect : Connect the USB device by enabling Rpu
  * @param  USBx  Selected device
  * @retval HAL status
  */
HAL_StatusTypeDef USB_DevConnect(USB_OTG_GlobalTypeDef *USBx)
{
  uint32_t USBx_BASE = (uint32_t)USBx;
 
  /* In case phy is stopped, ensure to ungate and restore the phy CLK */
  USBx_PCGCCTL &= ~(USB_OTG_PCGCCTL_STOPCLK | USB_OTG_PCGCCTL_GATECLK);
 
  USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_SDIS;
 
  return HAL_OK;
}

If I put a break point at line 13 the output on the D+ pin PA12 remains low, but when I step to the next line the output appears is in the image above.

When I repeat the same exercise, but with the STM32H767 the D+ pin PA12 is pulled all the way up to 3.3V and I can see the burst pulses coming through from the host.

If I add an external 1.5kOhm resistor to my custom board with the STM32H743ZIT6 the host responds as with the F767 device.

I am attaching my setup code and hope someone can see what is wrong.

static VOID app_ux_device_thread_entry(ULONG thread_input)
{
  /* USER CODE BEGIN app_ux_device_thread_entry */
  MX_USB_Device_Init();
  /* USER CODE END app_ux_device_thread_entry */
}
/**
  * @brief MX_USB_Device_Init
  *        Initialization of USB device.
  * Init USB device Library, add supported class and start the library
  * @retval None
  */
void MX_USB_Device_Init(void)
{
  /* USER CODE BEGIN USB_Device_Init_PreTreatment_0 */
  /* USER CODE END USB_Device_Init_PreTreatment_0 */
 
  /* USB_OTG_HS init function */
  MX_USB_OTG_FS_PCD_Init();
 
  /* USER CODE BEGIN USB_Device_Init_PreTreatment_1 */
  /* Set Rx FIFO */
  HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 0x200);
  /* Set Tx FIFO 0 */
  HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40);
  /* Set Tx FIFO 1 */
  HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x100);
  /* USER CODE END USB_Device_Init_PreTreatment_1 */
 
  /* initialize the device controller driver*/
  _ux_dcd_stm32_initialize((ULONG)USB_OTG_FS, (ULONG)&hpcd_USB_OTG_FS);
 
  HAL_PCD_Start(&hpcd_USB_OTG_FS);
 
  /* USER CODE BEGIN USB_Device_Init_PostTreatment */
  /* USER CODE END USB_Device_Init_PostTreatment */
}
/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file    usb_otg.c
  * @brief   This file provides code for the configuration
  *          of the USB_OTG instances.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2023 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "usb_otg.h"
 
/* USER CODE BEGIN 0 */
#if defined ( __ICCARM__ ) /* IAR Compiler */
#pragma location = 0x24027000
#elif defined ( __CC_ARM ) /* MDK ARM Compiler */
__attribute__((section(".UsbHpcdSection")))
//#elif defined ( __GNUC__ ) /* GNU Compiler */
__attribute__((section(".UsbHpcdSection")))
#elif defined ( __GNUC__ ) /* GNU Compiler */
__attribute__((section(".UsbHpcdSection")))
#endif
 
/* USER CODE END 0 */
 
PCD_HandleTypeDef hpcd_USB_OTG_FS;
 
/* USB_OTG_FS init function */
 
void MX_USB_OTG_FS_PCD_Init(void)
{
 
  /* USER CODE BEGIN USB_OTG_FS_Init 0 */
 
  /* USER CODE END USB_OTG_FS_Init 0 */
 
  /* USER CODE BEGIN USB_OTG_FS_Init 1 */
 
  /* USER CODE END USB_OTG_FS_Init 1 */
  hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
  hpcd_USB_OTG_FS.Init.dev_endpoints = 9;
  hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
  hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
  hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
  hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE;
  hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
  hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
  hpcd_USB_OTG_FS.Init.battery_charging_enable = DISABLE;
  hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE;
  hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
  if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN USB_OTG_FS_Init 2 */
  /* USER CODE END USB_OTG_FS_Init 2 */
 
}
 
void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
{
 
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  if(pcdHandle->Instance==USB_OTG_FS)
  {
  /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
 
  /* USER CODE END USB_OTG_FS_MspInit 0 */
 
  /** Initializes the peripherals clock
  */
    PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
    PeriphClkInitStruct.PLL3.PLL3M = 1;
    PeriphClkInitStruct.PLL3.PLL3N = 120;
    PeriphClkInitStruct.PLL3.PLL3P = 2;
    PeriphClkInitStruct.PLL3.PLL3Q = 20;
    PeriphClkInitStruct.PLL3.PLL3R = 2;
    PeriphClkInitStruct.PLL3.PLL3RGE = RCC_PLL3VCIRANGE_3;
    PeriphClkInitStruct.PLL3.PLL3FRACN = 0;
    PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLL3;
    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
    {
      Error_Handler();
    }
 
  /** Enable USB Voltage detector
  */
    HAL_PWREx_EnableUSBVoltageDetector();
 
    __HAL_RCC_GPIOA_CLK_ENABLE();
    /**USB_OTG_FS GPIO Configuration
    PA11     ------> USB_OTG_FS_DM
    PA12     ------> USB_OTG_FS_DP
    */
    GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF10_OTG2_FS;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
    /* USB_OTG_FS clock enable */
    __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
 
    /* USB_OTG_FS interrupt Init */
    HAL_NVIC_SetPriority(OTG_FS_IRQn, 6, 0);
    HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
  /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
 
  /* USER CODE END USB_OTG_FS_MspInit 1 */
  }
}
 
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle)
{
 
  if(pcdHandle->Instance==USB_OTG_FS)
  {
  /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
 
  /* USER CODE END USB_OTG_FS_MspDeInit 0 */
    /* Peripheral clock disable */
    __HAL_RCC_USB_OTG_FS_CLK_DISABLE();
 
    /**USB_OTG_FS GPIO Configuration
    PA11     ------> USB_OTG_FS_DM
    PA12     ------> USB_OTG_FS_DP
    */
    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);
 
    /* USB_OTG_FS interrupt Deinit */
    HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
  /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
 
  /* USER CODE END USB_OTG_FS_MspDeInit 1 */
  }
}
 
/* USER CODE BEGIN 1 */
 
/* USER CODE END 1 */

These are all generated by cube.

The traces from my usb connector to the controller is less than 1 inch long and impedance matched.

Please help I am stuck on this.

1 ACCEPTED SOLUTION

Accepted Solutions
wynandsp
Associate III

Thank you Amel and Jan for the response.

I found my bug not in software but in the hardware.

There is only a 100nF on VDD33USB. For some reason I had it that the power supply to the USB core would be internal and the only additional component would be a 100nF cap. After adding a 3.3V supply to this pin my two week long search was over.

What really confused me was the activity and the D+ pin so it seemed like all was well.

In my understanding of self powered and bus powered it was refering to the controller and not the USB core. I now have it self powered with the onboard 3.3V source and it is working perfectly with the code in my original post.

Thanks again for coming back to me. You guys are great!

View solution in original post

4 REPLIES 4
Amel NASRI
ST Employee

Hi @wynandsp​ ,

Not an USB expert, but I assume that VBUS sensing should be enabled:

 hpcd_USB_OTG_FS.Init.vbus_sensing_enable = ENABLE;

-Amel

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.

> If I put a break point at line 13 the output on the D+ pin PA12 remains low, but when I step to the next line the output appears is in the image above.

Try the same exercise (i.e. breakpoint and one single-step), without being connected to host.

And, for illustration, try the same (again, breakpoint and then one single-step) with the 'F7.

JW

wynandsp
Associate III

Thank you Amel and Jan for the response.

I found my bug not in software but in the hardware.

There is only a 100nF on VDD33USB. For some reason I had it that the power supply to the USB core would be internal and the only additional component would be a 100nF cap. After adding a 3.3V supply to this pin my two week long search was over.

What really confused me was the activity and the D+ pin so it seemed like all was well.

In my understanding of self powered and bus powered it was refering to the controller and not the USB core. I now have it self powered with the onboard 3.3V source and it is working perfectly with the code in my original post.

Thanks again for coming back to me. You guys are great!

Thanks for coming back with the solution.

The symptoms were indeed confusing... :)

JW