﻿Hello Emil,

Your four steps sound very good. There are of course a lot of configuration work to do, 
the hardware now probably works OK already. 
The part 3 in your list is a big task, I think it should also include understanding a lot 
about LinuxCNC configuration and internal behavior, not only about the ethernet driver. 
I try to write the basics about the ethernet driver configuration here:

- First thing to understand is that all the pins in STM32 cannot be used as:
   STEP pins, or 
   PWM outputs or 
   Encoder inputs. 

These functions rely on the hardware timers on STM32. 

So STEP signal can be connected only on pins where one of the functions is:
   TIMx_CHn, where n = 1, 2 or 3. 
   
The PWM output signal (which you will probably not need ) can be on pins where:
   n = 1, 2, 3, 4
  
The quadrature AB Encoder input can only be connected to timer channels 1 and 2. 

These all channels are connected to:
   PWMX_XX or ENCXX labels in your EM.jpg image. 
   
Actually those LED-signals (PD12,13) in the schematic happen to have TIM4_CH1 and 2 on them, 
so basically they could be used as STEP signal, but I have not configured them that way 
in the firmware, so change of code would be needed for that.

-Another thing to understand is that if you connect a step generator to some timer, 
lets say to pins PB6 an PB7 as STEP and DIR, you cannot use the other TIM4 pins to 
any other timer functionality (STEPGEN, ENCODER, PWM). 

So the rest of the TIM4 channels (PB8, PB9) can then only be used as INPUT or OUTPUT, 
which do not need timer functionality. There are five different timers available in STM32F407, 
so maximum number of step generators is five !!!!!!!

-The basic INPUT and OUTPUT pins and also the DIR pin in StepGen can be connected to 
any of the pins labelled as IO or ENC or PWM in EM.jpg. 
Those can be used for you limit switch inputs or emergency stops etc..

-The stepgen configuration syntax is:

STEPGEN Name StepPin DirPin PulseLen Delay1 Delay2

Where:

   Pulse length is length of the "high" pulse given to Step pin. 
   It is counted as clock cycles of the timer, which is running at 1.68MHz (If I remember right..)
   
   Delay1 is the minimum delay from Step pulse ending to the direction change.
   
   Delay2 is the minimum delay from direction change to the first pulse to the new direction.
   
Honestly, I am not sure if both of those delays are implemented in my code. 
I think they are, but I don't know if they work perfectly...
In you example, all those timings are set to one clock cycle.

To find out what the StepPin and DirPin actually are, you need to check PinDefinitions.h. 

To see what number 17 (the STEP pin in the example) means, you check starting from line 626. 
It says PB4. 20, the DIR pin is PE5. There is no reason why they are on different ports. 

The DIR pin can be basically connected to any pin, only the STEP has those timer limitations !!!!!!!!!!!!

So you can choose others if you like, just check what pin number you need to use in PinDefinitions.h.

Wow, that is a lot of text about StepGen... Hope I was not too unclear. On my PCB, 
I have clearly marked the pin numbering and the pins where PWM or Stepper or Encoder can be 
connected, so it is simper, but for you working with different hardware, it might be 
difficult to grasp..

And that is only the driver configuration, next they need to be connected to 
LinuxCNC internal signals in the hal file.. But maybe I write about that another time. 
I quickly checked through those hal and ini files.. There is not that much to clean up.
 
You are right, that PID setup can be removed, it is related to Servos. 

So on each [AXIS_X] the parameters from P to DEADBAND are useless with steppers. 

But everything else is necessary, I think. 

So basically to have four axis, just copy the STEPGEN line in ethernet.conf four times and 
choose different pins and different name for each stepgen. 

Then duplicate the lines 21-30 of Testmachine.hal for each axis. 

But like you said, lets first see if it works with one motor..

Good night,
Pekka