2019-12-10 08:10 PM
Is there a way to connect some pins to both ADC and comparator inputs, for example ADC_IN2 and COMP1_INP? It should be possible because they both are inputs.
2019-12-10 10:07 PM
You mean, routing the peripheral input to the same pin ?
That should supposedly work, others have successfully routed a UART in/output to multiple pins, albeit on other STM32 devices.
I can't say much about the G4, never tried that device.
2019-12-11 12:46 AM
I suppose that GPIOx_AFR registers are not required for analog peripheral, analog is turned in GPIOx_MODER register. But CubeMX does not allow to set ADC_IN2 and COMP1_INP to one pin. Maybe this is a Cube issue and I can to set them "manually"?
2019-12-11 01:15 AM
As said, I don't know the G4 device, so I can't speak of certain knowledge.
And neither do I use CubeMX or Cube/HAL generated code.
However, it is fact that Cube does not cover all possible use cases. It can't, IMHO.
I suppose the designer/implementing team has not foreseen your use case at all.
> Maybe this is a Cube issue and I can to set them "manually"?
I would definitely try, shouldn't cost you too much time.
2019-12-11 11:30 PM
I fully understand what you want to do.
In theory it would be possible: as you rightly say, being two inputs it would be possible to connect the same pin to an ADC and a COMP without problems (thus saving the use of an external pin).
Unfortunately, although the STM32G4 is very flexible compared to STM32F3, it does not have all the possible connections.
When a pin is configured in the "Analog input" mode, it is available to all analog peripherals ADMITTED THAT THEY HAVE THE PHYSICAL CONNECTION AT THAT PIN.
To check which pin can be shared between an ADC input and a comparator we must start from the table that lists the function of each pin found in the data-sheet of each MCU.
For example: let's analyze the data sheet of STM32G431RBT6, downloading the file DS12589 Rev1
Table 12 (from page 51) is the one to refer to. Open the PDF file and search for "COMP".
You will see that the search ends on pin "PF1": and you will see that that pin is associated with "COMP3_INM" and "ADC2_IN10". So this pin could do with your use.
Otherwise we continue the search and find the pin PC0 which is associated with "COMP3_INM" and "ADC12_IN6". And so on......
Once you have found the pin associated with the analog device you wish to use, you can have shared use set up with CubeMX (or CubeIDE): you must click on the "+" symbol that you find in the pin next to the indication of the device name.
See this:
Best regards
Andrea