Getting started with USB-Power Delivery Source

Revision as of 13:36, 25 October 2021 by Registered User
Under construction.png Coming soon

Target description

This tutorial will help you to:

  • Use the X-NUCLEO-SRC1M1 shield that includes a TCPP02-M18 protection circuit and provides a USB Type-C® connector
  • Create a USB-PD Source Device with the NUCLEO-G0B1RE board and the X-NUCLEO-SRC1M1 shield by using STM32CubeIDE software

Prerequisites

  • Computer with Windows 7 (or higher)

Hardware


  • NUCLEO-G0B1RE (tested on rev ???) [1]
  • X-NUCLEO-SRC1M1 (tested on Rev ???) [2]
  • USB cable Type-A to Micro-B
  • USB Type-C® to Type-C® cable
  • A USB-PD sink device to test our USB-PD device

Software

  • STM32CubeIDE (tested with V1.7.0) [3]

Literature

  • UM2324 NUCLEO-G0B1RE User Manual



1. Create a USB-PD Source Device

Clock.png ???min

1.1. Creating the project

Open STM32CubeIDE and create a New STM32 Project. As a target selection, choose the NUCLEO-G0B1RE from the "Board Selector" Tab


Click "Next", then enter you project's name. Leave the other fields as default and click "Finish".


1.2. Configuring the project

When prompted for initializing peripherals with their default mode, click Yes.
At this point your project is created and you are left with the STM32CubeMX view. In the next steps, we will configure the peripherals and options needed for the project.

1.2.1. Configure UCPD peripheral

Select the UCPD1 peripheral and enable it in source mode. Under the NVIC Settings tab, enable USB global interrupts.


Under the DMA Settings tab, add UCPD1_RX and UCPD1_TX DMA requests.


1.2.2. Configure FreeRTOS Middleware

In the Middleware section, enable FreeRTOS with CMSIS_V1 interface. Under the Config Parameters tab, change "TOTAL_HEAP_SIZE" to 7000 bytes.

0-FreeRTOSConf.png


Then, under the Include Parameters tab, Enable "eTaskGetState" include definition.

1-FreeRTOSConf.png


1.2.3. Configure USBPD Middleware

In the Middleware section, enable USBPD with the following configuration:

  • Port Configuration: Port 0: UCPD1
  • Stack Configuration: PD3 Full Stack
  • Timer service Source: TIM1

Under the PDO General Definitions tab, verify the following configuration:

  • Number of Sink PDOs for port 0: 1
  • Port 0 Sink PDO 1 0x2201912C (correspond to a 5V 3A source)


1.2.4. Configure ADC peripheral

In order for the Power Delivery stack to work, VBUS needs to be monitored. To do it, an ADC needs to be configured to measure the VBUS voltage.
In the Analog section, select ADC1 channel 0. You will then see pin PA0 turn green in the Pinout view. Under the Parameters Settings tab, configure the following fields:

  • Clock prescaler : Synch / 4
  • Enable Continuous conversion
  • Overrun data overwritten
  • Sampling time: 160.5 Cycles


Under the GPIO Settings tab, rename pin PA0 to VSENSE, a more descriptive name for the pin used for VBUS monitoring.

1-ADC1Conf.png


Then, under the USer Constants tab, add a constant named "VDD_APPLI" of value "3300".

2-ADC1Conf.png



1.2.5. Configure Clocks

Under the Clock Configuration main tab, change system clock mux to PLLCLK. It will set HCLK clock to 64MHz.

0-Clock.png


1.3. References