@armandleo
I'm not sure what board you're using, but this is what I've set up for a similar function on my RatRig 1075 with a Duet MB6HC board:
; Endstops
M574 X2 S1 P"io8.in" ; configure switch-type (e.g. microswitch) endstop for high end on X via pin io8.in
M574 Y2 S1 P"io6.in+io5.in" ; configure switch-type (e.g. microswitch) and dual self-squaring high ends on Y1 via pin io6.in and on Y2 via pin io5.in
M574 Z2 S1 P"io2.in" ; configure switch-type (e.g. microswitch) endstop for high end on Z via pin io2.in
...and my homing file looks like this (I haven't yet changed this to call the individual homing files for each axis):
; homeall.g
G91 ; relative positioning
G1 H1 Z100 F2400 ; move quickly to the Z axis endstop
G1 H2 Z-3 F240 ; go back 3mm
G1 H1 X550 Y787 F2400 ; move quickly to X and Y axis endstops (first pass)
G1 H2 X-3 Y-3 F240 ; go back 3mm
G90
Is this what you're looking for?