Godley (4-4) gave up only four hits and two walks while striking out seven. He threw 66 of his 105 pitches for strikes, obtaining a dozen outs via grounders. None of the 21 outs he recorded left the infield.
Luke Weaver (0-1) absorbed the defeat for St. Louis (50-52) in his first big league start this year. Weaver lasted five innings, yielding the four runs on five hits and two walks with four strikeouts.
Coming off a three-game sweep of Colorado, the Cardinals dropped to 4 1/2 games behind first-place Chicago in the NL Central, thanks to the Cubs' 6-3 victory at the Chicago White Sox.
After tallying 21 runs in sweeping Colorado, including 10 on Wednesday night, St. Louis got only one runner to third Thursday. However, Godley left him there, getting rookie Harrison Bader to take a half-swing at an 0-2 pitch for a strikeout that ended the sixth.
Godley and Weaver each began with three scoreless innings, hitting spots with their fastballs and mixing in enough effective breaking pitches to keep the opponent off-balance.
That ended in the fourth. The Diamondbacks loaded the bases with no outs on an A.J. Pollock double and consecutive walks to Jake Lamb and Paul Goldschmidt. Martinez cashed them all in with a 364-foot fly ball that curled inside the right field foul pole for the fourth grand slam of his career.
It was Martinez's fourth homer with Arizona and his 20th overall this year.
NOTES: To make room for Thursday night's starting pitcher, RHP Luke Weaver, St. Louis optioned RHP Mike Mayers back to Triple-A Memphis. Mayers was recalled Wednesday to take the place of RHP Adam Wainwright (back) on the 25-man roster. ... Arizona acquired C John Ryan Murphy from Minnesota for LHP Gabriel Moya and sent Murphy to Triple-A Reno. Murphy, a former New York Yankee, batted .222 with four home runs and 27 RBIs in 59 games at Triple-A Rochester. ... Cardinals RF Stephen Piscotty (right groin strain) started a rehab assignment Thursday night at Class A Peoria, going 0-for-3 before leaving the game after four innings.