TMC stepper Initialization confused smiley
May 20, 2024 02:27PM
Hello ,

I am trying to understand how Marlin firmware initializes the TMC stepper, there is #define X_DRIVER_TYPE TMC5160 line in the configuration. h; I think here we are declaring what board we are using but after that its very hard to follow the part where the steppers are getting initialized.

i saw tmc_init function in the tmc_util header file but cant able to find where this function is getting called.

If anyone whos how the initializing is happening or how the flow is from this line #define X_DRIVER_TYPE TMC5160 line please let me know it will help for my custom project

Thanks in advance smiling smiley
Re: TMC stepper Initialization confused smiley
May 20, 2024 11:32PM
Search for #if HAS_DRIVER(TMC5160)
Re: TMC stepper Initialization confused smiley
May 21, 2024 03:21PM
Thanks for the reply, the if condition has Tmc_init function but I cant found where this function was getting called in the program
Re: TMC stepper Initialization confused smiley
May 22, 2024 02:24AM
TMC_INIT is a macro that calls tmc_int as defined for each stepper driver type
Re: TMC stepper Initialization confused smiley
May 22, 2024 12:36PM
thanks, but i have hard time understanding what's happening i am new to C++. This is what i understood

#define X_DRIVER_TYPE TMC5160 then this is converted to HAS_DRIVER(TMC5160) and in the trinamics.cpp it executes #if HAS_DRIVER(TMC5160) logic, what i cant able to understand was where these variables AXIS_LETTER, DRIVER_ID, AXIS_ID are declared for each axis
for ex : X_DRIVER_TYPE TMC5160 this should be something like this TMCMarlin
Re: TMC stepper Initialization confused smiley
May 22, 2024 01:21PM
The code within the HAS_DRIVER(TMC5160) block in Marlin/src/module/stepper/trinamic.cpp is a template

starts with
template
  void tmc_init(TMCMarlin<TMC5160Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t hyb_thrs, const bool stealth, const chopper_timing_t &chop_init, const bool interpolate, float hold_multiplier) {

So anytime a tmc_init is used this template is used

In Marlin/src/module/stepper/trinamic.cpp we have

eg

TMC_INIT(X, STEALTH_AXIS_X);

this macro expands to (with default values in Configs)

tmc_init(stepperX, 800, 16, 100, stealthchop_by_axis[STEALTH_AXIS_X], chopper_timing_X, true, 0.5)

ie from the template st, mA, microsteps, stealth, chop_init and hold_multiplier

this is the call that initializes the tmc driver.

Edited 2 time(s). Last edit at 05/22/2024 01:25PM by Dust.
Re: TMC stepper Initialization confused smiley
May 23, 2024 11:53AM
Hi,

I have a similar question. How can I access the initialized drivers from anywhere in the code?
E.g. I want to extend the M122.cpp file (M122 displays TMC debugging info) so that I can show additional info about the drivers.

Specificly, I need to communicate with encoders via SPI using the TMC5160 driver (to get information about deviation of my motors and later correct it). The TMCStepper.h library (link: [teemuatlut.github.io]) seems to provide functions (ENC_STATUS(), ENC_DEVIATION(), etc.) that I need to call in Marlin.

Here's a rough idea of what I'm trying to do:
void GcodeSuite::M122() {

    [...]

    uint8_t enc_status = driver_x.ENC_STATUS(); // access initialized driver x/y/... and show status; that obv. does not work like it is written in the code and I have to figure out how to do this.
    if (enc_status & 0x01) {
      SERIAL_ECHOLNPGM("Encoder not ready");
    } else {
      SERIAL_ECHOLNPGM("Encoder ready");
    }

    [...]

    uint32_t enc_deviation = driver_x.ENC_DEV(); // sth. like this...
    SERIAL_ECHOLNPGM("deviation enc. x: ")
    SERIAL_ECHOLN(enc_deviation);

    [...]
}
How could I access 'driver_X' (that should be already initialized)?

(sorry, I hope I won't crating a crosspost, the original post is in German with more information... [reprap.org])

Thanks in advance!

Edited 2 time(s). Last edit at 05/23/2024 11:57AM by geroldsteiner.
Sorry, only registered users may post in this forum.

Click here to login