@dc42 Just to clear with the build as of 27th Mar, the version of the file using M3.8 directly does not seem to delay when you might expect it to. The version using M98 to run the same macro file does delay as expected.
I've just tried the same test files on a Duet3 running 3.5.0-rc.3+8 and see the same "odd" behaviour with the macro being "called" as a substitute for a gcode then the dwell does not happen when expected (they seem to happen at the end of the print), but with the same macro call using M98 then the dwell happens as expected.
These are the test files I used on the duet3, first the file I print (from my "jobs" directory):
G92 X0 Y0
M564 H0
;(Home)
;G28
;(Movement Configuration)
G90
G21
;(Park ppindle)
;(Move to center of table)
G0 X150
;(Start spindle)
echo {"[L=" ^ line ^ " T=" ^ state.time ^ "] Running M3.8 #1" }
M3.8 S24000 I1
;M98 p"M3.8.g" S24000 I1
echo {"[L=" ^ line ^ " T=" ^ state.time ^ "] M3.8 Complete #1" }
;(Do some moves)
G0 X100
G0 X0
G0 X200
G0 X100
G0 X40
;(Change spindle speed)
echo {"[L=" ^ line ^ " T=" ^ state.time ^ "] Running M3.8 #2" }
M3.8 S12000 I2
;M98 p"M3.8.g" S12000 I2
echo {"[L=" ^ line ^ " T=" ^ state.time ^ "] M3.8 Complete #2" }
;(Do some more moves)
G0 X50
G0 X0
G0 X200
G0 X100
G0 X80
G0 X150
;(Stop spindle)
echo {"[L=" ^ line ^ " T=" ^ state.time ^ "] Running M3.8 #3" }
M3.8 S0 I3
;M98 p"M3.8.g" S0 I3
echo {"[L=" ^ line ^ " T=" ^ state.time ^ "] M3.8 Complete #3" }
G0 X0
echo { "[L=" ^ line ^ " T=" ^ state.time ^ "] File complete" }
Then the M3.8 macro (that goes in system):
;if { !inputs[state.thisInput].active }
; M99
var dwellTime = 10
echo { "[L=" ^ line ^ " T=" ^ state.time ^ "] Waiting " ^ var.dwellTime ^ " seconds for spindle to change speed - #" ^ param.I }
G4 S{var.dwellTime}
echo { "[L=" ^ line ^ " T=" ^ state.time ^ "] Finished waiting for spindle to change speed - #" ^ param.I }
Note my Duet3 is a bench test system that only has a single stepper motor attached (as X) and has no homing switches hence the changes to allow the print file to run. I don't think any of these changes make any difference to the problem described here.