Skip to content

New debugging facility & stm32 driver refactoring #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 16, 2022

Conversation

runger1101001
Copy link
Member

@runger1101001 runger1101001 commented Feb 12, 2022

This pull request separates the debugging concept from the telemetry concept in the monitoring.

Debugging is only used for debug output, not the automatic sending of motor variables.

A debug statement now looks like this:

SIMPLEFOC_DEBUG("message");              // simple string
SIMPLEFOC_DEBUG("message", 42);       // string and int value
SIMPLEFOC_DEBUG("message", 42.0f);  // string an float value

It is implemented via the new class SimpleFOCDebug. The API is purely static, so you don't have to keep instances of the debug class ready to use it. Just include "SimpleFOCDebug.h" and use the macro.
If your use case needs it, you can also call SimpleFOCDebug::print(...) or SimpleFOCDebug::println(...) directly, for example to output multiple values on the same line.

Using the macro has some advantages:

  • the macro automatically uses F(str) to use the FlashStringHelper. No need to remember it.
  • when using the macro, the debug can be completely removed from the code by setting the build option "SIMPLEFOC_DEBUG_DISABLE"

So the usage pattern should be:

  • either SIMPLEFOC_DEBUG(msg)
  • or
#ifndef SIMPLEFOC_DEBUG_DISABLE
SimpleFOCDebug::print(...);
SimpleFOCDebug::println(...);
#endif

In this case we can completely remove the debug from the code by setting the build flag. I tried it out for SAMD21 and it makes about 1KB difference to the code size.

There are other ways we could do it of course, its only a suggestion, so @askuric if you don't like it let me know and we can change it....

@runger1101001
Copy link
Member Author

runger1101001 commented Mar 9, 2022

This pull request now also contains the STM32 driver refactoring, doh! Should have made a new branch for it.

I've tested it seems to compile on the boards I've tried, and it works to set up 2x 6-PWM with hardware interfaces. I now have two motors turning on my STM32G491 based Rosmo dual ESC board. yay!

If you set the build flag SIMPLEFOC_STM32_DEBUG it will print the pin combinations it tests, something like this:

Initializing driver 0...
TIM1-CH1 TIM1-CH1N TIM1-CH2 TIM1-CH2N TIM1-CH3 TIM1-CH3N score: 1
STM32: best: TIM1-CH1 TIM1-CH1N TIM1-CH2 TIM1-CH2N TIM1-CH3 TIM1-CH3N score: 1
Initializing driver 1...
TIM3-CH1 TIM2-CH2 TIM3-CH2 TIM3-CH1 TIM3-CH4 TIM8-CH4N score: -4
TIM3-CH1 TIM2-CH2 TIM3-CH2 TIM3-CH1 TIM8-CH4 TIM8-CH4N score: -4
TIM3-CH1 TIM2-CH2 TIM3-CH2 TIM8-CH2N TIM3-CH4 TIM8-CH4N score: -6
TIM3-CH1 TIM2-CH2 TIM3-CH2 TIM8-CH2N TIM8-CH4 TIM8-CH4N score: -6
TIM3-CH1 TIM2-CH2 TIM3-CH2 TIM16-CH1 TIM3-CH4 TIM8-CH4N score: -6
TIM3-CH1 TIM2-CH2 TIM3-CH2 TIM16-CH1 TIM8-CH4 TIM8-CH4N score: -6
TIM3-CH1 TIM2-CH2 TIM8-CH2 TIM3-CH1 TIM3-CH4 TIM8-CH4N score: -4
TIM3-CH1 TIM2-CH2 TIM8-CH2 TIM3-CH1 TIM8-CH4 TIM8-CH4N score: -4
TIM3-CH1 TIM2-CH2 TIM8-CH2 TIM8-CH2N TIM3-CH4 TIM8-CH4N score: -6
TIM3-CH1 TIM2-CH2 TIM8-CH2 TIM8-CH2N TIM8-CH4 TIM8-CH4N score: -6
TIM3-CH1 TIM2-CH2 TIM8-CH2 TIM16-CH1 TIM3-CH4 TIM8-CH4N score: -6
TIM3-CH1 TIM2-CH2 TIM8-CH2 TIM16-CH1 TIM8-CH4 TIM8-CH4N score: -6
TIM3-CH1 TIM8-CH1N TIM3-CH2 TIM3-CH1 TIM3-CH4 TIM8-CH4N score: -4
TIM3-CH1 TIM8-CH1N TIM3-CH2 TIM3-CH1 TIM8-CH4 TIM8-CH4N score: -4
TIM3-CH1 TIM8-CH1N TIM3-CH2 TIM8-CH2N TIM3-CH4 TIM8-CH4N score: -6
TIM3-CH1 TIM8-CH1N TIM3-CH2 TIM8-CH2N TIM8-CH4 TIM8-CH4N score: -6
TIM3-CH1 TIM8-CH1N TIM3-CH2 TIM16-CH1 TIM3-CH4 TIM8-CH4N score: -6
TIM3-CH1 TIM8-CH1N TIM3-CH2 TIM16-CH1 TIM8-CH4 TIM8-CH4N score: -6
TIM3-CH1 TIM8-CH1N TIM8-CH2 TIM3-CH1 TIM3-CH4 TIM8-CH4N score: -4
TIM3-CH1 TIM8-CH1N TIM8-CH2 TIM3-CH1 TIM8-CH4 TIM8-CH4N score: -4
TIM3-CH1 TIM8-CH1N TIM8-CH2 TIM8-CH2N TIM3-CH4 TIM8-CH4N score: -6
TIM3-CH1 TIM8-CH1N TIM8-CH2 TIM8-CH2N TIM8-CH4 TIM8-CH4N score: -6
TIM3-CH1 TIM8-CH1N TIM8-CH2 TIM16-CH1 TIM3-CH4 TIM8-CH4N score: -6
TIM3-CH1 TIM8-CH1N TIM8-CH2 TIM16-CH1 TIM8-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM2-CH2 TIM3-CH2 TIM3-CH1 TIM3-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM2-CH2 TIM3-CH2 TIM3-CH1 TIM8-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM2-CH2 TIM3-CH2 TIM8-CH2N TIM3-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM2-CH2 TIM3-CH2 TIM8-CH2N TIM8-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM2-CH2 TIM3-CH2 TIM16-CH1 TIM3-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM2-CH2 TIM3-CH2 TIM16-CH1 TIM8-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM2-CH2 TIM8-CH2 TIM3-CH1 TIM3-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM2-CH2 TIM8-CH2 TIM3-CH1 TIM8-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM2-CH2 TIM8-CH2 TIM8-CH2N TIM3-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM2-CH2 TIM8-CH2 TIM8-CH2N TIM8-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM2-CH2 TIM8-CH2 TIM16-CH1 TIM3-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM2-CH2 TIM8-CH2 TIM16-CH1 TIM8-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM8-CH1N TIM3-CH2 TIM3-CH1 TIM3-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM8-CH1N TIM3-CH2 TIM3-CH1 TIM8-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM8-CH1N TIM3-CH2 TIM8-CH2N TIM3-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM8-CH1N TIM3-CH2 TIM8-CH2N TIM8-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM8-CH1N TIM3-CH2 TIM16-CH1 TIM3-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM8-CH1N TIM3-CH2 TIM16-CH1 TIM8-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM8-CH1N TIM8-CH2 TIM3-CH1 TIM3-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM8-CH1N TIM8-CH2 TIM3-CH1 TIM8-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM8-CH1N TIM8-CH2 TIM8-CH2N TIM3-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM8-CH1N TIM8-CH2 TIM8-CH2N TIM8-CH4 TIM8-CH4N score: 1
TIM8-CH1 TIM8-CH1N TIM8-CH2 TIM16-CH1 TIM3-CH4 TIM8-CH4N score: -6
TIM8-CH1 TIM8-CH1N TIM8-CH2 TIM16-CH1 TIM8-CH4 TIM8-CH4N score: -6
STM32: best: TIM8-CH1 TIM8-CH1N TIM8-CH2 TIM8-CH2N TIM8-CH4 TIM8-CH4N score: 1

@runger1101001 runger1101001 changed the title New debugging facility New debugging facility & stm32 driver refactoring Mar 9, 2022
@runger1101001
Copy link
Member Author

STM32 driver refactor should now support choosing best choice of timers for a given pin combination, considering all the timers defined in the pinmap, i.e. including the alternate peripheral timers. Also some other small improvements to the initialisation logic.

This means:

  • alternate function timers supported
  • best choice made: prefers the combination using least number of timers
  • prefers hardware 6-PWM over software 6-PWM combinations
  • keeps track of and considers timers already used (multi-motor compatible)
  • supports hardware 6-PWM using multiple timers (each high/low pair on complementary channels of the same timer, but different timers possible per pair)
  • supports software 6-PWM on up to 6 timers (TODO test this)

@runger1101001
Copy link
Member Author

I've now tested this on another ESC board of my design, with STM32F401 and 3-PWM, and this is working fine too... I think I will merge it to dev at this point so we have a chance to test it well...

@runger1101001 runger1101001 merged commit 5038266 into simplefoc:dev Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant