Porting TMC5x code

Hi,
I’m in the process of porting the old TMC 5x code from Cru Waller. Back then the lower levels of klipper were slightly different so some reworking is needed. The main changes are in:

  • the trapq, where instead of (3) ramp segments I create just one containing the full ramp
  • in itersolve, where I’ve created a simpler itersolve_step_gen() still based on “flush time” that passes the trapq on to stepcompress (using the function below)
  • in stepcompress, where I created the following function, that takes the ramp struct and the print time, calculates the step_clock, create and queue the mesage (bypassing in fact all the stepcompress single-steps queuing tasks)
int
stepcompress_append_tmc(struct stepcompress *sc, struct tmc_move *m
                    , double print_time)
{
    // Calculate step clock
    double offset = print_time - sc->last_step_print_time;
    double rel_sc = offset * sc->mcu_freq;
    uint64_t step_clock = sc->last_step_clock + (uint64_t)rel_sc;

    // create and queue message
    uint32_t msg[8] = {
            sc->queue_step_msgtag, sc->oid,
            (uint32_t)(rel_sc), m->pos, m->amax, m->dmax, m->vmax, m->vstart
    };
    struct queue_message *qm = message_alloc_and_encode(msg, 8);
    qm->min_clock = qm->req_clock = sc->last_step_clock;
    list_add_tail(&qm->node, &sc->msg_queue);

    // TODO: add to history

    sc->last_step_clock = step_clock + m->ticks;    // ticks = move_time * mcu_freq

    // update last_step_print_time
    calc_last_step_print_time(sc);

    // update position
    sc->last_position = m->pos;

    return 0;
}

I’m testing manually sending G1 commands. The first is executed correctly, but the second throws a Timer too close error.

Anyone familiar with the low level queues is able to help out?
Let me know if you need more info

Cheers
Stef

below you can also find the relevant part of the mcu code involved in the tmc move. When a tmc_queue command is received the function in 2nd box is executed to fill a tmc_move struct and schedule its sending. Then when the event occurs the data are sent to the driver and the timer is rescheduled

finally here the responses with the relevant time parameters for the first and second G1 commands