Motor control seems working. It can spin a lot faster than what it can with modes different to foc_current. That is good.
But I would like to read temperature, VBUS and pot. I cannot get it to work with analogRead. They just read 0. Using digitalRead I can see observe if the pot is all the way CCW or CV.
I’m not sure what’s going on there, but I have a hunch: the STM32G4 code for the ESC-1 board sets up the ADC in a specific way, and probably this interferes with using analogRead().
I don’t have a quick solution for you here. You can either play with the library code to (for example) add the analog inputs you need to what is read by the current sensing code, or figure out a way to use them in parallel.
If you’re willing to wait a few weeks to months, the ADC code in SimpleFOC is being refactored, so after this task is completed, then there may be a cleaner way to use the other ADC pins.
I figured out that it would be the case. Analog read stops working after CurrentSensor.init(). When DMA is configured it dies.
I’ll try to look into configuring the other ADCs under DMA also. I guess I could be able to get hints from CubeIDE generated code?!
I also tried to configure the current sensor pins as pot, temp and VBUS, but that does not work. So I guess that something is hard coded for the actual current pins.
Just to confirm, that I also implemented your changes on top of V2.21 and they seem to work just fine! Thanks a lot, @ HoeckDK this helped me a tremedously!