cancel
Showing results for 
Search instead for 
Did you mean: 

[STM32G431KBU3 - USBPD] - Problem when trying to use another ADC

CGonz.5
Associate II

Dear all,

I wanted to develop a USB Power Delivery SINK project using my STM32G431KBU3 MCU.

For that reason, I have designed a custom PCB and follwed carefully ST's WiKi:

https://wiki.st.com/stm32mcu/wiki/STM32StepByStep:STM32_Advance_USB-Power_Delivery_Sink

I have successfully created an advanced SINK aplication in which I can negotiate Up to 6 different PDOs. I have used ADC2 Channel2 to read VBUS regarding my PCB demanded that.

The point is, everything works OK but, when trying to use ADC1 for other purposes of my aplication, USBPD negotiation stops working. Only configuring ADC1 in CUBE makes USBPD stops working. I didn't use ADC1 functions yet.

When sniffing USBPD trace, I can notice that something is wrong with ADC2 Channel2, the one which monitors VUSB.

So, my question is, are ADC1 and ADC2 not compatible in this USBPD SINK application? Is there any way to use ADC1 without stopping ADC2 and USBPD app??

Thank you in avance!

12 REPLIES 12
HFISTM
ST Employee

Hello @CGonz.5​ ,

Can you share the trace you are talking about ?

There shouldn't be any issue using another ADC for you application. Is your ADC1 initialized at the same time that the ADC2 ? If you followed the wiki, did you change the used ADC to ADC2 in function BSP_USBPD_PWR_VBUSGetVoltage ?

I case you are now aware of it, you can find a complete project, created by CubeMX and using a G474RE in x-cube-tcpp here.

Regards

CGonz.5
Associate II

Dear Heol,

Here is the trace I can se when no configuring ADC1, only using ADC2 - Channel 2 for the USB-PD application. Everything is OK:

0693W00000JP6TPQA1.pngThen, I just configure ADC1 - Channel 3. Generation code from CUBE, no any code or ADC usage, compilation and here is what i got:

0693W00000JP6bOQAT.pngYes, I changed ADC1 to ADC2 in function BSP_USBPD_PWR_VBUSGetVoltage , here is the code:

0693W00000JP6dAQAT.png 

If you notice, the new trace of USBPD, it seems that VBUS is being read wrong, as if now the application is getting VDDA_APPLI from ADC1 rather than ADC2 as configured previously...

What do you think?

Thank you in advance,

Carlos.

HFISTM
ST Employee

Dear @CGonz.5​,

It seems that you ADC2 is weirdly configured.

Do you mind sharing your code ? Or at least the MX ADC (for both ADC) initialization functions and the order they are called at the start of you main?

Thank you,

Regards

CGonz.5
Associate II

Dear Heol,

I followed carefully WiKi when configuring the ADC. Here my ADC2 configuration:

0693W00000JPIUFQA5.png 

Attached my main.c

Regards,

Carlos.

HFISTM
ST Employee

Dear Carlos,

I'm afraid the file you sent doesn't contains any code related to ADC1 configuration.

Did you configured it in CubeMX like you said earlier?

Regards

CGonz.5
Associate II

Dear Heol,

Yes you are right. I attach main.c in which both ADCs are configured.

Also the images in which CUBE is configured:

ADC2: the one used for USBPD application:

0693W00000JPJxwQAH.png 

ADC1: the one used for my application (DMA enabled):

0693W00000JPJwUQAX.png0693W00000JPJwyQAH.png0693W00000JPJxIQAX.png 

What do you think?

Regards,

Carlos

HFISTM
ST Employee

Thank you for this file.

Everything seems ok with it. Could you please also share your hal_msp.c file, to verify the DMA config ?

Thank you & best regards

CGonz.5
Associate II

Sure,

Find it attached.

I will try another approach... I will map my 3 analog inputs to 3 different channels of ADC1:

  • PA.0: analog input for my application. Channel 1.
  • PA.1:analog input for USB-PD: VSENSE. Channel 2.
  • PA.2: analog input for my application. Channel 3.

When I use this configuration, USBPD keeps working good, but now I have to access to Channel 1 and 3 as well.

I see USBPD uses "LL_ADC_REG_ReadConversionData12(ADC1)" to read VSENSE, but I don't know what this macro does, how it reads ADC1 Channel2 if that channel 2 is not specified in the argument, only ADC1 is specified...

How can I read Channel 1 and 3 without changing anything or interferring into Channel 2?

Regards,

Carlos.

HFISTM
ST Employee

I don't see anything in your main and msp files that can wrongly or reconfigure the ADC, your CubeMX screenshots looks good too. The issue could also comes from the user code you added alongside the wiki example.

Regarding your second question, as PA1 can be set to ADC1 ch2 or ADC2 ch2, yes you can use the same ADC for your application than for USBPD. You will need to modify a bit BSP_USBPD_PWR_VBUSGetVoltage function in order for it to sense the right channel, as the base example provided by the wiki assumes you only have the VBUS channel configured in your ADC. That is why LL_ADC_REG_ReadConversionData12 is used, this functions just reads the conversion result of the ADC (The ADC can only read one channel at a time), and because only one channel is configured, this result is the result of this channel.

In you case with multiple channels, you will need to use something else. As you are already using a DMA, I suggest the DMA can fill an array with the results of the conversions of the three channels, and function BSP_USBPD_PWR_VBUSGetVoltage can read this array (at the index corresponding the the VBUS channel) instead of using LL_ADC_REG_ReadConversionData12.

Regards